WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-20-2007, 10:43 AM
ghazanfar ghazanfar is offline
Member
 
Join Date: Mar 2007
Posts: 11
Problem with letting an avatar face towards another avatar

I am trying to let an avatar face towards another avatar, but i can't get it working.

I am trying to calculate the number of degrees that have to be rotated, using the difference between the x and z coordinates of the two avatars, but it gives wrong values, and i cannot find out why.

Can anyone help?


if(ag1=='a3' and ag2=='a1'):
pos=male1.get(viz.POSITION)
angpos=male1.get(viz.AXISANGLE)
pos2=male.get(viz.POSITION)
print "position",pos2
xdif = pos2[0] - pos[0]
zdif = pos2[2] - pos[2]
rotate_radians=math.atan(xdif/(zdif+0.0000001))
rotate_degrees = math.degrees(rotate_radians)
rotate_degrees -= angpos[3]
male1.rotate(0,1,0,rotate_degrees)
male1.act(6)
Reply With Quote
  #2  
Old 03-20-2007, 02:32 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
The problem might be caused by adding angpos[3] to the rotation. When you retrieve the axis angle it is not guaranteed that the rotation will be around the positive y axis. Try printing out the entire angpos for debugging. A better method might be to retrieve the euler rotation and use the yaw instead.

Also, you can use the vizmat.AngleToPoint function to compute the angle difference. Here is some sample code:
Code:
pos=male1.get(viz.POSITION)
euler=male1.get(viz.EULER)
pos2=male.get(viz.POSITION)
rotate_degrees = vizmat.AngleToPoint(pos[0],pos[2],pos2[0],pos2[2])
rotate_degrees -= euler[0]
Reply With Quote
  #3  
Old 03-21-2007, 03:30 AM
ghazanfar ghazanfar is offline
Member
 
Join Date: Mar 2007
Posts: 11
Thanks a lot for your help. We did not know there existed an angleToPoint() method. This helped us solve this. The main problem was that we thought that the rotate() method used the current rotation, and rotated further on from that point. But it seems the method just places the avatar in the rotation, not regarding the rotation before the method is applied.

Now the function is working using the following code:

pos=male.get(viz.POSITION)
pos2=female.get(viz.POSITION)
rotate_degrees = vizmat.AngleToPoint(pos[0],pos[2],pos2[0],pos2[2])
male.rotate(0,1,0,rotate_degrees)
male.act(6)
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 09:51 AM.


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