View Single Post
  #3  
Old 11-25-2008, 03:22 PM
michaelrepucci michaelrepucci is offline
Member
 
Join Date: Jul 2008
Posts: 53
Okay. Interesting. I was able to get a stripped-down example working, though my approach was slightly different than yours. So for the forum record I will post it here, then I just have a few questions about the differences. FYI, the sunyobjects module is just full of on-the-fly objects whose appearance should be obvious from the class name.

Code:
from __future__ import division #implements "/" as division without truncation regardless of its operands
import viz #basic Vizard module
import vizact #Vizard actions module
import viztask #Vizards task execution module
import vizcave #Vizard cave module
import vizinfo #Vizard 2D GUI commands
import viztracker #Vizard position/orientation tracker module
import sunyobjects

def onFrameUpdate(event):
	global headPosition, headOrientation
	
	#save head position and orientation
	headPosition += [tracker.getPosition()]
	headOrientation += [tracker.getQuat()]

def run():
	for i in range(2):
		if i%2:
			yield viz.message('Playback Head Position')
			for hp, ho in zip(headPosition,headOrientation):
				cave.update(hp,ho)
				viz.MainView.setPosition(hp)
				viz.MainView.setQuat(ho)
				yield viztask.waitDraw()
		else:
			yield viz.message('Recording Head Position (10 seconds)')
			cave.setTracker(pos=tracker,ori=tracker) #update frustums based on head-position
			view = vizcave.CaveView(tracker) #update view based on head-position
			viz.callback(viz.UPDATE_EVENT,onFrameUpdate)
			yield viztask.waitTime(10)
			viz.callback(viz.UPDATE_EVENT,None)
			cave.setTracker(pos=None,ori=None) #prevent update frustums based on head-position
			view.remove() #prevent update view based on head-position

#global variables
headPosition = [] #head position on each frame
headOrientation = [] #head orientation on each frame

#display keyboard mapping
keyMap = vizinfo.add('Left/Right = Q/E\n'+
	'Up/Down = R/F\n'+
	'Forwards/Backwards = W/S\n\n'+
	'Roll Left/Right = G/J\n'+
	'Pitch Up/Down = Y/H\n'+
	'Yaw Left/Right = A/D')
keyMap.title('Keyboard Tracker Mapping')
keyMap.shrink()

viz.go()
viz.eyeheight(1)
viz.MainWindow.mouse(viz.OFF)
viz.mouse.setVisible(viz.OFF)

#keyboard simulated tracker
tracker = viztracker.add()

#setup cave with wall and tracker (optional)
wall = vizcave.Wall('wall',[-1,1,0],[1,1,0],[-1,-1,0],[1,-1,0])
cave = vizcave.Cave()
cave.addWall(wall)

cube = sunyobjects.CompositeCube(0.5,0.01)

viztask.schedule(run()) #since control passes immediately do not place critical code after this point
So one fundamental difference is that during playback you use a node3d object to link to the cave (cave.setTracker and vizcave.CaveView), and then change that node's position, whereas I use cave.update and viz.MainView.setPosition directly. Aside from personal preference is there any performance reason to do this one way or the other?

A more minor difference is that during playback you yield on None after each position update, whereas I yield on viztask.waitDraw(). What is the difference between these approaches, and which would ensure that each frame of the playback was identical to the recorded frames?

Finally, and this perhaps is not a difference at all, you use vizact.onupdate, while I use viz.callback(viz.UPDATE_EVENT). Is there a reason to prefer one command over the other, or are they completely identical?

Thanks for all the help!
Reply With Quote