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 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 _update(self, _timeSinceLastFrame): objects.ObjectDepth._update(self, _timeSinceLastFrame) if not self.year == 0: self.time_year += _timeSinceLastFrame if self.time_year > self.year: self.time_year -= self.year # calculate object an = pi2 * float(self.time_year) / self.year self.setPosition( ogre.Vector3(self.orbA * math.cos(an), 0, self.orbB * math.sin(an))) if not self.day == 0: self.time_day += _timeSinceLastFrame if self.time_day > self.day: self.time_day -= self.day self.sceneNode.setOrientation( ogre.Quaternion(ogre.Radian(pi2 * self.time_day / self.day), ogre.Vector3(0, 1, 0))) # update child objects childs = self.getChilds() for child in childs: child._update(_timeSinceLastFrame)
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 createAnimation(self): pointNum = 32 period = self.year node = self.sceneNode sceneManager = render_engine._ogreSceneManager self.animation_orb = sceneManager.createAnimation( str(self) + "_orb", period) self.animation_orb.interpolationMode = ogre.Animation.IM_SPLINE animationTrack = self.animation_orb.createNodeTrack(0, node) an = 0 for i in range(pointNum): key = animationTrack.createNodeKeyFrame(i * period / pointNum) key.setTranslate( ogre.Vector3(self.orbA * math.cos(an), 0, self.orbB * math.sin(an))) an += 6.28 / pointNum key = animationTrack.createNodeKeyFrame(period) key.setTranslate(ogre.Vector3(1, 0, 0) * self.orbA) self.orbAnimState = sceneManager.createAnimationState( str(self) + "_orb") period = self.day node = self.sceneNode2 #print self.sceneNode2.getScale() #self.sceneNode2.setInheritScale(False) self.animation_spin = sceneManager.createAnimation( str(self) + "_spin", period) animationTrack = self.animation_spin.createNodeTrack(1, node) for i in range(pointNum): key = animationTrack.createNodeKeyFrame(i * period / pointNum) key.setRotation( ogre.Quaternion(ogre.Radian(i * 6.28 / pointNum), ogre.Vector3(0, 1, 0))) key.setScale(ogre.Vector3(self.scale, self.scale, self.scale)) key = animationTrack.createNodeKeyFrame(period) key.setRotation(ogre.Quaternion(ogre.Radian(0), ogre.Vector3(0, 1, 0))) key.setScale(ogre.Vector3(self.scale, self.scale, self.scale)) self.spinAnimState = sceneManager.createAnimationState( str(self) + "_spin")
def setWorldTransform(self, WorldTrans): x = WorldTrans.getOrigin().x() y = WorldTrans.getOrigin().y() z = WorldTrans.getOrigin().z() p = ogre.Vector3(x, y, z) q = ogre.Quaternion(WorldTrans.getRotation().w(), WorldTrans.getRotation().x(), WorldTrans.getRotation().y(), WorldTrans.getRotation().z()) self.mParentNode.setOrientation(q) self.mParentNode.setPosition(x, y, z)
def init(self, size, tex): #create a new pass in the material to render the decal self.m_pass = self.m_terrainMat.getTechnique(0).getPass("Decal") if not self.m_pass: techPref = self.m_terrainMat.getTechnique(0) self.m_pass = techPref.createPass() self.m_pass.setName("Decal") self.m_pass.setLightingEnabled(False) self.m_pass.setSceneBlending(og.SBT_TRANSPARENT_ALPHA) self.m_pass.setDepthBias(2.5, 2.5) self.m_pass.setFog(True) self.m_pass.createTextureUnitState("decalBase.png") #init projective decal #set up the main decal projection frustum self.m_frustProj = og.Frustum() self.m_nodeProj = self.m_sceneMgr.getRootSceneNode( ).createChildSceneNode() self.m_nodeProj.attachObject(self.m_frustProj) self.m_frustProj.setProjectionType(og.PT_ORTHOGRAPHIC) self.m_nodeProj.setOrientation( og.Quaternion(og.Degree(90), og.Vector3().UNIT_X)) # /* Commented out for general use. If you are using mouse picking in your scene, set this to an unselectable flag otherwise you may find the frustum in your ray queries. */ # //m_frustProj.setQueryFlags(Sanguis.UNSELECTABLE) # // set given values self.setSize(size) self.m_sTexName = tex # texture to apply # load the images for the decal and the filter og.TextureManager.getSingleton().load( self.m_sTexName, og.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, og.TEX_TYPE_2D, 1) self.m_bVisible = False
def _updateView(self): """Update object view Updating object materials based on state. """ objects.ObjectDepth._updateView(self) if self.needStateUpdate: # need to recreate materials self.destroyMaterials() self.createMaterials() #if render_engine.viewMode is render_engine.Mode_Isometric: if self.__manualObject is not None: self.needStateUpdate = False self.__materialName = self._getMaterialName2d() self.__materialNameArr = self._getMaterialNameArr() if self.__manualObject.getNumSections() > 0: self.__manualObject.setMaterialName(0, self.__materialName) if self.__manualObjectB is not None: self.__manualObjectB.setMaterialName( 0, self.__materialNameArr) if self.__manualObjectE is not None: self.__manualObjectE.setMaterialName( 0, self.__materialNameArr) else: self.needUpdate = True self.needViewUpdate = True #else: # self.needStateUpdate = False # self.__entity3d.setMaterialName(self._getMaterialName3d()) self._recalculateMaterial() # mode updating if self.needModeUpdate: if render_engine.viewMode is render_engine.Mode_Perspective: self.sceneNode.removeChild(self.__sceneNode2d) # self.sceneNode.addChild(self.__sceneNode3d) self.sceneNode.addChild(self.__sceneNode2d) else: # self.sceneNode.removeChild(self.__sceneNode3d) self.sceneNode.removeChild(self.__sceneNode2d) self.sceneNode.addChild(self.__sceneNode2d) self.needModeUpdate = False if render_engine.viewMode is render_engine.Mode_Perspective and self.__orientV is not None: p1 = self.sceneNode.getPosition() # + self.__orientV / 2.0 lookVec = p1 - render_engine._ogreCameraNode.getPosition() #upVec = render_engine._ogreCamera.getUp() orient = self.__orientV orient.normalise() rightVec = orient.crossProduct(lookVec) rightVec.normalise() lookVec = rightVec.crossProduct(orient) lookVec.normalise() matr = ogre.Matrix3() matr.FromAxes(rightVec, orient, lookVec) orientation = ogre.Quaternion() orientation.FromRotationMatrix(matr) orientation.normalise() #print orientation #self.sceneNode.setDirection(orient, ogre.SceneNode.TS_PARENT, [0, 1, 0]) self.sceneNode.setOrientation(orientation) # do not update position self.needPositionUpdate = False
def parseZonesFromXml(self, zoneXmlNode, map): if zoneXmlNode is None: return self.currentMap = map zoneNodes = zoneXmlNode.getiterator("zone") for zone in zoneNodes: zoneName = zone.attrib["name"] z = self.createZone(zoneName) areaNodes = zone.getiterator("area") for area in areaNodes: type = area.attrib["type"] meshFile = None if type == "mesh": meshFile = area.attrib["meshfile"] pos = og.Vector3() qw = qx = qy = qz = 0 scale = None hasRotation = False transformations = area.getiterator() for t in transformations: if t.tag == "position": posx = float(t.attrib["x"]) posy = float(t.attrib["y"]) posz = float(t.attrib["z"]) pos = og.Vector3(posx, posy, posz) elif t.tag == "rotation": qw = float(t.attrib["qw"]) qx = float(t.attrib["qx"]) qy = float(t.attrib["qy"]) qz = float(t.attrib["qz"]) hasRotation = True elif type == "mesh" and t.tag == "scale": scalex = float(t.attrib["x"]) scaley = float(t.attrib["y"]) scalez = float(t.attrib["z"]) scale = og.Vector3(scalex, scaley, scalez) elif t.tag == "size": scalex = float(t.attrib["x"]) scaley = float(t.attrib["y"]) scalez = float(t.attrib["z"]) scale = og.Vector3(scalex, scaley, scalez) rot = None if hasRotation: rot = og.Quaternion(qw, qx, qy, qz) z.addArea(type, pos, rot, scale, meshFile) lightNodes = zone.getiterator("light") for light in lightNodes: name = light.attrib["name"] z.lightList.append(name) triggerNodes = zone.getiterator("trigger") for trigger in triggerNodes: name = trigger.attrib["name"] classname = trigger.attrib["classname"] properties = trigger.getiterator("property") trigger = TriggerManager.instance.createTrigger( name, classname, properties) z.addTrigger(trigger) soundNodes = zone.getiterator("sound") for sound in soundNodes: name = sound.attrib["name"] z.soundList.append(name)
import sys as __sys # Attempt to import Ogre, if it fails try with PYTHON_OGRE_HOME on sys.path try: import ogre.renderer.OGRE as ogre except ImportError: # Check for PYTHON_OGRE_HOME in the environment if __os.environ.has_key('PYTHON_OGRE_HOME'): pythonOgreHome = __os.environ['PYTHON_OGRE_HOME'] # Only insert path if its not already on the path __path = __os.path.join(pythonOgreHome, 'packages_2.5') if __sys.path.count(__path) == 0: __sys.path.insert(0, __path) import ogre.renderer.OGRE as __OGRE __OGRE.Vector3.ZERO = __OGRE.Vector3().ZERO __OGRE.Vector3.UNIT_X = __OGRE.Vector3().UNIT_X __OGRE.Vector3.UNIT_Y = __OGRE.Vector3().UNIT_Y __OGRE.Vector3.UNIT_Z = __OGRE.Vector3().UNIT_Z __OGRE.Quaternion.IDENTITY = __OGRE.Quaternion().IDENTITY def OgreVector3(args): if type(args) is __OGRE.Vector3: return __OGRE.Vector3(args.x, args.y, args.z) else: assert len(args) == 3 return __OGRE.Vector3(*[float(x) for x in args])
def test_orientation(self): self.assertEqual(Ogre.Quaternion(1, 0, 0, 0), self.body.orientation)