WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 07-07-2008, 11:34 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I created a simple BonePointer class that allows you to specify a bone and where to point it at. This example will create an avatar and have it point its right arm towards the viewpoint. Let me know if anything is unclear.
Code:
import viz
viz.go()

class BonePointer(object):
	"""Class for pointing a bone at a specified point"""
	def __init__(self,bone,offset=None):
		
		self._node = viz.addGroup()
		self._node.visible(0)
		
		self._bone = bone
		
		#Get offset matrix to child bone
		if offset is None:
			srcPos = bone.getPosition(viz.AVATAR_LOCAL)
			dstPos = bone.getChildren()[0].getPosition(viz.AVATAR_LOCAL)
			self._node.setPosition(srcPos)
			self._node.lookat(dstPos)
			self._offset = viz.Matrix.quat(self._node.getQuat())
		else:
			self._offset = viz.Matrix(offset)
		self._offset.invert()
	
	def pointAt(self,pos):
		"""Point the bone at the specified position"""
		srcPos = self._bone.getPosition(viz.AVATAR_WORLD)
		self._node.setPosition(srcPos)
		self._node.lookat(pos)
		m = viz.Matrix.quat(self._node.getQuat())
		m.preMult(self._offset)
		self._bone.setQuat(m.getQuat(),viz.AVATAR_WORLD)
		
		
#Add avatar
model = viz.add('vcc_female.cfg',euler=(180,0,0))

#Create pointer object for shoulder bone
pointer = BonePointer(model.getBone('Bip01 R UpperArm'))

#Setup timer to update pointer every frame
def UpdatePointer():
	pointer.pointAt(viz.MainView.getPosition())
vizact.ontimer(0,UpdatePointer)
Reply With Quote
 


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
making a talking and imitating avatar marc van gaal Vizard 9 10-20-2006 04:28 AM
Generating morphs when making new avatar heads.. vjmcho Vizard 1 09-18-2006 02:36 PM
Making an avatar speak while performing an idling animation vr_boyko Vizard 1 10-05-2004 04:23 PM


All times are GMT -7. The time now is 10:57 AM.


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