View Single Post
Old 05-09-2009, 06:39 AM
nasr nasr is offline
Join Date: Apr 2009
Posts: 27
how to move seperately?

im trying to move the marker and ball seperately but both are moving can i move both of them seperately?
import viz

import vizinfo
info = vizinfo.add( 'Demonstrates the single function creation of a grab object relationship.\nThe arrow keys move the hand object.\nThe w, a, s, d, keys rotate the hand.\nThe t, g, h, f, keys rotate the ball.' )


#Add the object that will do the grabbing
hand = viz.add( 'marker.wrl' )
hand.translate( 0, 1.5, 3 )

#Add the object that the marker will grab
ball = viz.add( 'ball.wrl' )
ball.translate( 0.5, 1.5, 3 )

link = None #The handle to the link object

#Grab or let go of the ball
def toggleLink():
global link
if link:
#If link exits, stop grabbing
link = None
#If no link, grab the ball with the hand
link = viz.grab( hand, ball )

vizact.onkeydown(' ',toggleLink)

#Setup keyboard control of hand and ball
vizact.whilekeydown(viz.KEY_UP,hand.translate,0,vi zact.elapsed(1),0,viz.RELATIVE_WORLD)
vizact.whilekeydown(viz.KEY_DOWN,hand.translate,0, vizact.elapsed(-1),0,viz.RELATIVE_WORLD)
vizact.whilekeydown(viz.KEY_RIGHT,hand.translate,v izact.elapsed(1),0,0,viz.RELATIVE_WORLD)
vizact.whilekeydown(viz.KEY_LEFT,hand.translate,vi zact.elapsed(-1),0,0,viz.RELATIVE_WORLD)

vizact.whilekeydown('w',hand.rotate,1,0,0,vizact.e lapsed(90),viz.RELATIVE_WORLD)
vizact.whilekeydown('s',hand.rotate,1,0,0,vizact.e lapsed(-90),viz.RELATIVE_WORLD)
vizact.whilekeydown('d',hand.rotate,0,1,0,vizact.e lapsed(90),viz.RELATIVE_WORLD)
vizact.whilekeydown('a',hand.rotate,0,1,0,vizact.e lapsed(-90),viz.RELATIVE_WORLD)

vizact.whilekeydown('t',ball.rotate,1,0,0,vizact.e lapsed(90),viz.RELATIVE_WORLD)
vizact.whilekeydown('g',ball.rotate,1,0,0,vizact.e lapsed(-90),viz.RELATIVE_WORLD)
vizact.whilekeydown('h',ball.rotate,0,1,0,vizact.e lapsed(90),viz.RELATIVE_WORLD)
vizact.whilekeydown('f',ball.rotate,0,1,0,vizact.e lapsed(-90),viz.RELATIVE_WORLD)
Reply With Quote