コード例 #1
0
 def createGhostObjectEntity(self, sceneNode, radius):
     
     pos = sceneNode.getPosition()
     transform = bullet.btTransform()
     transform.setIdentity()
     transform.setOrigin(bullet.btVector3(pos.x, pos.y, pos.z))
     
     ghostObject = bullet.btPairCachingGhostObject()
     
     ghostObject.setWorldTransform(transform)
     
     sphereShape = bullet.btSphereShape(1.0)
     
     ghostObject.setCollisionShape(sphereShape)
     #ghostObject.setCollisionFlags(bullet.btCollisionObject.CO_GHOST_OBJECT)
     
     
     
     actionEntity = ActionEntity(self.world, ghostObject, sceneNode)
     
     self.world.addCollisionObject(ghostObject, bullet.btBroadphaseProxy.SensorTrigger, bullet.btBroadphaseProxy.AllFilter)
     #self.world.getBroadphase().getOverlappingPairCache().setInternalGhostPairCallback(bullet.btGhostPairCallback())
     #self.world.addAction(actionEntity)
     
     self.shapes.append(sphereShape)
     
     return actionEntity       
コード例 #2
0
 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
コード例 #3
0
ファイル: camera.py プロジェクト: simeks/D0016E-VIS
    def update(self, pos, orientation, acceleration, velocity):
        if(self.rigidBody != None):
            #self.rigidBody.applyForce(physics.toBtVector3(acceleration), physics.toBtVector3(pos));
            self.rigidBody.proceedToTransform(bullet.btTransform(physics.toBtQuaternion(ogre.Quaternion(0, (0, 1, 0))), physics.toBtVector3(pos)));
            self.rigidBody.setAngularVelocity(bullet.btVector3(0,0,0));
            self.rigidBody.setLinearVelocity(bullet.btVector3(0,0,0));

            
        self.orientation = orientation;
        acceleration = orientation * acceleration;
        self.velocity = orientation*velocity;

        orientationx = ogre.Quaternion((5.0*(acceleration.z))*(math.pi/180.0), (1,0,0));
        orientationz = ogre.Quaternion((5.0*(acceleration.x))*(math.pi/180.0), (0,0,1));

        orientation = orientation * orientationx * orientationz;
        self.mainCamera.setOrientation(orientation);

        self.mainCamera.setPosition(pos);


        if self.multipleCameras:
            sqrPt5 = math.sqrt(0.5);
            
            leftOrientation = orientation * ogre.Quaternion(self.cameraAngle * (math.pi/180.0), (0,1,0));
            self.leftCamera.setOrientation(leftOrientation);
            self.leftCamera.setPosition(pos);
                    
            rightOrientation = orientation * ogre.Quaternion(-self.cameraAngle * (math.pi/180.0), (0,1,0));
            self.rightCamera.setOrientation(rightOrientation);
            self.rightCamera.setPosition(pos);
コード例 #4
0
ファイル: base.py プロジェクト: magcius/supyrdupyr
    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
コード例 #5
0
ファイル: test04.py プロジェクト: holocronweaver/python-ogre
 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)   
コード例 #6
0
ファイル: chunk.py プロジェクト: kyphelps/pynecraft
 def add_block_without_rebuild(self, block, x, y, z):
     transform = bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), bullet.btVector3(x * Block.size,
                                                                                      y * Block.size,
                                                                                      z * Block.size))
     self.collision_shape.addChildShape(transform, BOX_COLLISION_SHAPE)
     self.collision_shape_indicies[(x, y, z)] = self.block_count
     self._blocks[(x, y, z)] = block
     self.block_count += 1
コード例 #7
0
ファイル: physics_system.py プロジェクト: kyphelps/pynecraft
 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
コード例 #8
0
 def fireCube(self, pos, force):
     cube = self.cubes[(self.curCubeIdx) % len(self.cubes)]
     self.curCubeIdx += 1
     transform = bullet.btTransform()
     transform.setOrigin(bullet.btVector3(pos.x, pos.y, pos.z))
     cube.clearForces()
     cube.setLinearVelocity(bullet.btVector3(0.0, 0.0, 0.0))
     cube.setWorldTransform(transform)
     impulse = bullet.btVector3(force.x, force.y, force.z)
     cube.applyImpulse(impulse, bullet.btVector3(0.0, 0.0, 0.0))
コード例 #9
0
ファイル: physics_system.py プロジェクト: kyphelps/pynecraft
 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
