WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-11-2009, 12:53 PM
Enlil Enlil is offline
Member
 
Join Date: May 2008
Posts: 61
Problems with getting head bone rotation right

Hello,

I am trying to write some code that causes a head to turn and face an object. I looked at the lookat() commands, and those didn't do what we were looking for, so I am writing it from scratch.

Now, I have a routine that takes two points and gives the euler angle that will point the first at the second. I can use this to turn the camera towards an object. However, when I try to do the same thing with the head or neck bone of an avatar, it does not work like I expected.

The code is here:

def GetTargetAngleToFace(position1, position2):
# Find horizontal target angle
x_pos = position1[X_POS] - position2[X_POS]
z_pos = position1[Z_POS] - position2[Z_POS]
horiz_angle = math.degrees(math.atan2(x_pos, z_pos))
#find vertical target angle
vert_x = math.sqrt(x_pos*x_pos + z_pos*z_pos)
y_pos = position1[Y_POS] - position2[Y_POS]
vert_angle = -math.degrees(math.atan2(y_pos, vert_x))
#print "Angles: H: " + str(horiz_angle) + " V: " + str(vert_angle)
return [horiz_angle, vert_angle, 0]


target_euler = GetTargetAngleToFace(self.ObjectToFollowWithHead.g etPosition(mode = viz.ABS_GLOBAL), self.HeadBone.getPosition(mode = viz.ABS_GLOBAL))
self.HeadBone.setEuler(target_euler, mode = viz.ABS_GLOBAL)

where self.HeadBone is the locked 'Bip01 Head' of the vcc_female model that comes with vizard.

What I get is the head tilting to not at all the same euler as target_euler. For that matter, if I just get the current euler of the head and change one element of it, then put it back in with setEuler in viz.ABS_GLOBAL mode, I get a different value when I do a getEuler in viz.ABS_GLOBAL mode. So I figure I am doing something wrong. Could anyone help me here?

Thanks,
Christian
Reply With Quote
  #2  
Old 02-13-2009, 09:45 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You should be able to use the bone.lookat command to have the head face a certain position. Here is a sample script:
Code:
import viz
import vizact
viz.go()

viz.add('tut_ground.wrl')

#Create animating ball
ball = viz.add('white_ball.wrl')
ball.add(vizact.sequence(vizact.goto(-2,1,0),vizact.goto(2,1,0),viz.FOREVER))

#Create male avatar
avatar1 = viz.add('vcc_male.cfg',pos=(-2,0,3),euler=(180,0,0))
avatar1.state(1)
head1 = avatar1.getBone('Bip01 Head')
head1.lock()

#Create female avatar
avatar2 = viz.add('vcc_female.cfg',pos=(2,0,3),euler=(180,0,0))
avatar2.state(1)
head2 = avatar2.getBone('Bip01 Head')
head2.lock()

def UpdateAvatarHead():
	"""Update avatars to look at ball position"""
	pos = ball.getPosition()
	
	head1.lookat(pos,0,viz.AVATAR_WORLD)
	head2.lookat(pos,0,viz.AVATAR_WORLD)

vizact.ontimer(0,UpdateAvatarHead)

viz.MainView.move(0,0,-5)
Reply With Quote
  #3  
Old 02-13-2009, 10:24 AM
Enlil Enlil is offline
Member
 
Join Date: May 2008
Posts: 61
We require finer control than lookat provides, but I solved the problem - it appears that mode = viz.ABS_GLOBAL does not work in python, though I used viz.AVATAR_WORLD

Thanks for the help in any case.

Christian
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking problems with Live Character Frank Verberne Vizard 5 06-04-2008 11:42 AM
Texturing Avatar head problems S.Telemaque Vizard 0 04-01-2007 10:01 PM
Problems Texturing avatar head S.Telemaque Vizard 3 03-27-2007 07:18 PM
problems adding a custom morph head to a custom body Greenwu Vizard 1 07-27-2006 10:32 AM
tracking head rotation orientation VAmanda Vizard 3 09-21-2005 04:57 PM


All times are GMT -7. The time now is 06:14 AM.


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