All pastes #921098 Raw Edit

Something

public python v1 · immutable
#921098 ·published 2008-02-27 20:37 UTC
rendered paste body
#Test ODE with OGRE integrationimport syssys.path.insert(0,'..')import PythonOgreConfigimport math as mathimport ode as odeimport ogre.renderer.OGRE as ogreimport SampleFramework as sf#CALLBACKSdef collisionCallback(args, geom1, geom2):    # Check if the objects do collide    world,contactgroup = args    contacts = ode.collide(geom1, geom2)        # Create contact joints        for c in contacts:        c.setBounce(0.1)        c.setMu(5000)        j = ode.ContactJoint(world, contactgroup, c)        j.attach(geom1.getBody(), geom2.getBody())    #MAIN APP CLASSclass TestApplication(sf.Application):    def _createScene(self):                self.pWorld = ode.World()        self.pWorld.setGravity((0.0,-10.0,0.0))        self.pWorld.setAutoDisableTime(1)               self.pWorld.setERP(0.8)        self.pWorld.setCFM(1E-5)                             self.pSpace = ode.SimpleSpace()        self.pFloor = ode.GeomPlane(self.pSpace, (0.0,1.0,0.0),0)         self.pContactGroup = ode.JointGroup()                        self.sceneManager.setAmbientLight(ogre.ColourValue(0.1,0.1,0.1))          self.sceneManager.setShadowTechnique(ogre.SHADOWTYPE_STENCIL_ADDITIVE)                #camera        self.camera.setPosition((0,150,0))                #lights        light = self.sceneManager.createLight('mainlight')        self.sceneManager.rootSceneNode.createChildSceneNode((10,150,10)).attachObject(light)                #meshes        ogrehead = self.sceneManager.createEntity('ogrehead', 'ogrehead.mesh')        self.ogrehead = ogrehead        ogrehead.setCastShadows(1)        self.ogrenode = self.sceneManager.rootSceneNode.createChildSceneNode((0,500,0))        self.ogrenode.attachObject(ogrehead)        box = ogrehead.getBoundingBox()        sizex = math.fabs(box.getMaximum().x - box.getMinimum().x)        sizey = math.fabs(box.getMaximum().y - box.getMinimum().y)        sizez = math.fabs(box.getMaximum().z - box.getMinimum().z)        ogrehead.pBody = ode.Body(self.pWorld)                M = ode.Mass()        M.setBox(300,sizex,sizey,sizez)        ogrehead.pBody.setMass(M)        ogrehead.pBody.setPosition((0.0,500.0,0.0))        ogrehead.pGeom = ode.GeomBox(self.pSpace, (sizex, sizey, sizez))                ogrehead.pGeom.setBody(ogrehead.pBody)                #sky + floor                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))        self.ground = self.sceneManager.createEntity('groundEntity', 'Ground')        self.ground.setCastShadows(0)        self.ground.setMaterialName("Examples/Rockwall")        self.groundnode = self.sceneManager.rootSceneNode.createChildSceneNode()        self.groundnode.attachObject(self.ground)                        self.sceneManager.setSkyDome(1, "Examples/CloudySky", 40, 4)            def _createFrameListener(self):        self.frameListener = TestFrameListener(self)        self.root.addFrameListener(self.frameListener)    #FRAME RENDER LISTENER (GAME LOOP)    class TestFrameListener(sf.FrameListener):    def __init__(self, applicationObj):        sf.FrameListener.__init__(self, applicationObj.renderWindow, applicationObj.camera)        self.application = applicationObj                def frameStarted(self, frameEvent):        #do physics        self.application.pSpace.collide((self.application.pWorld, self.application.pContactGroup),collisionCallback)        self.application.pWorld.step(0.1)                self.application.pContactGroup.empty()                #update node position                self.application.ogrenode.setPosition( self.application.ogrehead.pBody.getPosition() )        self.application.ogrenode.setOrientation( self.application.ogrehead.pBody.getQuaternion() )                print self.application.ogrenode.getPosition()         return sf.FrameListener.frameStarted(self, frameEvent)        #start the game    if __name__ == '__main__':    try:        application = TestApplication()        application.go()    except ogre.OgreException, e:        print e