View Single Post
  #1  
Old 07-05-2006, 11:32 AM
halley halley is offline
Member
 
Join Date: Oct 2005
Posts: 27
demo of new hand.getFingerTip()

Just thought I'd put in a demo that works in the beta, and some feedback.

Code:
# This is a demonstration of the new hand.getFingerTip()
# method, which lets you find the positions of each fingertip
# in a hand model.  This is useful if you wanted to
# interact with small objects in an immersive space:  e.g.,
# type on a virtual keyboard or create "fingerpaint" geometry.

import viz
import vizmat ; from vizmat import Transform
import hand

viz.go()

import vizinfo
vizinfo.add('This script fetches the positions of each fingertip on a hand model.\n' +
            'Three balls are just moved to the new positions.\n' +
            'Two are moved and oriented to match each finger.\n')

# Add a poseable hand object.
# This will work even without a glove connected.
#
PORT_5DT_USB = 0
aSensor = viz.add('5dt.dls')
aHand = hand.add(aSensor)
aHand.manual()

# Position it so we get a good view.
aHand.translate(0, 1.8, 0.4)
aHand.rotate(1, 0, 0, -90)
aHand.rotate(0, 1, 0, -150, viz.RELATIVE)
aHand.setGesture(hand.GESTURE_FIST, closeThumb=True)

# Make a colored ball for each finger.
lDots = []
size = 0.05
for i in range(5):
	aDot = viz.add('ball.wrl')
	aDot.scale(size, size, size)
	aDot.rotate(0, 1, 0, -90)
	lDots.append(aDot)

# On each timer event, we move the hand.
# Every once in a while, we pick a different gesture.
# Then we reposition the balls to the new fingertip locations.
# Some balls are just moved to the fingertip position,
# while other balls are given the orientation too.
#
z = 1
def on_timer(id):
	global lDots, z

	# move the hand
	aHand.rotate(0, 0, 1, +1, viz.RELATIVE)

	# pick a new pose (gesture)
	z += 1
	if (0 == (z % 500)):
		aHand.setGesture(hand.GESTURE_INDEX_FINGER, closeThumb=True)
	elif (0 == (z % 400)):
		aHand.setGesture(hand.GESTURE_TWO_FINGER, closeThumb=True)
	elif (0 == (z % 300)):
		aHand.setGesture(hand.GESTURE_THREE_FINGER, closeThumb=True)
	elif (0 == (z % 200)):
		aHand.setGesture(hand.GESTURE_FLAT_HAND, closeThumb=True)
	elif (0 == (z % 100)):
		aHand.setGesture(hand.GESTURE_FLAT_HAND, closeThumb=False)

	# adjust the ball positions
	for i in range(5):
		matrix = aHand.getFingerTip(i)
		# two different ways to use the matrix
		if i < 3:
			# extract the positional portion of the matrix
			transform = Transform(matrix)
			position = transform.getPosition()
			lDots[i].translate(position)
		else:
			# use the position and orientation
			# re-adjust the scale
			lDots[i].setMatrix(matrix)
			lDots[i].scale(size, size, size)

# Start the timer so things happen.
#
viz.callback(viz.TIMER_EVENT, on_timer)
viz.starttimer(0,0.01, viz.FOREVER)
First off, thanks to Farshid, who said "oh, that would be quick to add" when I asked for the feature. You guys are welcome to include this demo script in your "Examples > Avatar" online help.

It would be nice if the caller could get the matrix OR just the position, but my demo above shows how someone could use the vizmat.Transform class to extract useful scale, rotation, translation components separately.

Using the hand model gestures in .manual() mode highlights the fact that there is no such thing as .spinto() on a VizBone. Perhaps that can be added in the future so the hand can be flexed open and closed over the course of a few milliseconds instead of snapping to each new gesture position. (It's not critical to my work.)
__________________
--
[ e d h a l l e y ]
I'm just a user, not a representative of WorldViz. Hope I've been helpful.
Reply With Quote