def setupScene(self): self.sceneManager = self.root.createSceneManager( ogre.ST_GENERIC, "Default SceneManager") self.camera = self.sceneManager.createCamera("Camera") self.camera.nearClipDistance = 2 self.viewPort = self.root.getAutoCreatedWindow().addViewport( self.camera) self.sceneManager.ambientLight = 100, 100, 100 # Setup a ground plane. #plane = ogre.Plane ((0, 1, 0), -100) #plane = ogre.Plane ((0, 1, 0), 0) self.groundPlane = ogre.Plane((0, 1, 0), 0) meshManager = ogre.MeshManager.getSingleton() meshManager.createPlane('Ground', 'General', self.groundPlane, 100, 100, 20, 20, True, 1, 5, 5, (0, 0, 1)) ent = self.sceneManager.createEntity('GroundEntity', 'Ground') self.sceneManager.getRootSceneNode().createChildSceneNode( ).attachObject(ent) ent.setMaterialName('1335851461_1_outline.png') #self.sceneManager.setSkyBox (True, "Examples/MorningSkyBox", 5000, False) self.camYawNode = self.sceneManager.getRootSceneNode( ).createChildSceneNode( 'CamNode1', #(-400, 200, 400)) (0, 8, 0)) #node.yaw(ogre.Degree(-45)) self.camYawNode.yaw(ogre.Degree(0)) self.camera.lookAt((0, 0, 0)) self.camPitchNode = self.camYawNode.createChildSceneNode('PitchNode1') self.camPitchNode.attachObject(self.camera) self.camPitchNode.pitch(ogre.Degree(-90))
def __createRotatePivot(self): self.xRotateEntity = self.sceneManager.createEntity( "EditorXRotator", "Rotate_Torus.mesh") self.xRotateEntity.setMaterialName("Lockenwickler_Pivot_X") self.xRotateEntity.setRenderQueueGroup(og.RENDER_QUEUE_OVERLAY - 1) self.xRotateNode = self.pivotNode.createChildSceneNode() self.xRotateNode.attachObject(self.xRotateEntity) #self.xRotateNode.translate(0, 0, -5) self.xRotateNode.rotate(og.Vector3().UNIT_Y, og.Degree(90)) self.yRotateEntity = self.sceneManager.createEntity( "EditorYRotator", "Rotate_Torus.mesh") self.yRotateEntity.setMaterialName("Lockenwickler_Pivot_Y") self.yRotateEntity.setRenderQueueGroup(og.RENDER_QUEUE_OVERLAY - 1) self.yRotateNode = self.pivotNode.createChildSceneNode() self.yRotateNode.attachObject(self.yRotateEntity) #self.yRotateNode.translate(0, 0, -10) self.yRotateNode.rotate(og.Vector3().UNIT_X, og.Degree(90)) self.zRotateEntity = self.sceneManager.createEntity( "EditorZRotator", "Rotate_Torus.mesh") self.zRotateEntity.setMaterialName("Lockenwickler_Pivot_Z") self.zRotateEntity.setRenderQueueGroup(og.RENDER_QUEUE_OVERLAY - 1) self.zRotateNode = self.pivotNode.createChildSceneNode() self.zRotateNode.attachObject(self.zRotateEntity)
def _createCamera(robot, name, position, direction): """Lets hack on a camera (integrate better in the future)""" sceneMgr = ogre.Root.getSingleton().getSceneManager('Main') if sceneMgr.hasCamera(name): return sceneMgr.getCamera(name) node = robot._main_part._node # Create camera and attached it to our ourself camera = sceneMgr.createCamera(name) # Align and Position camera.position = position camera.lookAt(camera.position + ram.sim.OgreVector3(direction)) camera.nearClipDistance = 0.05 node.attachObject(camera) # This needs be set from the config file (only VERTICAL FOV) camera.FOVy = ogre.Degree(78) # NOTE: Fix not needed because camera on the vehicle is offset in the # same way, what an odd coincidence # Account for the odd up vector difference between our and Ogre's # default coordinate systems camera.roll(ogre.Degree(-90)) return camera
def __createScalePivot(self): self.xScaleEntity = self.sceneManager.createEntity( "EditorXScaler", "Pivot_Arrow.mesh") self.xScaleEntity.setMaterialName("Lockenwickler_Pivot_X") self.xScaleEntity.setRenderQueueGroup(og.RENDER_QUEUE_OVERLAY - 1) self.xScaleNode = self.pivotNode.createChildSceneNode() self.xScaleNode.attachObject(self.xScaleEntity) self.xScaleNode.translate(og.Vector3(2, 0, 0)) self.xScaleNode.rotate(og.Vector3().UNIT_Y, og.Degree(90)) self.yScaleEntity = self.sceneManager.createEntity( "EditorYScaler", "Pivot_Arrow.mesh") self.yScaleEntity.setMaterialName("Lockenwickler_Pivot_Y") self.yScaleEntity.setRenderQueueGroup(og.RENDER_QUEUE_OVERLAY - 1) self.yScaleNode = self.pivotNode.createChildSceneNode() self.yScaleNode.attachObject(self.yScaleEntity) self.yScaleNode.translate(og.Vector3(0, 2, 0)) self.yScaleNode.rotate(og.Vector3().UNIT_X, og.Degree(-90)) self.zScaleEntity = self.sceneManager.createEntity( "EditorZScaler", "Pivot_Arrow.mesh") self.zScaleEntity.setMaterialName("Lockenwickler_Pivot_Z") self.zScaleEntity.setRenderQueueGroup(og.RENDER_QUEUE_OVERLAY - 1) self.zScaleNode = self.pivotNode.createChildSceneNode() self.zScaleNode.attachObject(self.zScaleEntity) self.zScaleNode.translate(og.Vector3(0, 0, 2)) self.uniScaleEntity = self.sceneManager.createEntity( "UniScaler", "UniCube.mesh") self.uniScaleEntity.setMaterialName("Lockenwickler_FreeMover") self.uniScaleEntity.setRenderQueueGroup(og.RENDER_QUEUE_OVERLAY - 1) self.uniScaleNode = self.pivotNode.createChildSceneNode() self.uniScaleNode.attachObject(self.uniScaleEntity)
def _processUnbufferedMouseInput(self, frameEvent): ms = self.Mouse.getMouseState() if ms.buttonDown(OIS.MB_Right): self.translateVector.x += ms.X.rel * 0.13 self.translateVector.y -= ms.Y.rel * 0.13 else: self.rotationX = ogre.Degree(-ms.X.rel * 0.13) self.rotationY = ogre.Degree(-ms.Y.rel * 0.13)
def createCamera(self): self.camera = self.sceneManager.createCamera("Camera") self.camera.nearClipDistance = 10 yawNode = self.sceneManager.getRootSceneNode().createChildSceneNode("RTSCamNode", (0, 1000, 3300)) yawNode.yaw(ogre.Degree(0)) yawNode.pitch(ogre.Degree(-25)) yawNode.createChildSceneNode("RTSPitchNode").attachObject(self.camera) self.camera.lookAt = (0, 0, 0)
def rotate(self, h_angle, v_angle): cam_focus = self.sceneManager.getSceneNode("CameraFocus") self.v_angle += v_angle self.h_angle += h_angle q = ogre.Quaternion(ogre.Degree(self.h_angle), ogre.Vector3().UNIT_Z) r = ogre.Quaternion(ogre.Degree(self.v_angle), ogre.Vector3().UNIT_X) q = q * r cam_focus.setOrientation(q)
def update(self, time_since_last_frame): moveUnit = 5 * time_since_last_frame # A really bad way to generate the rotation vectors I want # Moves us in the Z (up/down direction) height = Ogre.Vector3(0, 0, moveUnit) # We ignore z, because that always go up and down relative to the world # axes. Here we want forward and side to be relative to the direction # the camera is facing. toCamera = self._camera.getRealPosition() - self._camera_node.position toCamera.z = 0 quat = Ogre.Vector3.UNIT_X.getRotationTo(toCamera) # Moves us in the X (Forward/back direction) trans = quat * Ogre.Vector3(-moveUnit, 0, 0) trans.z = 0 # Moves us in the Y (Left/Right direction) strafe = quat * Ogre.Vector3(0, moveUnit, 0) strafe.z = 0 if self.original_parent is None: if self._forward: self._camera_node.translate(trans) #, Ogre.Node.TS_WORLD) if self._backward: self._camera_node.translate(trans * -1.0) #, Ogre.Node.TS_WORLD) if self._up: self._camera_node.translate(height) #, Ogre.Node.TS_WORLD) if self._down: self._camera_node.translate(height * -1.0) #, Ogre.Node.TS_WORLD) if self._left: self._camera_node.translate(strafe * -1.0) #, Ogre.Node.TS_WORLD) if self._right: self._camera_node.translate(strafe) #, Ogre.Node.TS_WORLD) pos = self._camera.position if self._zoom_in: self._camera.setPosition(pos + (pos * -moveUnit / 3)) if self._zoom_out: self._camera.setPosition(pos + (pos * moveUnit / 3)) if self._pitch_up: self._camera_node.yaw(Ogre.Degree(moveUnit * 6)) if self._pitch_down: self._camera_node.yaw(Ogre.Degree(-moveUnit * 6)) if self._yaw_left: self._camera_node.roll(Ogre.Degree(-moveUnit * 6), Ogre.Node.TS_WORLD) if self._yaw_right: self._camera_node.roll(Ogre.Degree(moveUnit * 6), Ogre.Node.TS_WORLD)
def _createCamera(self): # creating the cameras # Tkinter.Tk().withdraw() # global file_path # self.openOpt = options = {} # options['initialdir'] = wDir+'\..\..\..\Configurations' # options['title'] = 'Select experiment parameters' # #file_path = tkFileDialog.askopenfilename(**self.openOpt) # asking which experiment to load? # file_path = u'C:/LuigsNeumann_Treadmill/Configurations/20181001ReducedMazeSet.xlsx' # wb = load_workbook(file_path) # ws = wb.get_active_sheet() self.numMonitors = 3 #int(ws.cell('C46').value) self.resolution = [ 1024, 768 ] #map(int,re.findall(r'\d+',ws.cell('C47').value)) # 1024 x 768 #This value represents the VERTICAL field-of-view. # The horizontal field of view is calculated from this depending on the dimensions of the viewport # (they will only be the same if the viewport is square). if self.numMonitors == 5: FOV = 34 else: FOV = 73.74 self.camera = self.sceneManager.createCamera('PlayerCam') self.camera.nearClipDistance = 1 self.camera.setFOVy(ogre.Degree(FOV)) camH = 4.9 # self.camera.pitch(ogre.Degree(22)) # to pitch the camera towards the sky self.camera.setPosition(ogre.Vector3(0, camH, 0)) if self.numMonitors >= 3: self.cameraL = self.sceneManager.createCamera('CamL') self.cameraL.nearClipDistance = 1 self.cameraL.setFOVy(ogre.Degree(FOV)) self.cameraR = self.sceneManager.createCamera('CamR') self.cameraR.nearClipDistance = 1 self.cameraR.setFOVy(ogre.Degree(FOV)) self.cameraL.setPosition(ogre.Vector3(0, camH, 0)) self.cameraR.setPosition(ogre.Vector3(0, camH, 0)) if self.numMonitors == 5: self.cameraLL = self.sceneManager.createCamera('CamLL') self.cameraLL.nearClipDistance = 1 self.cameraLL.setFOVy(ogre.Degree(FOV)) self.cameraRR = self.sceneManager.createCamera('CamRR') self.cameraRR.nearClipDistance = 1 self.cameraRR.setFOVy(ogre.Degree(FOV)) self.renderWindow.resize( max(1, self.numMonitors) * self.resolution[0], self.resolution[1] + 30) # window size and position # self.renderWindow.reposition(-(max(1,self.numMonitors)-1)/2*self.resolution[0],-30) # self.renderWindow.reposition(-3*self.resolution[0],-30) self.renderWindow.reposition(-3080, -30)
def _onMouseMoved(self, _evt): """Mouse moved event """ mstate = _evt.get_state() prev_pos = self.mouse_pos self.mouse_pos = (mstate.X.abs, mstate.Y.abs) # move object if self.state is SCgEditMode.ES_Move: pos = self.move_obj.getPosition() #self.move_obj.setPosition((pos[0] + dpos[0], pos[1] + dpos[1])) if render_engine.viewMode is render_engine.Mode_Isometric: self.move_obj.setPosition( render_engine.pos2dTo3dIsoPos(self.mouse_pos)) else: self.move_obj.setPosition( render_engine.pos2dToViewPortRay( self.mouse_pos).getPoint(25.0)) # if self.vis_menu.isShow(): self.vis_menu.move(self.mouse_pos) return True elif self.state is SCgEditMode.ES_LineCreate: pos = render_engine.pos2dTo3dIsoPos(self.mouse_pos) self.line_mode_obj.setPosition(pos) self._updateLineCreationObjects() self._highlight() return True elif self.state is SCgEditMode.ES_BusCreate: pos = render_engine.pos2dTo3dIsoPos(self.mouse_pos) self.line_mode_obj.setPosition(pos) self._updateLineCreationObjects() self._highlight() return True elif self.state is SCgEditMode.ES_Translate: if render_engine.viewMode is render_engine.Mode_Isometric: render_engine._ogreCameraNode.translate( -mstate.X.rel / float(render_engine.scale2d), mstate.Y.rel / float(render_engine.scale2d), 0.0) self._logic._getSheet()._updateChildTexts() else: self.rotX = ogre.Degree(-mstate.X.rel * 0.13) self.rotY = ogre.Degree(-mstate.Y.rel * 0.13) #FIXME: add perspective mode # scaling if self._ctrl and mstate.Z.rel != 0 and render_engine.viewMode == render_engine.Mode_Isometric: sc = 1.0 + mstate.Z.rel / 1200.0 sheet = self._logic._getSheet() sheet.setScale(sheet.getScale() * sc) self._highlight() return False
def _onMouseMoved(self, _evt): """Mouse moved event """ if BaseEditMode._onMouseMoved(self, _evt): return True mstate = _evt.get_state() self.mouse_pos = (mstate.X.abs, mstate.Y.abs) self._highlight() if self.navigation: self.rotX = ogre.Degree(-mstate.X.rel * 0.13) self.rotY = ogre.Degree(-mstate.Y.rel * 0.13) return False
def _spawnMarker(self): # Now lets spawn an object obj = scene.SceneObject() position = self._robot._main_part._node.position robotOrient = self._robot._main_part._node.orientation # 30cm below robot offset = ogre.Vector3(0.15, 0.30 - (self._count * 0.2), -0.10) position = position + robotOrient * offset orientation = ogre.Quaternion(ogre.Degree(90), ogre.Vector3.UNIT_X) cfg = { 'name' : self._name + str(self._count), 'position' : position, 'Graphical' : { 'mesh' : 'cylinder.mesh', 'scale' : [0.0762, 0.0127, 0.0127], 'material' : 'Simple/Red', 'orientation' : orientation * robotOrient }, 'Physical' : { 'mass' : 0.01, 'center_of_mass' : [0, 0, 0.0127], # Top heavy 'orientation' : orientation * robotOrient, 'Shape' : { 'type' : 'cylinder', 'radius' : 0.0127, 'height' : 0.0762 } } } obj.load((self._scene, None, cfg)) self._scene._objects.append(obj)
def setupScene(self): self.sceneManager = self.root.createSceneManager( ogre.ST_GENERIC, "Default SceneManager") self.camera = self.sceneManager.createCamera("Camera") self.camera.nearClipDistance = 5 self.viewPort = self.root.getAutoCreatedWindow().addViewport( self.camera) self.sceneManager.ambientLight = 1, 1, 1 # Setup a ground plane. #plane = ogre.Plane ((0, 1, 0), -100) #plane = ogre.Plane ((0, 1, 0), 0) self.groundPlane = ogre.Plane((0, 1, 0), 0) meshManager = ogre.MeshManager.getSingleton() meshManager.createPlane('Ground', 'General', self.groundPlane, 5000, 5000, 20, 20, True, 1, 5, 5, (0, 0, 1)) self.ent = self.sceneManager.createEntity('GroundEntity', 'Ground') self.sceneManager.getRootSceneNode().createChildSceneNode( ).attachObject(self.ent) self.ent.setMaterialName('OceanCg') self.ent.castShadows = False #self.sceneManager.setSkyDome (True, "Examples/CloudySky", 5000, False) self.camYawNode = self.sceneManager.getRootSceneNode( ).createChildSceneNode( 'CamNode1', #(-400, 200, 400)) (0, 1500, -2000)) #node.yaw(ogre.Degree(-45)) self.camYawNode.yaw(ogre.Degree(0)) self.camera.lookAt((0, -800, 350)) self.camPitchNode = self.camYawNode.createChildSceneNode('PitchNode1') self.camPitchNode.attachObject(self.camera) self.camPitchNode.pitch(ogre.Radian(-0.4))
def __init__(self, engine, id, pos = MyVector(0, 0 ,0), vel = MyVector(0, 0, 0), yaw = 0, team = 0): self.team = team Entity.__init__(self, engine, id, pos = pos, vel = vel, yaw = yaw) print "player init" self.mesh = 'ninja.mesh' self.uiname = 'BVB' + str(BVB.id) BVB.id += 1 self.acceleration = 360 self.turningRate = 120 self.maxSpeed = 400 self.desiredSpeed = 0 self.desiredHeading = 0 self.speed = 0 self.heading = 0 self.wakeSize = 'Large' self.offset = ogre.Degree(-90) self.hasAnimation = True self.scale = ogre.Vector3(.5, .5, .5) self.material = "Examples/YellowTeam" self.color = "RedCircle" self.circle = None self.team = team self.radiiNorm = 115.0 self.radiiSlide = 200.0
def __init__(self, name, scene, position, offset, orientation, near_clip=0.5): offset = sim.OgreVector3(offset) self._camera = scene.scene_mgr.createCamera(name) self._camera.nearClipDistance = near_clip self._camera.setFixedYawAxis(False) # Place the camera out in front at the needed distance self._camera.position = (offset.length(), 0, 0) # Make it face back toward zero self._camera.lookAt((0, 0, 0)) # Account for the odd up vector difference between our and Ogre's # default coordinate systems self._camera.roll(Ogre.Degree(90)) # Apply custom rotation if desired self._camera.rotate(orientation) # Allows easier movement of camera self._node = scene.scene_mgr.getRootSceneNode().createChildSceneNode() self._node.position = (0, 0, 0) self._node.attachObject(self._camera) # Rotate the node to place the camera in its desired offset position # Do the in plane rotation, then up rotation to keep the cameras up # facing the proper way inPlane = Ogre.Vector3(offset.x, offset.y, 0) if inPlane.length() != 0: self._node.rotate(self._camera.position.getRotationTo(inPlane)) else: # The camera is directly above or below self._camera.roll(Ogre.Degree(180)) inPlane = Ogre.Vector3.UNIT_X self._node.rotate(inPlane.getRotationTo(offset), Ogre.Node.TS_WORLD) # position camera self._node.position = position
def frameStarted(self, evt): # print('frame started') self.Mouse.capture() self.Keyboard.capture() if (self.mWindow.isActive() == False): return False if (self.mQuit): return False else: if self.bReload: self.app.s_root.removeAndDestroyAllChildren() self.app._build_scene() self.bReload = False self.mSkipCount += 1 if (self.mSkipCount >= self.mUpdateFreq): self.mSkipCount = 0 # # # self.updateStats() ## update movement process if (self.mProcessMovement or self.mUpdateMovement): if self.mMoveLeft: self.mTranslateVector.x += self.mAvgFrameTime * -self.mMoveSpeed if self.mMoveRight: self.mTranslateVector.x += self.mAvgFrameTime * self.mMoveSpeed if self.mMoveFwd: self.mTranslateVector.z += self.mAvgFrameTime * -self.mMoveSpeed if self.mMoveBck: self.mTranslateVector.z += self.mAvgFrameTime * self.mMoveSpeed self.camera.yaw(ogre.Degree(self.mRotX)) self.camera.pitch(ogre.Degree(self.mRotY)) self.camera.moveRelative(self.mTranslateVector) self.mUpdateMovement = False self.mRotX = 0 self.mRotY = 0 self.mTranslateVector = ogre.Vector3().ZERO if (self.mWriteToFile): self.mNumScreenShots += 1 self.mWindow.writeContentsToFile("frame_" + str(self.mNumScreenShots) + ".png") return True
def frameRenderingQueued ( self, evt ): if(self.renderWindow.isClosed() or self.shouldQuit ): return False if self.unittest: self.unittest_duration -= evt.timeSinceLastFrame if self.unittest_duration < 0: self.renderWindow.writeContentsToFile(self.unittest_screenshot + '.jpg') return False #Need to capture/update each device - this will also trigger any listeners self.Keyboard.capture() self.Mouse.capture() buffJ = True if( self.Joy ): self.Joy.capture() buffJ = self.Joy.buffered() #Check if one of the devices is not buffered if not self.Mouse.buffered() or not self.Keyboard.buffered() or not buffJ : # one of the input modes is immediate, so setup what is needed for immediate movement if self.timeUntilNextToggle >= 0: self.timeUntilNextToggle -= evt.timeSinceLastFrame # Move about 100 units per second self.moveScale = self.moveSpeed * evt.timeSinceLastFrame # Take about 10 seconds for full rotation self.rotScale = self.rotateSpeed * evt.timeSinceLastFrame self.rotationX = ogre.Degree(0.0) self.rotationY = ogre.Degree(0.0) self.translateVector = ogre.Vector3().ZERO #Check to see which device is not buffered, and handle it if not self.Keyboard.buffered(): if not self._processUnbufferedKeyInput(evt): return False if not self.Mouse.buffered(): if not self._processUnbufferedMouseInput(evt): return False if not self.Mouse.buffered() or not self.Keyboard.buffered() or not buffJ: self._moveCamera(evt) self._updateSimulation(evt) return True
def _createScene(self): sceneManager = self.sceneManager sceneManager.ambientLight = (0, 0, 0) sceneManager.shadowTechnique = ogre.SHADOWTYPE_STENCIL_ADDITIVE ent = sceneManager.createEntity("Ninja", "ninja.mesh") ent.castShadows = True sceneManager.getRootSceneNode().createChildSceneNode().attachObject( ent) plane = ogre.Plane((0, 1, 0), 0) meshManager = ogre.MeshManager.getSingleton() meshManager.createPlane("Ground", "General", plane, 1500, 1500, 20, 20, True, 1, 5, 5, (0, 0, 1)) ent = sceneManager.createEntity("GroundEntity", "Ground") sceneManager.getRootSceneNode().createChildSceneNode().attachObject( ent) ent.setMaterialName("Examples/Rockwall") ent.castShadows = False #point light and properties light = sceneManager.createLight("PointLight") light.type = ogre.Light.LT_POINT light.position = (150, 300, 150) light.diffuseColour = (.5, .0, .0) light.specularColour = (.5, .0, .0) #directional light and properties light = sceneManager.createLight("DirectionalLight") light.type = ogre.Light.LT_DIRECTIONAL light.diffuseColour = (.5, .5, .0) light.specularColour = (.75, .75, .75) light.direction = (0, -1, 1) #spot light and properties light = sceneManager.createLight("spotLight") light.type = ogre.Light.LT_SPOTLIGHT light.diffuseColour = (0, 0, .5) light.specularColour = (0, 0, .5) light.direction = (-1, -1, 0) light.position = (300, 300, 0) light.setSpotlightRange(ogre.Degree(35), ogre.Degree(50))
def __init__(self, ent): self.ent = ent self.entOgre = self.ent.engine.gfxMgr.sceneManager.createEntity( self.ent.uiname + str(self.ent.engine.entityMgr.nEnts), self.ent.mesh) self.node = self.ent.engine.gfxMgr.sceneManager.getRootSceneNode( ).createChildSceneNode(self.ent.uiname + 'node', self.ent.pos) self.node.attachObject(self.entOgre) self.ent.node = self.node self.node.scale(self.ent.scale) wakeOffsetz = self.entOgre.getBoundingBox().getSize().z / 2 wakeOffsetx = self.entOgre.getBoundingBox().getSize().x / 2 #for jetski and models that are not facing right if self.ent.offset != 0: #add wake and offset 3rd person camera because lookat won't work self.wakeNode = self.node.createChildSceneNode( ogre.Vector3(0, 0, -wakeOffsetz)) camNode = self.node.createChildSceneNode( self.ent.uiname + 'camNode', ogre.Vector3(0, 2 * wakeOffsetx, -3 * wakeOffsetz)) camNode.yaw(ogre.Degree(180)) else: self.wakeNode = self.node.createChildSceneNode( ogre.Vector3(-wakeOffsetx, 0, 0)) #adjust yaw and pitch because lookat isn't working camNode = self.node.createChildSceneNode( self.ent.uiname + 'camNode', ogre.Vector3(-3 * wakeOffsetx, 2 * wakeOffsetz, 0)) camNode.yaw(ogre.Degree(-90)) self.wakeParticle = self.ent.engine.gfxMgr.sceneManager.createParticleSystem( self.ent.uiname + str(self.ent.engine.entityMgr.nEnts) + "_wake", 'Water/Wake' + self.ent.wakeSize) self.wakeNode.attachObject(self.wakeParticle)
def setSize(self, size): if self.m_size is not size: self.m_size = size #m_frustProj.setAspectRatio(m_size.x / m_size.y) self.m_frustProj.setOrthoWindow(self.m_size.x, self.m_size.y) # set fovy so that tan = 1, so 45 degrees self.m_frustProj.setFOVy(og.Degree(45)) # set near clip plane according to fovy: self.m_frustProj.setNearClipDistance(self.m_size.y)
def frameStarted(self, frameEvent): if self.timeUntilNextToggle >= 0: self.timeUntilNextToggle -= frameEvent.timeSinceLastFrame if frameEvent.timeSinceLastFrame == 0: self.moveScale = 1 self.rotationScale = 0.1 else: self.moveScale = self.moveSpeed * frameEvent.timeSinceLastFrame self.rotationScale = self.rotationSpeed * frameEvent.timeSinceLastFrame self.rotationX = ogre.Degree(0.0) self.rotationY = ogre.Degree(0.0) self.translateVector = ogre.Vector3(0.0, 0.0, 0.0) if not self._processUnbufferedKeyInput(frameEvent): return False if not self.MenuMode: # if we are in Menu mode we don't move the camera.. self._processUnbufferedMouseInput(frameEvent) self._moveCamera() return True
def _createScene(self): self.surfaceHeight = 0 # Setup a scene with a low level of ambient light. sceneManager = self.sceneManager sceneManager.ambientLight = (0.78, 0.89, 1) sceneManager.shadowTechnique = ogre.SHADOWTYPE_STENCIL_ADDITIVE # Setup a mesh entity and attach it to a scene node. entity = sceneManager.createEntity('Cube0', 'cube.mesh') node = sceneManager.getRootSceneNode().createChildSceneNode( 'CubeNode0', (0, 0, 0)) node.attachObject(entity) entity = sceneManager.createEntity('Cube1', 'cube.mesh') node = sceneManager.getRootSceneNode().createChildSceneNode( 'CubeNode1', (100, 200, 0)) node.attachObject(entity) plane = ogre.Plane((0, 1, 0), self.surfaceHeight) meshManager = ogre.MeshManager.getSingleton() meshManager.createPlane("Ground", "General", plane, 10000, 10000, 20, 20, True, 1, 5, 5, (0, 0, 1)) ent = sceneManager.createEntity("GroundEntity", "Ground") sceneManager.getRootSceneNode().createChildSceneNode().attachObject( ent) ent.setMaterialName("Examples/TextureEffect2") #ent.setMaterialName("Examples/Rockwall") ent.castShadows = False self.sceneManager.setSkyDome(True, "Examples/CloudySky", 5, 8) # Setup a White point light. light = sceneManager.createLight('Light1') light.type = ogre.Light.LT_POINT light.position = (150, 300, 150) light.diffuseColour = (1, 1, 1) light.specularColour = (1, 1, 1) # Setup the first camera node and pitch node and aim it. node = sceneManager.getRootSceneNode().createChildSceneNode( 'CamNode1', (-400, 200, 400)) node.yaw(ogre.Degree(-45)) node = node.createChildSceneNode('PitchNode1') node.attachObject(self.camera) # Setup the second camera node and pitch node. node = sceneManager.getRootSceneNode().createChildSceneNode( 'CamNode2', (0, 200, 400)) node.createChildSceneNode('PitchNode2')
def tick(self, dtime): self.ent.node.setPosition(self.ent.pos) self.ent.node.resetOrientation() #for jetski self.wakeNode.yaw(self.ent.offset) self.ent.node.yaw(self.ent.offset) self.ent.node.yaw(ogre.Degree(self.ent.heading)) if self.ent.speed > 0: self.wakeNode.setVisible(True) else: self.wakeNode.setVisible(False)
def __init__(self, renderWindow, camera, bufferedKeys = False, bufferedMouse = False, bufferedJoy = False): ogre.FrameListener.__init__(self) ogre.WindowEventListener.__init__(self) self.camera = camera self.renderWindow = renderWindow self.statisticsOn = True self.numScreenShots = 0 self.timeUntilNextToggle = 0 self.sceneDetailIndex = 0 self.moveScale = 0.0 self.rotationScale = 0.0 self.translateVector = ogre.Vector3(0.0,0.0,0.0) self.filtering = ogre.TFO_BILINEAR self.showDebugOverlay(True) self.rotateSpeed = ogre.Degree(36) self.moveSpeed = 100.0 self.rotationSpeed = 8.0 self.displayCameraDetails = False self.bufferedKeys = bufferedKeys self.bufferedMouse = bufferedMouse self.rotationX = ogre.Degree(0.0) self.rotationY = ogre.Degree(0.0) self.bufferedJoy = bufferedJoy self.shouldQuit = False # set to True to exit.. self.MenuMode = False # lets understand a simple menu function self.unittest = isUnitTest() self.unittest_duration = UnitTest_Duration() # seconds before screen shot a exit # self.unittest_screenshot = sys.modules['__main__'].__file__.split('.')[0] # file name for unittest screenshot self.unittest_screenshot = UnitTest_Screenshot() ## we can tell if we are using OgreRefapp based upon the camera class if self.camera.__class__ == ogre.Camera: self.RefAppEnable = False else: self.RefAppEnable = True self._setupInput()
def Quat(*args, **kwargs): """ Converts to list of values to a Quaternion, either with axis angles, when the flag is true, the last value is treated as the angle. Otherwise its (w,x,y,z) """ values = args # Assumes each argument is an element if len(values) == 1: values = args[0] if kwargs.has_key('axis_angle') and kwargs['axis_angle'] == True: return Ogre.Quaternion(Ogre.Degree(d=values[3]), Vector(values, length=3)) else: return Ogre.Quaternion(values[0], values[1], values[2], values[3])
def setupScene(self): ## Load the level. # @todo: Remove .scene dependancy and move to external file (format?). # Load some data from the .scene file sceneLoader = SceneLoader.DotSceneLoader("media/testtilescene.scene", self.sceneManager) sceneLoader.parseDotScene() # Create the world. self.world = gamestate.world.World() # Attach a handler to world.object_added self.world.object_added += self.on_world_object_added # Add a player to the world and set it as our active player. self.player = gamestate.objects.Player(self.world) self.world.add_object(self.player) # Add stationary NPC ninja... npc = gamestate.objects.Player(self.world) self.world.add_object(npc) npc.position = (-500, 0) npc.isPassable = False # Add boundary lines for map walls. self.setup_level_boundaries("media/levelbounds.bounds") # Listen to player events. self.player.position_changed += self.on_player_position_changed self.player.element_changed += self.on_player_element_changed # Setup camera self.camera.nearClipDistance = 1 self.camera.farClipDistance = 500 self.camera.setProjectionType(ogre.PT_ORTHOGRAPHIC) # THIS SPECIFIES THE HEIGHT OF THE ORTHOGRAPHIC WINDOW # the width will be recalculated based on the aspect ratio # in ortho projection mode, decreasing the size of the window # is equivalent to zooming in, increasing is the equivalent of # zooming out. self.camera.setOrthoWindowHeight(200) # Setup camera node self.cameraNode.position = (0, 100, 100) self.cameraNode.pitch(ogre.Degree(-45))
def tick(self, dtime): if (self.ent.mesh == "sphere.mesh"): self.entOgre.setMaterialName("Ball") elif (self.ent.hasAnimation and self.ent.material): self.entOgre.setMaterialName(self.ent.material) self.ent.node.setPosition(self.ent.pos) self.ent.node.resetOrientation() #for jetski self.wakeNode.yaw(self.ent.offset) self.ent.node.yaw(self.ent.offset) self.ent.node.yaw(ogre.Degree(self.ent.heading)) if (self.ent.mesh == "post.mesh"): #self.ent.node.pitch(200) #self.ent.node.roll(90) #self.ent.node.yaw(90) pass if (self.ent.slide): if (self.ent.heading > 180): self.node.roll(80) if (self.ent.heading <= 180): self.node.roll(-80) if (self.ent.hasAnimation): if self.ent.speed > 0: self.wakeNode.setVisible(True) self.animationState = self.entOgre.getAnimationState('Walk') self.animationState.setLoop(True) self.animationState.setEnabled(True) self.animationState.addTime(2 * dtime) else: self.wakeNode.setVisible(False) self.animationState = self.entOgre.getAnimationState('Idle1') self.animationState.setLoop(True) self.animationState.setEnabled(True) self.animationState.addTime(dtime) else: if self.ent.speed > 0: ent = self.ent self.ent.node.pitch(ent.vel.x)
def __init__(self, ent, angle=ogre.Degree(8), ttl=9, particleVelocity=(1, 3), emissionRate=90, direction=Vector3(-1, 0, 0), position=Vector3(0, -10, 0)): self.ent = ent self.emitter = self.ent.pSystem.addEmitter("Point") self.emitter.setAngle(angle) self.emitter.setTimeToLive(ttl) low, high = particleVelocity self.emitter.setParticleVelocity(low, high) self.emitter.setDirection(direction) self.emitter.setEmissionRate(emissionRate) self.emitter.setPosition(position)
def _updateLengthPosition(self): """Recalculate length text position """ if self.length_text_obj: # get center p1 = self.getBegin().getPosition() p2 = self.getEnd().getPosition() pm = p1.midPoint(p2) angle = math.atan2(p2.y - p1.y, p2.x - p1.x) angle = ogre.Radian(angle) + ogre.Degree(90.0).valueRadians() angle = angle.valueRadians() r = 0.2 self.length_text_obj.setPosition( ogre.Vector3(r * math.cos(angle), r * math.sin(angle), 0.0) + pm)
def _createScene(self): #initialize surface height self.surfaceHeight = 0 #make the room slightly lit sceneManager = self.sceneManager sceneManager.ambientLight = (0.78, 0.89, 1) sceneManager.shadowTechnique = ogre.SHADOWTYPE_STENCIL_ADDITIVE #add cube that is able to cast shadow to scene ent = sceneManager.createEntity("Cube", "cube.mesh") ent.castShadows = True sceneManager.getRootSceneNode().createChildSceneNode( "CubeNode").attachObject(ent) #create a plane and register it with mesh manager plane = ogre.Plane((0, 1, 0), self.surfaceHeight) meshManager = ogre.MeshManager.getSingleton() meshManager.createPlane("Ground", "General", plane, 10000, 10000, 20, 20, True, 1, 5, 5, (0, 0, 1)) #Ground plane ent = sceneManager.createEntity("GroundEntity", "Ground") sceneManager.getRootSceneNode().createChildSceneNode().attachObject( ent) #ent.setMaterialName("Examples/TextureEffect2") ent.setMaterialName("Examples/Rockwall") ent.castShadows = False node = sceneManager.getRootSceneNode().createChildSceneNode( 'CamNode1', (-400, 200, 400)) node.yaw(ogre.Degree(-45)) node = node.createChildSceneNode('PitchNode1') node.attachObject(self.camera) self.sceneManager.setSkyDome(True, "Examples/CloudySky", 5, 8) #point light and properties light = sceneManager.createLight("Sun") light.type = ogre.Light.LT_POINT light.position = (150, 300, 150) light.diffuseColour = (1, 1, 1) light.specularColour = (1, 1, 1)