View Single Post
  #11  
Old 04-29-2011, 11:51 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Here's some code that moves a car forward/back with the joystick and links the view to the car. The viewpoint can be moved around with a keyboard tracker relative to the car. The viewpoint and car positions are printed out in a timer function. Does this help with your question?
Code:
import viz
import vizact
import vizjoy
import viztracker
viz.go()

keyTracker = viztracker.Keyboard6DOF()

viz.addChild('tut_ground.wrl')
viz.clearcolor(viz.SKYBLUE)

car = viz.addChild('mini.osgx')
ViewCarLink = viz.link(car,viz.MainView)
ViewCarLink.preTrans([-0.2,1.1,-0.3])
ViewCarLink.preMultLinkable(keyTracker)

joy = vizjoy.add()

def updateCar():
	#Use y position of joystick to compute forward car movement
	forwardMovementAmount = viz.elapsed() * 10 * -joy.getPosition()[1]
	car.setPosition( [ 0, 0, forwardMovementAmount], viz.REL_LOCAL )
	
vizact.ontimer(0,updateCar)

def recordData():
	print 'Car position',car.getPosition()
	print 'View position',viz.MainView.getPosition()

vizact.ontimer(1,recordData)
Reply With Quote