PDA

View Full Version : demo of new hand.getFingerTip()


halley
07-05-2006, 11:32 AM
Just thought I'd put in a demo that works in the beta, and some feedback.


# 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.)

Gladsomebeast
07-07-2006, 12:20 PM
Nice. I like how you differentiated between just using the position and using the full matrix to add orientation.

I like the idea of adding actions to bones. That would really ease manually animating them. Now that I'm thinking about it, it would also be cool if our hand model had some built in animations...

giancamati
07-07-2006, 02:51 PM
Hi, I tried to import hand, but I received an error. Is it hand a standard module of vizard?

thank you so much.

giancarlo

Gladsomebeast
07-07-2006, 02:54 PM
Hand is a standard module. Can you post the text of your error?

giancamati
12-12-2006, 06:05 AM
File "hand.py", line 23, in ?
aHand = hand.add(aSensor)
AttributeError: 'module' object has no attribute 'add'

Gladsomebeast
12-12-2006, 09:31 AM
Save the name of your script to something besides hand.py because it is overriding the standard hand module.

giancamati
12-13-2006, 03:42 AM
I saved the example with a different name, but I received the same error.

Giancarlo
** ERROR: Failed to connect to 5DT glove on COM1
Traceback (most recent call last):
File "<string>", line 11, in ?
File "mano.py", line 9, in ?
import hand
File "hand.py", line 23, in ?
aHand = hand.add(aSensor)
AttributeError: 'module' object has no attribute 'add'
** Load Time: 4.00 seconds

Gladsomebeast
12-13-2006, 09:35 AM
If you have your previous hand.py file in the same directory as your new mano.py file then mano.py will import your hand.py file and not the standard Vizard module.

farshizzo
12-13-2006, 09:38 AM
Also, if there is a hand.pyc file in your script directory, you need to delete it.

giancamati
12-14-2006, 12:40 AM
great I understood all my problems thank you so much.

Giancarlo