def _addCube(self, pos, cubeBounds=ogre.Vector3(0.3, 0.3, 0.3), tangentBundle=None):
     #cubeBounds=bullet.btVector3(0.3, 0.3, 0.3)):
     ent = self.sceneManager.createEntity("Bulletbox.mesh")
     ent.setMaterialName("GridNormalMap3")
     node = self.sceneManager.getRootSceneNode().createChildSceneNode()
     node.attachObject(ent)
     node.scale(cubeBounds)
     #node.scale(cubeBounds.getX(), cubeBounds.getY(), cubeBounds.getZ())
     mass = 1.0
     res = 0.01
     bodyFriction = 0.2
     fallInertia = bullet.btVector3(0, 0, 0)
     cubeIdx = len(self.bodies)
     
     cubeShape = bullet.btBoxShape(collisions.OgreBtConverter.to(cubeBounds))
     cubeShape.calculateLocalInertia(mass, fallInertia)
     cubeMotionState = OgreMotionState(bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), bullet.btVector3(pos.x, pos.y, pos.z)), node, tb=tangentBundle)
     cubeBodyCI = bullet.btRigidBody.btRigidBodyConstructionInfo(mass, cubeMotionState, cubeShape, fallInertia)
     cubeBody = bullet.btRigidBody(cubeBodyCI)
     cubeBody.setActivationState(4) #state is never deactivate
     cubeMotionState.rb = cubeBody
     self.world.addRigidBody(cubeBody)
     
     self.motionStates.append(cubeMotionState)
     
     """
     cubeShape = collisions.BoxCollisionShape(cubeBounds)
     cubeBody = dynamics.RigidBody("cube" + str(cubeIdx), self.world)
     cubeBody.setShape(node, cubeShape, res, bodyFriction, mass, pos)
     cubeBody.getBulletRigidBody().setActivationState(4)
     """
     self.bodies.append(cubeBody)
     self.shapes.append(cubeShape)
     return cubeBody
Exemple #2
0
    def createBody(self, mass, position):
        
        position = bullet.btVector3(*position)
        transform = bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), position)
        
        if self.hasGhostObject:
            body = bullet.btPairCachingGhostObject()
            body.setCollisionShape(self.physShape)
            body.setWorldTransform(transform)
            self.world.physWorld.addCollisionObject(body, getTagBits(self.tags), getTagBits(self.collisionTags))
        else:
            self.motionState = self.MotionState(self, transform)
            self.physMass = mass

            localInertia = bullet.btVector3(0, 0, 0)
            self.physShape.calculateLocalInertia(mass, localInertia)
        
            construct = bullet.btRigidBody.btRigidBodyConstructionInfo(mass, self.motionState, self.physShape, localInertia)
            body = bullet.btRigidBody(construct)
            
            self.world.physWorld.addRigidBody(body, getTagBits(self.tags), getTagBits(self.collisionTags))
        
        body.setCollisionFlags(body.getCollisionFlags() | self.physFlags)
        body.setUserData(self)
        self.physBody = body
Exemple #3
0
 def createBoxes( self ):
     print 2
     ent = self.sceneManager.createEntity( "box", "cube.mesh" )
     print 2
     node = self.sceneManager.getRootSceneNode().createChildSceneNode()
     print 2
     node.attachObject( ent )
     print 2
     ent.setMaterialName( "Examples/RustySteel")
     print 2
     
     mass = 10
     fallInertia = bullet.btVector3(0, 0, 0)
     print 2
     shape=bullet.btSphereShape(1)
     print 2
     shape.calculateLocalInertia(mass, fallInertia)
     print "Creating motionState"
     motionState=OgreMotionState(bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), bullet.btVector3(0, 50, 0)))
     print "creating construct"
     construct = bullet.btRigidBody.btRigidBodyConstructionInfo(mass, motionState, shape, fallInertia)
     print "creating object"
     Object=bullet.btRigidBody(construct) # ...this should work in my eyes 
     print "adding rigidBody"
     self.world.addRigidBody(Object)
     print "completed" 
     self.world.stepSimulation(1)   
Exemple #4
0
 def register_collision_object(self, size, x, y, z, rotation=bullet.btQuaternion(0, 0, 0, 1), mass=0, motion_state=bullet.btDefaultMotionState):
     """Register a simple collision object with bullet."""
     shape = bullet.btBoxShape(bullet.btVector3(size / 2, size / 2, size / 2))
     transform = bullet.btTransform(rotation, bullet.btVector3(x, y, z))
     inertia = bullet.btVector3(0, 0, 0)
     motion_state = motion_state(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
Exemple #5
0
 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
Exemple #6
0
    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);
Exemple #7
0
    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 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)
Exemple #9
0
    def createCylinder(self, sceneNode, width, height, depth, mass):
        pos = sceneNode.getPosition();
        rot = sceneNode.getOrientation();
        
        # Skapa motion state
        motionState = NodeMotionState(sceneNode);

        shape = bullet.btCylinderShape(bullet.btVector3(width/2.0, height/2.0, depth/2.0));
        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);
