def SetupODE(self): # Create a world object self.world = ode.dWorld() self.world.setGravity(0, -9.81, 0) self.world.setERP(0.8) self.world.setCFM(1e-5) # Create a space object self.space = ode.CreateSimpleSpace() # Create a plane geom which prevent the objects from falling forever self.floor = ode.dPlane(space.id(), 0.0, 1.0, 0.0, 0.0) # A list with ODE bodies self.odebodies = [] # A joint group for the contact joints that are generated whenever # two bodies collide self.contactgroup = ode.dJointGroup()
def create_box(world, space, density, lx, ly, lz): """Create a box body and its corresponding geom.""" # Create body body = ode.dBody(world.id()) M = ode.dMass() M.setBox(density, lx, ly, lz) body.setMass(M) # Set parameters for drawing the body body.shape = "box" body.boxsize = (lx, ly, lz) # Create a box geom for collision detection geom = ode.dCreateBox(space.id(), lx,ly,lz ) ode.dGeomSetBody ( geom, body.id() ) return body
def ODE_callback(self, args, geom1, geom2): """Callback function for the collide() method. This function checks if the given geoms do collide and creates contact joints if they do. """ # Check if the objects do collide contacts = ode.dCollide(geom1, geom2) # Create contact joints world, contactgroup = args for c in contacts: c.setBounce(0.2) c.setMu(5000) j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())
contactCount = ode.dCollide(geom1, geom2) # Create contact joints world,contactgroup = args for c in contacts: c.setBounce(0.2) c.setMu(5000) j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody()) ###################################################################### # Create a world object world = ode.dWorld() world.setGravity( 0,-9.81,0 ) world.setERP(0.8) world.setCFM(1E-5) # Create a space object space = ode.CreateSimpleSpace() # Create a plane geom which prevent the objects from falling forever floor = ode.dPlane(space.id(), 0.0, 1.0, 0.0, 0.0) # A list with ODE bodies bodies = [] # A joint group for the contact joints that are generated whenever # two bodies collide
# pyODE example 1: Getting started import sys sys.path.insert(0,'..') import PythonOgreConfig import ogre.physics.ODE as ode # Create a world object world = ode.dWorld() world.setGravity( 0,-9.81,0 ) # Create a body inside the world body = ode.dBody(world.id() ) M = ode.dMass() M.setSphere(2500.0, 0.05) M.mass = 1.0 body.setMass(M) body.setPosition( 0,2,0 ) body.addForce( 0,200,0 ) # Do the simulation... total_time = 0.0 dt = 0.04 while total_time<2.0: x,y,z = body.getPosition() u,v,w = body.getLinearVel() print "%1.2fsec: pos=(%6.3f, %6.3f, %6.3f) vel=(%6.3f, %6.3f, %6.3f)" % \ (total_time, x, y, z, u,v,w) world.step(dt) total_time+=dt