コード例 #10
0
 def __init__(self, dynamicsWorld):
     """Base Collision Object for Testing"""
     self.mShape = None
     self.dynamicsWorld = dynamicsWorld
     self.mRigidBody = None
     self.mTransform = bullet.btTransform()
     self.mTransform.setIdentity()
     self.mInertia = bullet.btVector3(0, 0, 0)
     self.mMotionState = None
     self.mMass = 0.0
     self.mTriMesh = None
コード例 #11
0
ファイル: physics.py プロジェクト: simeks/D0016E-VIS
    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);
コード例 #12
0
 def __init__(self, dynamicsWorld):
     """Base Collision Object for Testing"""
     self.mShape = None
     self.dynamicsWorld = dynamicsWorld
     self.mRigidBody = None
     self.mTransform = bullet.btTransform()
     self.mTransform.setIdentity()
     self.mInertia = bullet.btVector3(0, 0, 0)
     self.mMotionState = None
     self.mMass = 0.0
     self.mTriMesh = None
コード例 #13
0
ファイル: physics_system.py プロジェクト: kyphelps/pynecraft
 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
コード例 #14
0
ファイル: physics.py プロジェクト: simeks/D0016E-VIS
    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;
コード例 #15
0
ファイル: body.py プロジェクト: KACAH/PhyCharacter
    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)
コード例 #16
0
 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
コード例 #17
0
 def updateAction(self, deltaTime):
     transform = bullet.btTransform()
     pos = self.sceneNode.getPosition()
     
     transform.setOrigin(bullet.btVector3(pos.x, pos.y, pos.z))
     
     self.ghostObject.setWorldTransform(transform)
     
     
     manifoldArray = bullet.btManifoldArray()
     pairArray = self.ghostObject.getOverlappingPairCache().getOverlappingPairArray()
     collision = False
     for i in range(pairArray.size()):
         manifoldArray.clear()
         pair = pairArray[i] 
         collisionPair = self.world.getPairCache().findPair(pair.m_pProxy0, pair.m_pProxy1)
         if collisionPair is None:
             continue
         proxyObject = collisionPair.m_pProxy1.m_clientObject
         if proxyObject == self.target:
             continue
         if (collisionPair.m_algorithm):
             collisionPair.m_algorithm.getAllContactManifolds(manifoldArray)
         
         for j in manifoldArray:
             directionSign = None
             if j.getBody0() == self.ghostObject:
                 directionSign = -1.0
             else:
                 directionSign = 1.0
             for k in range(j.getNumContacts()):
                 pt = j.getContactPoint(k)
                 if pt.getDistance() < 0.0:
                     collision = True
                     
     if collision:
         self.entity.onCollision()
コード例 #18
0
ファイル: test01.py プロジェクト: holocronweaver/python-ogre
        self.Position = ogre.Vector3(WorldTrans.getOrigin().x(), WorldTrans.getOrigin().y(), WorldTrans.getOrigin().z())
        self.Quaternion = ogre.Quaternion(
            WorldTrans.getRotation().w(),
            WorldTrans.getRotation().x(),
            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
コード例 #19
0
ファイル: body.py プロジェクト: KACAH/PhyCharacter
 def setOrientation(self, rot):
     _tr = bullet.btTransform()
     self.body.getMotionState().getWorldTransform(_tr)
     _tr.setRotation(bullet.btQuaternion(rot.x, rot.y, rot.z, rot.w))
     self.body.getMotionState().setWorldTransform(_tr)
コード例 #20
0
ファイル: body.py プロジェクト: KACAH/PhyCharacter
 def setPosition(self, pos):
     _tr = bullet.btTransform()
     self.body.getMotionState().getWorldTransform(_tr)
     _tr.setOrigin(bullet.btVector3(pos.x, pos.y, pos.z))
     self.body.getMotionState().setWorldTransform(_tr)
コード例 #21
0
ファイル: body.py プロジェクト: KACAH/PhyCharacter
 def _create_simple_tr():
     _tr = bullet.btTransform()
     _tr.setIdentity()
     _tr.setOrigin(bullet.btVector3(0, 0, 0))
     _tr.setRotation(bullet.btQuaternion(0, 0, 0, 1))
     return _tr
コード例 #22
0
ファイル: vector.py プロジェクト: kyphelps/pynecraft
def transform_zero():
    return bullet.btTransform(bullet.btQuaternion(0, 0, 0, 0),
                              bullet.btVector3(0, 0, 0))
コード例 #23
0
ファイル: vector.py プロジェクト: kyphelps/pynecraft
def transform_from_ogre(v, q):
    return bullet.btTransform(ogre2bullet_quaternion(q), ogre2bullet_vector(v))
コード例 #24
0
ファイル: test03.py プロジェクト: holocronweaver/python-ogre
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