PDA

View Full Version : Cave car simulation


Marcel
06-14-2012, 07:16 AM
Hello there,

We are currently working on a school project that includes Vizard and a CAVE, and a WII remote controller.

The project contains a city where you can drive through and a car.

I have the city working, our problem is however, we need to simulate that the person is driving a car. I found this tutorial :

http://docs.worldviz.com/vizard/VizHelp.htm#head_and_body.htm

And it works perfect while you are running it in viz.go. But if i am going to implement it with the CAVE lib, we have the problem that the car is behind and moves separately with the "white" character while they both react on the arrow keys.

My question is, how can i get the car simulation working within the CAVE while having the same effect as the tutorial above.

(that the car model is moving and turning together with the white character)

With regards,
Marcel

Jeff
06-22-2012, 09:56 PM
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:

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')