View Single Post
  #2  
Old 06-22-2012, 09:56 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You could try linking the cave origin to the car's movements that are updated using the wiimote. Do you also have some type of head tracker so the user can move around within the car?

In the following example a keyboard tracker (wasd keys) is used in place of a head tracker and updates the projection matrices. The arrow keys move the car and the cave origin around the environment:
Code:
import viz
import vizcave
import viztracker

#Dimension of PowerWall in meters
WIDTH       = 3.0
HEIGHT      = 3.0
DISTANCE    = 2.0

#Initialize graphics window
viz.go()

#Create single power wall
PowerWall = vizcave.Wall(   upperLeft=(-WIDTH/2.0,HEIGHT,DISTANCE),
                            upperRight=(WIDTH/2.0,HEIGHT,DISTANCE),
                            lowerLeft=(-WIDTH/2.0,0.0,DISTANCE),
                            lowerRight=(WIDTH/2.0,0.0,DISTANCE),
                            name='Power Wall' )

#Create cave object with power wall
cave = vizcave.Cave()
cave.addWall(PowerWall)

#Create tracker object using the keyboard (WASD keys control the viewpoint, the user's eye location)
#Make the starting location for the user's eye above origin
viewtracker = viztracker.KeyboardPos()
viewtracker.setPosition(0.0,1.8,0.0)

#Pass the viewpoint tracker into the cave object so it can be automatically updated
cave.setTracker(pos=viewtracker)

#Create CaveView object for manipulating the entire cave environment
#The caveorigin is a node that can be adjusted to move the entire cave around the virtual environment
caveorigin = vizcave.CaveView(viewtracker)

#link caveorigin to mini
mini = viz.addChild('mini.osg')
originLink = viz.link(mini,caveorigin)
originLink.preTrans([-0.3,-0.6,-0.1])

MOVE_SPEED = 5
TURN_SPEED = 60

def updatecar():
	#move car forward and backward
	if viz.key.isDown(viz.KEY_UP):
		mini.setPosition([0,0,MOVE_SPEED*viz.elapsed()],viz.REL_LOCAL)
	elif viz.key.isDown(viz.KEY_DOWN):
		mini.setPosition([0,0,-MOVE_SPEED*viz.elapsed()],viz.REL_LOCAL)

	#rotate car left and right
	if viz.key.isDown(viz.KEY_RIGHT):
		mini.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.REL_LOCAL)
	elif viz.key.isDown(viz.KEY_LEFT):
		mini.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.REL_LOCAL)

vizact.ontimer(0,updatecar)

#Add gallery environment model
viz.add('ground.osgb')
Reply With Quote