Exemple #10
0
 def register_entity(self, entity, mass, motion_state):
     """Register an entity that is moved by the engine. This allows the
     physics system to work together with the engine in order to know
     about the movement the engine produces, but also the movement that is
     caused through the physics simulations"""
     #logging.info("Registering %s with the physics system. kinematic=%s" % (str(entity), str(kinematic)))
     entity.shape = self._create_collision_entity(entity)
     transform = bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1),
                                    bullet.btVector3(entity.position.x,
                                                     entity.position.y,
                                                     entity.position.z))
     inertia = bullet.btVector3(0, 0, 0)
     entity.motion_state = motion_state(transform)
     construction = bullet.btRigidBody.btRigidBodyConstructionInfo(mass, entity.motion_state, entity.shape, inertia)
     entity.rigid_body = bullet.btRigidBody(construction)
     self.dynamics_world.addRigidBody(entity.rigid_body, 1, 1)
     return entity.rigid_body
Exemple #11
0
    def createSphere(self, sceneNode, radius, mass):
        pos = sceneNode.getPosition();
        rot = sceneNode.getOrientation();
        
        # Skapa motion state
        motionState = NodeMotionState(sceneNode);


        sphereShape = bullet.btSphereShape(radius);
        inertia = bullet.btVector3(0,0,0);
        sphereShape.calculateLocalInertia(mass, inertia);
        
        constructInfo = bullet.btRigidBody.btRigidBodyConstructionInfo(
            mass, motionState, sphereShape, inertia);
        rigidBody = bullet.btRigidBody(constructInfo);

        self.bodies.append(PhysicsWorld.Body(sphereShape, motionState, constructInfo, rigidBody));
        self.world.addRigidBody(rigidBody);
Exemple #12
0
    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;
Exemple #13
0
    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)
 def createSphere(self, pos, radius, node):
     
     mass = 1.0
     res = 0.1
     bodyFriction = 0.8
     fallInertia = bullet.btVector3(0, 0, 0)
     sphereId = len(self.bodies)
     
     sphereShape = bullet.btSphereShape(radius)
     sphereShape.calculateLocalInertia(mass, fallInertia)
     sphereMotionState = OgreMotionState(bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), bullet.btVector3(pos.x, pos.y, pos.z)), node)
     sphereBodyCI = bullet.btRigidBody.btRigidBodyConstructionInfo(mass, sphereMotionState, sphereShape, fallInertia)
     sphereBody = bullet.btRigidBody(sphereBodyCI)
     sphereBody.setActivationState(4)
     sphereBody.setCollisionFlags(bullet.btCollisionObject.CF_KINEMATIC_OBJECT)
     self.world.addRigidBody(sphereBody)
     
     self.motionStates.append(sphereMotionState)
     
     self.bodies.append(sphereBody)
     self.shapes.append(sphereShape)
     
     return None
Exemple #15
0
            WorldTrans.getRotation().y(),
            WorldTrans.getRotation().z(),
        )
        # print "setWorldTrans", WorldTrans


mass = 10
fallInertia = bullet.btVector3(0, 0, 0)
shape = bullet.btSphereShape(1)
shape.calculateLocalInertia(mass, fallInertia)
print "Creating motionState"
motionState = OgreMotionState(bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), bullet.btVector3(0, 50, 0)))
print "1"
construct = bullet.btRigidBody.btRigidBodyConstructionInfo(mass, motionState, shape, fallInertia)
print "1"
Object = bullet.btRigidBody(construct)  # ...this should work in my eyes
print dir(Object)
print "1"
world.addRigidBody(Object)
print "1"

for x in range(90):
    world.stepSimulation(x * 1 / 30)

    print "OBJECT:",
    print Object.getAabb(bullet.btVector3(0, 0, 0), bullet.btVector3(10, 10, 10))
    print Object.getMotionState
    pos = Object.getMotionState().Position
    print x, "height: " + str(pos.y)

v = bullet.btVector3(1.0, 2.0, 3)
Exemple #16
0
import ogre.renderer.OGRE as ogre
from ogre.physics import bullet

# Set up bullet
collisionConfiguration = bullet.get_btDefaultCollisionConfiguration()
dispatcher = bullet.get_btCollisionDispatcher1(collisionConfiguration)
broadphase = bullet.btDbvtBroadphase()
solver = bullet.btSequentialImpulseConstraintSolver()

world = bullet.btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration)
world.setGravity(bullet.btVector3(0, -10, 0))
world.getDispatchInfo().m_enableSPU = True
store = []
for i in range(200):
    print(i)
    mass = 10
    shape = bullet.btBoxShape(bullet.btVector3(10, 10, 10))
    mots = bullet.btDefaultMotionState()
    o = bullet.btRigidBody(mass, mots, shape)
    world.addRigidBody(o)
    store.append(shape)
    store.append(o)
    store.append(mots)

for i in range(90):
    world.stepSimulation(0.0001)

# note we need to delete the world before the Object as there are issues with the destructor on Objects causing
# virtual functions being called errors
del world
Exemple #17
0
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