WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   looking at a point (https://forum.worldviz.com/showthread.php?t=369)

vadrian 06-02-2005 04:21 PM

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)

this doesnt' seem to work, but i think you get the point. so how do i do this?

farshizzo 06-02-2005 04:50 PM

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)

I'll add the lookat command for bones in the next release.

You're two for two today. Are there any other features you want me to add to the next release? :)

vadrian 06-03-2005 03:51 PM

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).

farshizzo 06-03-2005 04:52 PM

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)


vadrian 06-07-2005 05:11 PM

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)

is there another way to go about this? nothing seems to work with avatar heads like it does with regular objects.

farshizzo 06-07-2005 05:43 PM

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)



All times are GMT -7. The time now is 08:11 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC