#1
|
|||
|
|||
looking at a point
i want to make an avatar look at an absolut point in space (e.g. have all the students in a class look at the teacher). avatar.lookat() makes the entire body point, while avatar.heatto() creates an animation using yaw/pitch/roll. i want this:
Code:
teacher = [2, 3, 4] avatar.lookatpoint(teacher) def lookatpoint(self, point): self._headbone = self.getbone('skel_Head') self._headbone.lock() self._headbone.lookat(point, viz.ABSOLUTE_WORLD) |
#2
|
|||
|
|||
Hi,
Here is a sample script that should help you out: Code:
import viz viz.go() male = viz.add('male.cfg') head = male.getbone('skel_Head') head.lock() dummy = viz.add(viz.GROUP) ball = viz.add('white_ball.wrl') ball.spin(0,1,0,45) ball.translate(2,0,0) ball.center(-2,0,0) def ontimer(num): dummy.translate(head.get(viz.POSITION,viz.ABSOLUTE_WORLD)) dummy.lookat(ball.get(viz.POSITION,viz.ABSOLUTE_WORLD)) head.rotatequat(dummy.get(viz.QUAT), viz.ABSOLUTE_WORLD) viz.callback(viz.TIMER_EVENT,ontimer) viz.starttimer(0,0,viz.FOREVER) You're two for two today. Are there any other features you want me to add to the next release? |
#3
|
|||
|
|||
do i have to make the dummy node, move it, and adjust the head using timers and quats? or is there a simpler way considering that i will have 20 people in the simulation that either need to be looking at the teacher, at someone/thing else, or straight ahead (which would be too many hard-coded functions for my taste).
Last edited by vadrian; 06-03-2005 at 05:12 PM. |
#4
|
|||
|
|||
Just create a global dummy node and then have a function that pretty much contains the code in the timer. Here's a cleaned up version of the sample code:
Code:
#You only need a single global dummy node dummy = viz.add(viz.GROUP) def lookatpoint(self, point): self._headbone = self.getbone('skel_Head') self._headbone.lock() dummy.translate(self._headbone.get(viz.POSITION,viz.ABSOLUTE_WORLD)) dummy.lookat(point) self._headbone.rotatequat(dummy.get(viz.QUAT), viz.ABSOLUTE_WORLD) |
#5
|
|||
|
|||
i even made your code a bit more specific to absolute-world location, but it still doesnt work. all the heads look to the same absolute-local point.
Code:
self._headbone.lock() _dummy.translate(self._headbone.get(viz.POSITION,viz.ABSOLUTE_WORLD), viz.ABSOLUTE_WORLD) _dummy.lookat(point, 0, viz.ABSOLUTE_WORLD) self._headbone.rotatequat(_dummy.get(viz.QUAT), viz.ABSOLUTE_WORLD) |
#6
|
|||
|
|||
Let me know if this example script works. There should be two avatars in front of you who will be tracking a ball that is moving back and forth across the screen.
Code:
import viz viz.go() viz.add('tut_ground.wrl') ball = viz.add('white_ball.wrl') ball.add(vizact.sequence(vizact.goto(-2,1,0),vizact.goto(2,1,0),viz.FOREVER)) avatar1 = viz.add('male.cfg') avatar1.translate(-2,0,3) avatar1.rotate(180,0,0) avatar2 = viz.add('female.cfg') avatar2.translate(2,0,3) avatar2.rotate(180,0,0) dummy = viz.add(viz.GROUP) def lookatpoint(avatar,point): _headbone = avatar.getbone('skel_Head') _headbone.lock() dummy.translate(_headbone.get(viz.POSITION,viz.ABSOLUTE_WORLD)) dummy.lookat(point) _headbone.rotatequat(dummy.get(viz.QUAT), viz.ABSOLUTE_WORLD) def ontimer(num): pos = ball.get(viz.POSITION) lookatpoint(avatar1,pos) lookatpoint(avatar2,pos) viz.callback(viz.TIMER_EVENT,ontimer) viz.starttimer(0,0,viz.FOREVER) viz.move(0,0,-5) |
|
|