Example #1
0
def create(ship_position=(0, 0, 0)):
    """Create a HexShip entity."""
    # Initialize OGRE graphical representation.
    ship_id = entitysystem.create_entity()
    logging.debug("HexShip id: " + str(ship_id) + "   pos: (" +
                    str(ship_position[0]) + ", " +
                    str(ship_position[1]) + ", " +
                    str(ship_position[2]) + ")"
                  )

    ogre_entity = application.ogre_scene_manager.createEntity(
                          'ogreEntity-' + str(ship_id), 'HexCell.mesh')
    ogre_node = application.ogre_root_node.createChildSceneNode(
                          'ogreNode-' + str(ship_id))
    ogre_node.attachObject(ogre_entity)
    ogre_entity.setCastShadows(True)
    ogre_node.setScale(ogre.Vector3(1.0, 1.0, 1.0))
    entitysystem.add_component( ship_id,
                                entitysystem.ComponentTypes.Graphics,
                                ogre_node)

    # Initialize physics.
    collision_object = OgreBulletUtils.CollisionObject(application.bullet_world)
    collision_object.setShape(OgreBulletUtils.MeshInfo.createCylinderShape(
                                            ogre_entity,
                                            OgreBulletUtils.BulletShapes.CYLINDERZ))
    collision_object.setTransform(bullet.btVector3( ship_position[0],
                                                    ship_position[1],
                                                    ship_position[2]))
    collision_object.setMass(1.0)
    collision_object.setInertia(bullet.btVector3(0.0, 0.0, 0.0))
    collision_object.setMotion(ogre_entity.getParentSceneNode())
    entitysystem.add_component( ship_id,
                                entitysystem.ComponentTypes.Physics,
                                collision_object)
Example #2
0
def create(ship_position=(0, 0, 0)):
    """Create a HexShip entity."""
    # Initialize OGRE graphical representation.
    ship_id = entitysystem.create_entity()
    logging.debug("HexShip id: " + str(ship_id) + "   pos: (" +
                  str(ship_position[0]) + ", " + str(ship_position[1]) + ", " +
                  str(ship_position[2]) + ")")

    ogre_entity = application.ogre_scene_manager.createEntity(
        'ogreEntity-' + str(ship_id), 'HexCell.mesh')
    ogre_node = application.ogre_root_node.createChildSceneNode('ogreNode-' +
                                                                str(ship_id))
    ogre_node.attachObject(ogre_entity)
    ogre_entity.setCastShadows(True)
    ogre_node.setScale(ogre.Vector3(1.0, 1.0, 1.0))
    entitysystem.add_component(ship_id, entitysystem.ComponentTypes.Graphics,
                               ogre_node)

    # Initialize physics.
    collision_object = OgreBulletUtils.CollisionObject(
        application.bullet_world)
    collision_object.setShape(
        OgreBulletUtils.MeshInfo.createCylinderShape(
            ogre_entity, OgreBulletUtils.BulletShapes.CYLINDERZ))
    collision_object.setTransform(
        bullet.btVector3(ship_position[0], ship_position[1], ship_position[2]))
    collision_object.setMass(1.0)
    collision_object.setInertia(bullet.btVector3(0.0, 0.0, 0.0))
    collision_object.setMotion(ogre_entity.getParentSceneNode())
    entitysystem.add_component(ship_id, entitysystem.ComponentTypes.Physics,
                               collision_object)
Example #3
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
Example #4
0
    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);
Example #5
0
    def __init__(self):
        sf.Application.__init__(self)
        patchDecl = ogre.VertexDeclaration()
        self.patchCtlPoints = 0
        # Create the global log manager instance
        self.logMgr = ogre.LogManager()
        # create the instance of our log listener
        self.myLog = MyLog()
        # create a "log"
        self.currentLog = ogre.LogManager.getSingletonPtr().createLog(
            "dummy.log",
            True,  # it's the default log
            False,  # I don't want it sent to the debug window
            True,  # it's a virtual log, so you need a listener :)
        )
        # register our listener
        self.currentLog.addListener(self.myLog)

        self.collisionConfiguration = bullet.btDefaultCollisionConfiguration()
        self.dispatcher = bullet.btCollisionDispatcher(self.collisionConfiguration)

        worldAabbMin = bullet.btVector3(-1000, -1000, -1000)
        worldAabbMax = bullet.btVector3(1000, 1000, 1000)
        maxProxies = 32766

        self.broadphase = bullet.btAxisSweep3(worldAabbMin, worldAabbMax, maxProxies)

        self.solver = bullet.btSequentialImpulseConstraintSolver()
        self.world = bullet.btDiscreteDynamicsWorld(
            self.dispatcher, self.broadphase, self.solver, self.collisionConfiguration
        )
        self.world.stepSimulation(0.1)
        self.world.stepSimulation(1)
        print "INIT OK"
