View Single Post
  #1  
Old 08-14-2008, 11:08 AM
TrashcanPatrol TrashcanPatrol is offline
Member
 
Join Date: Aug 2008
Posts: 43
Avatar w/ hat cannot look at viewpoint

Hello, I was trying a combination of scripts from tutorials... the first one was the one to bind the hat to an avatar, and the second was to make the avatar look at the viewpoint. My problem is, I can't get them to work at the same time for some reason. :/
Here is the hat code I am using:

Code:
patient=viz.add('vcc_male.cfg')
patient.translate(-5.1,0,8.9)
patient.rotate(0,1,0,180)
patient.state(1)
hat = viz.add('tophat.3ds')
head2 = patient.getBone('Bip01 Head')
HatLink = viz.link(head2,hat)
HatLink.preTrans( [0,0.150,0.01] )
HatLink.preEuler( [0,-10,0] )

toon = viz.add('toon.dlm')
patient.modify(toon)
And here is the look code that I am using:

Code:
#Get a handle to the Neck bone
head = patient.getBone('Bip01 Neck')
head.lock() #Disable automatic bone animation so that we can manually animate it

#Lock the head bone so that manual movement of the neck bone also moves the child head bone
patient.getBone('Bip01 Head').lock()

#Used to rotate the torso when the viewpoint moves to the side of the avatar
torso = patient.getBone('Bip01 Spine1')
torso.lock()


def ontimer(num):
  #Make head look at viewpoint
  viewPOS = viz.MainView.getPosition()
  head.lookat( viewPOS, 0, viz.AVATAR_WORLD ) #points the head and neck at the viewpoint
  #Get neck orientation to see if we need to translate torso
  headOrientation = head.getEuler( viz.AVATAR_LOCAL )


  #Move torso so that the neck does not twist too much
  
  if headOrientation[0] < -90 and headOrientation[0] > -180: # -90 to -180
#Viewpoint in avatar's left-back yaw quadrant
	torso.setEuler( headOrientation[0] + 90, 0, 0, viz.AVATAR_LOCAL )
	#Point head back at view because it is child object and was moved by torso rotation
	head.lookat( viewPOS, 0, viz.AVATAR_WORLD )

  elif headOrientation[0] > 90 and headOrientation[0] < 180: #90 to 180
#Viewpoint in avatar's right-back yaw quadrant
	torso.setEuler( headOrientation[0] - 90, 0, 0, viz.AVATAR_LOCAL )
	#Point head back at view because it is child object and was moved by torso rotation
	head.lookat( viewPOS, 0, viz.AVATAR_WORLD )

	
viz.callback( viz.TIMER_EVENT, ontimer )
viz.starttimer( 1, 0, viz.PERPETUAL )
I hope there's something I can do to fix it... thanks in advance for any advice/tips
Reply With Quote