def create_compound_shape(self, x, y, z, mass=0): """Create a compound shape and register it with bullet.""" shape = bullet.btCompoundShape() transform = bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), bullet.btVector3(x, y, z)) inertia = bullet.btVector3(0, 0, 0) motion_state = bullet.btDefaultMotionState(transform) construction = bullet.btRigidBody.btRigidBodyConstructionInfo(mass, motion_state, shape, inertia) rigid_body = bullet.btRigidBody(construction) self.dynamics_world.addRigidBody(rigid_body, 1, 1) return rigid_body, motion_state, shape
def setMotion(self, mParentNode): if not self.isDynamic(): self.mMotionState = bullet.btDefaultMotionState(self.mTransform) else: self.mMotionState = OgreMotionState(self.mTransform, mParentNode) rigidbody_info = bullet.btRigidBody.btRigidBodyConstructionInfo( self.mMass, self.mMotionState, self.mShape, self.mInertia) self.mRigidBody = bullet.btRigidBody(rigidbody_info) self.dynamicsWorld.addRigidBody(self.mRigidBody) self.mRigidBody.setUserData(mParentNode)
def createGround(self, sceneNode): groundShape = bullet.btStaticPlaneShape(bullet.btVector3(0,1,0),0); # Skapa motion state motionState = bullet.btDefaultMotionState(bullet.btTransform( bullet.btQuaternion(0,0,0,1), bullet.btVector3(0,-1,0))); constructInfo = bullet.btRigidBody.btRigidBodyConstructionInfo( 0, motionState, groundShape, bullet.btVector3(0,0,0)); rigidBody = bullet.btRigidBody(constructInfo); self.bodies.append(PhysicsWorld.Body(groundShape, motionState, constructInfo, rigidBody)); self.world.addRigidBody(rigidBody);
def createCameraBody(self, camera, halfSize, mass): pos = camera.getPosition(); rot = camera.getOrientation(); # Skapa motion state motionState = bullet.btDefaultMotionState(bullet.btTransform( bullet.btQuaternion(0,0,0,1), bullet.btVector3(pos.x,pos.y,pos.z))); shape = bullet.btBoxShape(toBtVector3(halfSize)); inertia = bullet.btVector3(0,0,0); shape.calculateLocalInertia(mass, inertia); constructInfo = bullet.btRigidBody.btRigidBodyConstructionInfo( mass, motionState, shape, inertia); rigidBody = bullet.btRigidBody(constructInfo); self.bodies.append(PhysicsWorld.Body(shape, motionState, constructInfo, rigidBody)); self.world.addRigidBody(rigidBody); return rigidBody;
def __init__(self, app, pos, rot): self.app = app self.shape = bullet.btEmptyShape() _tr = bullet.btTransform() _tr.setIdentity() _tr.setOrigin(bullet.btVector3(pos.x, pos.y, pos.z)) _tr.setRotation(bullet.btQuaternion(rot.x, rot.y, rot.z, rot.w)) _local_inertia = bullet.btVector3(0,0,0) self.shape.calculateLocalInertia(self.MASS, _local_inertia) self.motion_state = bullet.btDefaultMotionState(_tr) self.rb_info = bullet.btRigidBody.btRigidBodyConstructionInfo( self.MASS, self.motion_state, self.shape, _local_inertia) self.body = bullet.btRigidBody(self.rb_info) self.body.setCollisionFlags(self.body.getCollisionFlags() \ | bullet.btCollisionObject.CF_KINEMATIC_OBJECT) self.app.world.getBulletDynamicsWorld().addRigidBody(self.body)
import sys sys.path.insert(0,'..') import PythonOgreConfig import ogre.renderer.OGRE as ogre import ogre.physics.bullet as bullet t = bullet.btTransform() ms = bullet.btDefaultMotionState (t) s = bullet.btBoxShape(bullet.btVector3(10,10,10)) body = bullet.btRigidBody(1, ms, s) print body collisionConfiguration = bullet.btDefaultCollisionConfiguration() dispatcher = bullet.btCollisionDispatcher (collisionConfiguration) worldAabbMin = bullet.btVector3(-1000,-1000,-1000) worldAabbMax = bullet.btVector3(1000,1000,1000) maxProxies = 32766 broadphase = bullet.btAxisSweep3(worldAabbMin, worldAabbMax, maxProxies) solver = bullet.btSequentialImpulseConstraintSolver() world = bullet.btDiscreteDynamicsWorld(dispatcher, broadphase , solver, collisionConfiguration) world.getDispatchInfo().m_enableSPU = True world.setGravity(bullet.btVector3(0,-10,0)) print world print dir(world) print solver