WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Old 06-02-2005, 04:21 PM
vadrian vadrian is offline
Member
 
Join Date: Sep 2004
Posts: 32
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?
Reply With Quote
  #2  
Old 06-02-2005, 04:50 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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?
Reply With Quote
  #3  
Old 06-03-2005, 03:51 PM
vadrian vadrian is offline
Member
 
Join Date: Sep 2004
Posts: 32
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 04:12 PM.
Reply With Quote
  #4  
Old 06-03-2005, 04:52 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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)
Reply With Quote
  #5  
Old 06-07-2005, 05:11 PM
vadrian vadrian is offline
Member
 
Join Date: Sep 2004
Posts: 32
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.
Reply With Quote
  #6  
Old 06-07-2005, 05:43 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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