Example #6
0
def initializePhysics():
    """Start the Bullet Physics engine."""
    global bullet_world
    global bullet_debug_drawer
    global bullet_collision_configuration
    global bullet_dispatcher
    global bullet_broadphase
    global bullet_solver

    bullet_collision_configuration = bullet.get_btDefaultCollisionConfiguration()
    bullet_dispatcher = bullet.get_btCollisionDispatcher1(bullet_collision_configuration)
    #bullet_broadphase = bullet.btDbvtBroadphase()
    bullet_broadphase = bullet.btAxisSweep3(
                                    bullet.btVector3(-10000, -10000, -10000),
                                    bullet.btVector3(10000, 10000, 10000),
                                    1024)
    bullet_solver = bullet.btSequentialImpulseConstraintSolver()

    bullet_world = bullet.btDiscreteDynamicsWorld(
                                    bullet_dispatcher,
                                    bullet_broadphase,
                                    bullet_solver,
                                    bullet_collision_configuration)
    bullet_world.setGravity(bullet.btVector3(0, -10, 0))
    bullet_world.getDispatchInfo().m_enableSPU = True

    bullet_debug_drawer = OgreBulletUtils.DebugDrawer(ogre_scene_manager)
    bullet_world.setDebugDrawer(bullet_debug_drawer)
    bullet_world.getDebugDrawer().setDebugMode(
                                       bullet.btIDebugDraw.DBG_DrawWireframe |
                                       bullet.btIDebugDraw.DBG_DrawAabb
                                       #bullet.btIDebugDraw.DBG_DrawContactPoints
                                       #bullet.btIDebugDraw.DBG_NoDebug
                                               )
 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))
Example #8
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
Example #9
0
 def initialize(self):
     self.duration = 1000 * 60 * 30  # 30 minutes
     self.teams = {RED_TEAM: Team(RED_TEAM, bullet.btVector3(0, 0, 0), [], "team/red", 0),
                   BLUE_TEAM: Team(BLUE_TEAM, bullet.btVector3(0, 0, 0), [], "team/blue", 0)}
     self.min_teams = 2
     self.max_teams = 2
     self.min_players = 2
     self.max_players = 12
     self.winning_score = 10
     self.game_state = GameState.WAITING_FOR_PLAYERS
Example #10
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
Example #11
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);
Example #12
0
 def setupBullet( self ):
     self.collisionConfiguration = bullet.btDefaultCollisionConfiguration() 
     self.dispatcher = bullet.btCollisionDispatcher (self.collisionConfiguration) 
     worldAabbMin = bullet.btVector3(-1000,-1000,-1000) 
     worldAabbMax = bullet.btVector3(1000,1000,1000) 
     maxProxies = 32# 766 
     self.broadphase = bullet.btAxisSweep3(worldAabbMin, worldAabbMax, maxProxies) 
     self.solver = bullet.btSequentialImpulseConstraintSolver() 
     self.world = bullet.btDiscreteDynamicsWorld(self.dispatcher, self.broadphase , self.solver, self.collisionConfiguration) 
     self.world.stepSimulation(0.1)
     self.world.stepSimulation(1)
     print "Leaving setup"
 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
