def recordViewAnimation(): ### replace with your own application setup import viz import vizcam import vizact viz.setMultiSample(4) viz.go() vizcam.WalkNavigate() piazza = viz.addChild("piazza.osgb") ### ### Add this at the bottom ''' Create an AnimationPathRecorder and link it to any node, which needs to have it's transformation documented. If 'start' is set to True the recording will start automatically, otherwise you need to start manually. you can specify the file name under which the animation will be saved. '.txt' is automatically added. ''' rec = AnimationPathRecorder(start=False) viz.link(viz.MainView, rec) # toggle path recording and saving finished recording to a file named 'test_animation.txt' def toggleRecord(rec): if rec.isRunning(): rec.stop() rec.writeToFile("test_animation") print "Animation path saved to test_animation.txt" else: rec.start() print "Animation path recording started." vizact.onkeydown('r', toggleRecord, rec)
boundary4.visible(0) return context ##lighting mylight = viz.addLight() mylight.enable() mylight.position(0, 10, 0) mylight.spread(180) ##uniform ambient lighting mylight.intensity(2.5) #setup keyboard controls vizcam.WalkNavigate(forward='w', backward='s', left='æ', right='¨', moveScale=1.1, turnScale=0.35) #turn on collisions viz.collision(viz.ON) ####################### ## PROXIMITY MANAGER ## ####################### ##Create proximity manager global manager manager = vizproximity.Manager() #Add main viewpoint as proximity target'
#cV.remove() i = i+1 return globalCrns # scale factor scFac = 60 viz.setMultiSample(4) viz.go() viz.eyeheight(ct.EYE_HEIGHT) # add code to navigate through scene via "wasd" control vizcam.WalkNavigate(forward='w', backward='s', left='a', right='d', moveScale=ct.MOVE_SPEED, turnScale=1.0) #Get a handle to the main headlight and disable it headLight = viz.MainView.getHeadLight() #dheadLight.disable() # add sky sky = viz.add('sky_day.osgb') # add grassy plane surrounded by mountains gScale = 1.1 hills = vizfx.addChild(os.path.join(ct.PATH_TO_OSGB, 'hills.osgb')) hills.setScale(gScale, gScale, gScale) # add invisible cylinder to prevent subjects from leaving the arena
def getOutputTexture(self): return self._output_texture def remove(self): self._cam.remove() self._projector.remove() viz.VizNode.remove(self) if __name__ == '__main__': import vizshape import vizcam viz.setMultiSample(4) viz.fov(60) viz.go() vizcam.WalkNavigate() piazza = viz.addChild('piazza.osgb') capture = ViewAccumulator(frame_weight=0.5, aperture_scale=0.5) capture.setPosition(0, 1.8, 3.0) # add debug quad output_quad = vizshape.addQuad() output_quad.texture(capture.getOutputTexture()) output_quad.disable(viz.LIGHTING) output_quad.renderOnlyToWindows( [viz.addWindow(pos=[0.5, 0.5], size=[0.5, 0.5])]) viz.link(capture, output_quad)
def __init__(self, config): viz.EventClass.__init__(self) viz.mouse(viz.ON) self.config = config # set first person movement controls and hide mouse viz.cam.setHandler(vizcam.WalkNavigate(moveScale=2.0, turnScale=2.0)) viz.mouse.setVisible(viz.OFF) # initialize camera and map self.camera = viz.MainView self.map = viz.add(self.config[0]) self.camX = self.config[1] self.camY = self.config[2] self.camZ = self.config[3] self.camAngle = self.camera.getAxisAngle() self.camVector = [0, 0, 0] self.bulletVector = [0, 0, 0] # initialize gun self.gun = viz.add('gun.dae') # track active bullets self.bullets = [] # reload indicator self.reload = viz.addText3D(' R\n to Reload') self.reload.color(viz.WHITE) self.reload.font('COURIER NEW') self.reload.visible(viz.OFF) self.gunX = self.config[1] self.gunY = self.config[2] self.gunZ = self.config[3] + 2 mat = viz.Matrix() mat.postTrans(self.gunX, self.gunY, self.gunZ) self.gun.setMatrix(mat) # position the camera self.setCameraTransforms() # add enemies enemyCoords = self.config[4] self.enemyList = [] counter = 0 for x, y, z, radius in enemyCoords: self.enemyList.append(viz.add('model.dae')) mat = viz.Matrix() mat.postScale(0.125, 0.125, 0.125) mat.postTrans(x, y, z) self.enemyList[counter].setMatrix(mat) counter += 1 # scoring variables self.enemyCount = 0 for enemy in self.enemyList: self.enemyCount += 1 self.score = 0 # game over variables self.gameIsOver = False self.gameOverText = None # add a sky self.sky = viz.add(viz.ENVIRONMENT_MAP, 'sky.jpg') self.skybox = viz.add('skydome.dlc') self.skybox.texture(self.sky) # enable physics self.setPhysics() self.callback(viz.TIMER_EVENT, self.onTimer) self.callback(viz.MOUSEDOWN_EVENT, self.onMouseDown) self.callback(viz.COLLIDE_BEGIN_EVENT, self.onCollide) self.callback(viz.COLLISION_EVENT, self.camCollide) self.callback(viz.KEYDOWN_EVENT, self.onKeyDown) self.starttimer(0, 1 / 2, viz.FOREVER)