コード例 #1
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
コード例 #2
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)   
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
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
コード例 #7
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);
コード例 #8
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
コード例 #9
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;
コード例 #10
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)
コード例 #11
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
コード例 #12
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
コード例 #13
0
ファイル: vector.py プロジェクト: kyphelps/pynecraft
def transform_zero():
    return bullet.btTransform(bullet.btQuaternion(0, 0, 0, 0),
                              bullet.btVector3(0, 0, 0))
コード例 #14
0
ファイル: vector.py プロジェクト: kyphelps/pynecraft
def ogre2bullet_quaternion(q):
    return bullet.btQuaternion(q.w, q.x, q.y, q.z)
コード例 #15
0
ファイル: util.py プロジェクト: magcius/supyrdupyr
def multiplyQuat(quat, scalar):
    from ogre.physics import bullet as bt
    return bt.btQuaternion(quat.x() * scalar, quat.y() * scalar, quat.z() * scalar, quat.w() * scalar)
コード例 #16
0
 def rotate(self, x, y, z):
     """Rotate the entity"""
     xform = self.entity.rigid_body.getWorldTransform()
     new_rotation = xform.getRotation() * bullet.btQuaternion(x, y, z)
     xform.setRotation(new_rotation)
     self.entity.rigid_body.setWorldTransform(xform)
コード例 #17
0
ファイル: physics.py プロジェクト: simeks/D0016E-VIS
def toBtQuaternion(ogreRot):
    return bullet.btQuaternion(ogreRot.x, ogreRot.y, ogreRot.z, ogreRot.w);
コード例 #18
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)
コード例 #19
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