Example #14
0
    def __init__(self, app):
        self.app = app
        self.body = {}
        
        app.world = self

        self.frameListener = WorldFrameListener(self)
        app.root.addFrameListener(self.frameListener)
        self.worldNode = app.sceneManager.getRootSceneNode().createChildSceneNode("World")
        
        self.physCollisionConfiguration = bullet.btDefaultCollisionConfiguration() 
        self.physDispatcher = bullet.btCollisionDispatcher (self.physCollisionConfiguration)
        
        # self.physBroadphase = bullet.btAxisSweep3(bullet.btVector3(-1000, -1000, -1000), bullet.btVector3(1000, 1000, 1000))
        self.physBroadphase = bullet.btDbvtBroadphase()
        self.physGhostCallback = bullet.btGhostPairCallback()
        self.physBroadphase.getOverlappingPairCache().setInternalGhostPairCallback(self.physGhostCallback)
        self.physSolver = bullet.btSequentialImpulseConstraintSolver() 
        self.physWorld = bullet.btDiscreteDynamicsWorld(self.physDispatcher, self.physBroadphase, self.physSolver, self.physCollisionConfiguration)
        self.physWorld.setGravity(bullet.btVector3(0, -10, 0))

        # self.cells = {}
        self.entities = {}

        self.setupWorld()
 def __init__(self, sceneManager):
    
     self.sceneManager = sceneManager
     """
     bounds = ogre.AxisAlignedBox(-100.0, -100.0, -100.0, 100.0, 100.0, 100.0)
     self.world = dynamics.DynamicsWorld(self.sceneManager, bounds, ogre.Vector3(0.0, -9.91, 0.0))
     """
     self.collisionConfiguration = bullet.get_btDefaultCollisionConfiguration()
     self.dispatcher = bullet.get_btCollisionDispatcher1(self.collisionConfiguration)
     
     self.broadphase = bullet.btDbvtBroadphase()
     self.solver = bullet.btSequentialImpulseConstraintSolver()
     
     self.world = bullet.btDiscreteDynamicsWorld(self.dispatcher, self.broadphase, self.solver, self.collisionConfiguration)
     self.world.setGravity(bullet.btVector3(0, 0, 0))
     
     self.bodies = []
     self.shapes = []
     self.cubes = []
     self.motionStates = []
     self.elapsedTime = 0.0
     self.duration = 10.0
     
     self.curCubeIdx = 0
     
     self.tangentBundle = None
     
     return None
Example #16
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)   
 def __init__(self, scaleDict):
     '''
     Constructor
     '''
     #self.constantGoal = ogre.Vector3(460,0,256)
     self.constantGoal = ogre.Vector3(308,0,303)
     self.unitsPerBlock = scaleDict['nUnitsToOneMeter'] #we do this because one units block is one meter. We need to write a class for this.
     self.YAXIS = ogre.Vector3(0.0, 1.0, 0.0)
     self.targetCell = ogre.Vector3(0,0,0)
     self.cell = ogre.Vector3(0,0,0)
     self.dir = ogre.Vector3(0, 0, 0)
     self.dirToGoal = ogre.Vector3(0, 0, 0)
     self.potMapReso = 0
     self.descendVec = ogre.Vector3(0, 0, 0)
     self.force = bullet.btVector3()
     self.thrustOffset = 0.0
     self.impulseForce = 5.0
     self.impulse=False
     self.q11 = ogre.Vector2()
     self.q21 = ogre.Vector2()
     self.q12 = ogre.Vector2()
     self.q22 = ogre.Vector2()
     self.fr10 = ogre.Vector2()
     self.fr11 = ogre.Vector2()
     self.fr20 = ogre.Vector2()
     self.fr21 = ogre.Vector2()
     self.fp = ogre.Vector2()
 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       
Example #19
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
Example #20
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);
Example #21
0
    def init(self, gravity):
        self.collisionConfiguration = bullet.btDefaultCollisionConfiguration()
        self.dispatcher = bullet.btCollisionDispatcher (self.collisionConfiguration)

        
        worldAabbMin = bullet.btVector3(-20000,-1000,-20000)
        worldAabbMax = bullet.btVector3(20000,1000,20000)
        self.broadphase = bullet.btAxisSweep3(worldAabbMin, worldAabbMax);

        self.solver = bullet.btSequentialImpulseConstraintSolver();

        self.world = bullet.btDiscreteDynamicsWorld(self.dispatcher, self.broadphase, self.solver,
                                                    self.collisionConfiguration);
        self.world.getDispatchInfo().m_enableSPU = True
        self.world.setGravity(bullet.btVector3(0,gravity,0));

        self.world.stepSimulation(0);
Example #22
0
 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
Example #23
0
 def init(self):
     """Setup keyboard hooks"""
     # Controllable MUST be renderable.
     if not hasattr(self.entity, Renderable.__name__):
         raise Exception("Controllable entities must have the renderable aspect")
     self.engine.physics_system.register_entity(self.entity, 1, PlayerMotionState)
     self.entity.rigid_body.setActivationState(DISABLE_DEACTIVATION)
     self.entity.rigid_body.setDamping(.999, 0)
     self.velocity = bullet.btVector3(0, 0, 0)
Example #24
0
    def _create_collision_entity(self, entity):
        """Register a static entity for collision detection as a cube. This
        function returns the collision object created"""
#        cobj = bullet.btCollisionObject()
        size = entity.size / 2
        cube = bullet.btBoxShape(bullet.btVector3(size, size, size))
#        cobj.setCollisionShape(cube)
#        self.collision_objects.append(cobj)
        return cube
 def createBoxShape(entity, unitScale=True):
     """Bullet Box Shape"""
     ## mesh extents
     e = MeshInfo.getBoundingBox(entity)
     size = bullet.btVector3(e.getHalfSize().x,
                             e.getHalfSize().y,
                             e.getHalfSize().z)
     print size.x(), size.y(), size.z()
     return bullet.btBoxShape(size)
Example #26
0
 def createBoxShape(entity, unitScale=True):
     """Bullet Box Shape"""
     ## mesh extents
     e = MeshInfo.getBoundingBox(entity)
     size = bullet.btVector3(e.getHalfSize().x,
                             e.getHalfSize().y,
                             e.getHalfSize().z)
     print size.x(), size.y(), size.z()
     return bullet.btBoxShape(size)
Example #27
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;
Example #28
0
    def createTriMeshShape(entity):
        """Bullet Triangle Mesh Shape"""
        vertices = []
        faces = []

        if entity.getMesh().sharedVertexData:
            vertices += MeshInfo.GetVerticies(
                entity.getMesh().sharedVertexData,
                entity.getParentSceneNode()._getFullTransform())

        for m in range(entity.getMesh().numSubMeshes):
            sm = entity.getMesh().getSubMesh(m)
            #print "Entity Shared ", entity.getMesh().sharedVertexData
            #print "Uses Shared Vertices ", sm.useSharedVertices
            #print "Uses Shared Vertices ", dir(sm.parent.sharedVertexData)

            if not sm.useSharedVertices:
                faces += MeshInfo.GetIndicies(sm.indexData)
                vertices += MeshInfo.GetVerticies(
                    sm.vertexData,
                    entity.getParentSceneNode()._getFullTransform())
                #print "ENTITY SUB MESH NO SHARED VERTEX DATA"
            else:
                faces += MeshInfo.GetIndicies(sm.indexData)

        logging.debug("Mesh faces: " + str(len(faces)) + "\tvertices: " +
                      str(len(vertices)))

        mTriMesh = bullet.btTriangleMesh()
        for ind in faces:
            v1 = vertices[ind[0]]
            v2 = vertices[ind[1]]
            v3 = vertices[ind[2]]
            b1 = bullet.btVector3(v1[0], v1[1], v1[2])
            b2 = bullet.btVector3(v2[0], v2[1], v2[2])
            b3 = bullet.btVector3(v3[0], v3[1], v3[2])
            mTriMesh.addTriangle(b1, b2, b3)

        useQuantizedAABB = True
        del vertices
        del faces
        return mTriMesh, bullet.btBvhTriangleMeshShape(mTriMesh,
                                                       useQuantizedAABB)
Example #29
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
 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
 def createCylinderShape(entity, axis):
     """Bullet Cylinder Shape"""
     ## mesh extents
     e = MeshInfo.getBoundingBox(entity)
     size = bullet.btVector3(e.getHalfSize().x,
                             e.getHalfSize().y,
                             e.getHalfSize().z)
     shape = None
     if axis == BulletShapes.CYLINDERX:
         height = size.x()
         radius = max(size.z(), size.y())
         shape = bullet.btCylinderShapeX(bullet.btVector3(height, radius, radius))
     if axis == BulletShapes.CYLINDERY:
         height = size.y()
         radius = max(size.z(), size.x())
         shape = bullet.btCylinderShape(bullet.btVector3(radius, height, radius))
     if axis == BulletShapes.CYLINDERZ:
         height = size.z()
         radius = max(size.x(), size.y())
         shape = bullet.btCylinderShapeZ(bullet.btVector3(radius, radius, height))
     return shape
Example #32
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 createTriMeshShape(entity):
        """Bullet Triangle Mesh Shape"""
        vertices = []
        faces = []

        if entity.getMesh().sharedVertexData:
            vertices += MeshInfo.GetVerticies(entity.getMesh().sharedVertexData,
                              entity.getParentSceneNode()._getFullTransform())

        for m in range(entity.getMesh().numSubMeshes):
            sm = entity.getMesh().getSubMesh(m)
            #print "Entity Shared ", entity.getMesh().sharedVertexData
            #print "Uses Shared Vertices ", sm.useSharedVertices
            #print "Uses Shared Vertices ", dir(sm.parent.sharedVertexData)

            if not sm.useSharedVertices:
                faces += MeshInfo.GetIndicies (sm.indexData)
                vertices += MeshInfo.GetVerticies (sm.vertexData, entity.getParentSceneNode()._getFullTransform())
                #print "ENTITY SUB MESH NO SHARED VERTEX DATA"
            else:
                faces += MeshInfo.GetIndicies (sm.indexData)


        logging.debug("Mesh faces: " + str(len(faces)) +
                        "\tvertices: " + str(len(vertices)))

        mTriMesh = bullet.btTriangleMesh()
        for ind in faces:
            v1 = vertices[ind[0]]
            v2 = vertices[ind[1]]
            v3 = vertices[ind[2]]
            b1 = bullet.btVector3(v1[0], v1[1], v1[2])
            b2 = bullet.btVector3(v2[0], v2[1], v2[2])
            b3 = bullet.btVector3(v3[0], v3[1], v3[2])
            mTriMesh.addTriangle(b1, b2, b3)

        useQuantizedAABB = True
        del vertices
        del faces
        return mTriMesh, bullet.btBvhTriangleMeshShape(mTriMesh, useQuantizedAABB)
 def setWorldTransform(self, WorldTrans):
     #print "setWorldTrans", WorldTrans 
     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()) 
  
     self.node.setPosition(self.Position)
     self.node.setOrientation(self.Quaternion)
     
     
     if(self.tb is not None):
         self.tb.setPosition(self.Position)
         normal = -self.tb.normal*3000.0 / self.tb.dsqr
         gravity = bullet.btVector3(normal.x, normal.y, normal.z)
         self.rb.setGravity(gravity)           
         self.rb.applyGravity() 
Example #35
0
 def createCylinderShape(entity, axis):
     """Bullet Cylinder Shape"""
     ## mesh extents
     e = MeshInfo.getBoundingBox(entity)
     size = bullet.btVector3(e.getHalfSize().x,
                             e.getHalfSize().y,
                             e.getHalfSize().z)
     shape = None
     if axis == BulletShapes.CYLINDERX:
         height = size.x()
         radius = max(size.z(), size.y())
         shape = bullet.btCylinderShapeX(
             bullet.btVector3(height, radius, radius))
     if axis == BulletShapes.CYLINDERY:
         height = size.y()
         radius = max(size.z(), size.x())
         shape = bullet.btCylinderShape(
             bullet.btVector3(radius, height, radius))
     if axis == BulletShapes.CYLINDERZ:
         height = size.z()
         radius = max(size.x(), size.y())
         shape = bullet.btCylinderShapeZ(
             bullet.btVector3(radius, radius, height))
     return shape
Example #36
0
 def createConeShape(entity, axis):
     """Bullet Cone Shape"""
     e = MeshInfo.getBoundingBox(entity)
     size = bullet.btVector3(e.getHalfSize().x,
                             e.getHalfSize().y,
                             e.getHalfSize().z)
     shape = None
     if axis == BulletShapes.CONEX:
         height = size.x()
         radius = max(size.z(), size.y()) / 2.0
         shape = bullet.btConeShapeX(radius, height)
     if axis == BulletShapes.CONEY:
         height = size.y()
         radius = max(size.x(), size.z()) / 2.0
         shape = bullet.btConeShape(radius, height)
     if axis == BulletShapes.CONEZ:
         height = size.z()
         radius = max(size.x(), size.y()) / 2.0
         shape = bullet.btConeShapeZ(radius, height)
     return shape