Vizard 7 » Tutorials & Examples » Hardware » 5DT data gloves » Tutorial: A bird in the hand
7.6

Tutorial: A bird in the hand

Now let's use the gloves to interact with a world. We'll create a duck and then animate that duck with hand gestures. First comment out the glove from your script:

##Create a hand object from the data glove
#glove = hand.add(sensor,hand.GLOVE_5DT)
#
##Place the hand in front of the user
#glove.setEuler([0,-90,0])
#viz.MainView.setPosition([0,0.02,-0.4])

Add a duck:

#Add a duck.
duck = viz.add('duck.cfg')
duck.setPosition([0,.5,4])
duck.setEuler([180,0,0])

Now add the highlighted lines to your getGesture() function.

#Add a timer function that pulls the gesture categories from the sensor
#and prints out their labels and moves the duck
def getGesture():
    gesture = int(sensor.get()[-1])
    gestureText.message(gestureName[gesture])

    if gesture == 2:
        #Middle finger point
        duck.setEuler([1,0,0],viz.REL_PARENT)
    if gesture == 8:
        #Little finger point
        duck.state(1)
    if gesture == 9:
        #Index and little finger point
        duck.state(2)
    if gesture == 1:
        #Index finger point
        duck.setPosition([0,.05,0], viz.REL_PARENT)
    if gesture == 0:
        #Fist
        duck.setPosition([0,-.05,0], viz.REL_PARENT)

vizact.ontimer(0, getGesture)

Run the script and try playing with the glove. Point with your index and little finger to get the duck jumping, point with your little finger to make it walk, point with your index finger to make it rise, make a fist to make it fall, and point with your middle finger to make it spin.

Getting your glove working

A bird in the hand