WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create mini car driving by wiimote superantTTY Vizard 7 05-18-2010 05:18 AM
How to pause the Vizard simulation? 4711 Vizard 4 03-18-2010 04:45 PM
Particle simulation imperialkat Vizard 0 01-29-2010 12:01 PM
driving simulator paulpars Vizard 1 05-12-2006 11:46 AM


All times are GMT -7. The time now is 01:51 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC