View Single Post
  #5  
Old 03-28-2008, 01:32 AM
Andy Andy is offline
Member
 
Join Date: Mar 2008
Location: Germany
Posts: 36
OK fine, now it looks much better…

Code:
import viz
import vizcave
import viztracker

viz.go()
viz.MainWindow.stereo(viz.STEREO_RIGHT)

c0 = -1,2,0
c1 = 1.,2,0
c2 = 1.,0.6,0
c3 = -1,0.6,0

cave = vizcave.Cave()
FrontWall = vizcave.Wall(upperLeft=c0,upperRight=c1,lowerLeft= c3,lowerRight=c2,name='Front Wall' )
cave.addWall(FrontWall, mask =None, window = viz.MainWindow)

#Add a sensor.
tracker = viz.add('fastrak.dls')

vpT = [0, 1.82, -1.6] # tracker-offset-values
vpM = [0, 0, -1.6] # set the Main-ViewPoint in the center of the tracker
#viz.MainView.translate(vpM)

viz.add('tut_ground.wrl')
mini = viz.add("mini.osgx")
mini.translate(0,0.7,0)
mini.setScale(1, 1, 1)
mini.add(vizact.spin(0,1,0,15))

def UpdateCave():
	TP = tracker.getPosition()
	TO = tracker.getEuler()
	NewTO = vizmat.EulerToQuat(TO[1],TO[0],TO[2]) #swap X-Y and transform in quaternion
	NewTP = [-TP[0]+vpT[0],-TP[1]+vpT[1],-TP[2]+vpT[2]] #invert the tracker-position-data and set offsetvalues
	cave.update(pos = NewTP,ori =NewTO)
	viz.MainView.translate(vpM[0]+NewTP[0],vpM[1]+NewTP[1],vpM[2]+NewTP[2])
	print "Tracker_P: ", NewTP
	print "Tracker_O: ", NewTO
	print "Main_VP: ", viz.MainView.getPosition()
	print "Main_VO: ", viz.MainView.getEuler()

vizact.ontimer(0,UpdateCave)

TURN_SPEED = 60
def onKeyDown(key):
	#move the main-ViewPoint
	#move the ViewPoint
	if viz.key.isDown('w'): #plus
		vpM[2] += 1*viz.elapsed()
	if viz.key.isDown('s'): #minus
		vpM[2] -= 1*viz.elapsed()
	if viz.key.isDown('e'): #down
		vpM[1] += 1*viz.elapsed()
	if viz.key.isDown('d'): #up
		vpM[1] -= 1*viz.elapsed()
	#Rotate the ViewPoint
	if viz.key.isDown('q'): #left
		viz.MainView.rotate(0,1,0,-TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.RELATIVE_WORLD)
	if viz.key.isDown('a'): #right
		viz.MainView.rotate(0,1,0,TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.RELATIVE_WORLD)	
viz.callback(viz.KEYDOWN_EVENT,onKeyDown) 

viz.starttimer(0,0.01,viz.FOREVER)
Now I have a new problem. I want to navigate but I have to use “vpM” and “NewTP” to update the “MainView” function. When I use “viz.MainView.rotate” for ViewPoint-rotation it seems to by ok, but I can not use “viz.MainView.move” because so I do not include the position I get from the Tracker (NewTP).
Do you have an idea?
Reply With Quote