WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 8 votes, 5.00 average. Display Modes
  #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
  #2  
Old 08-14-2008, 05:04 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
It works for me. What exactly is the problem you are experiencing?
Reply With Quote
  #3  
Old 08-15-2008, 08:22 AM
TrashcanPatrol TrashcanPatrol is offline
Member
 
Join Date: Aug 2008
Posts: 43
Hmm, that's funny... On my level I have made, the patient does not do that. I thought for sure it was the hat that screwed up. Sorry, I'll keep looking into it and come here if I figure out what the problem really is
Reply With Quote
  #4  
Old 08-15-2008, 08:43 AM
TrashcanPatrol TrashcanPatrol is offline
Member
 
Join Date: Aug 2008
Posts: 43
I've found out that there's another code conflicting with the avatar's looking patterns for some reason... It's the callback for when I put the arrow following the player's movement in the Bird's Eye view.
Note: The map I'm using for this thing is room.wrl, so the Bird's Eye is tweaked so that it is specifically for that level.

Code:
# Create a new window in the upper right corner
UpperRightWindow = viz.add(viz.WINDOW)
UpperRightWindow.position(0.75, 1.0)
UpperRightWindow.size(0.3, 0.3)
UpperRightWindow.visible(0,viz.SCREEN)

# Create a new viewpoint
BirdView = viz.add(viz.VIEWPOINT)

#Attach the bird's eye view to the upper right window
UpperRightWindow.viewpoint(BirdView)

#Move the view above the center of the room
BirdView.translate(-1,20,2)

#Rotate the view so that it looks down
BirdView.rotate(1,0,0,90)

arrow = viz.add('arrow.wrl')
arrow.scale(0.5,0.5,0.5)

def mytimer(num):
    #Get the current head orientation and position
    ori = viz.get(viz.VIEW_YAW)
    pos = viz.get(viz.HEAD_POS)
   
#    #Move the rear view to the current position
#    RearView.translate(pos)
#   
#    #Rotate the rear view so that it faces behind us
#    RearView.rotate(0,1,0,ori+180)
#   
    #Move the arrow to our current location
    arrow.translate(pos[0],3.3,pos[2])
    arrow.rotate(ori,-90,0)

# Disable collisions with the arrow
arrow.disable(viz.COLLISION)   

# Create callback to a timer and start it
viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.001,-1)
Is there any way you guys would recommend that would allow for me to have both the Bird's Eye view at the topright with the arrow pointing to the player's position, as well as have the avatar looking towards the player?
Reply With Quote
  #5  
Old 08-18-2008, 01:07 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You are using two different timer callbacks. So the last one that is being registered is overwriting the first one. You are better off using the vizact.ontimer function to register multiple timer events that do not conflict with each other. Your code would look something like this:
Code:
def ArrowTimer():
    #Place code that updates arrow here
    pass
vizact.ontimer(0,ArrowTimer)

def AvatarLookTimer():
    #Place code that update avatar head here
    pass
vizact.ontimer(0,AvatarLookTimer)
Reply With Quote
  #6  
Old 08-19-2008, 08:26 AM
TrashcanPatrol TrashcanPatrol is offline
Member
 
Join Date: Aug 2008
Posts: 43
Thanks farshizzo, it works like a charm now!
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
Collision of an avatar with a quad Frank Verberne Vizard 8 06-04-2008 09:44 AM
Looking through the eyes of an avatar Frank Verberne Vizard 2 04-01-2008 05:52 AM
How to make avatar's eyes to blink when speaking michelcm3 Vizard 12 01-15-2008 08:48 AM
Avatars in an array and link/unlink betancourtb82 Vizard 7 09-05-2006 04:06 PM
VRML Viewpoint error bstankie Vizard 1 03-11-2003 02:10 PM


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


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