![]() |
#3
|
|||
|
|||
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 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! |
|
|