示例#1
0
 def setUp(self):
     self.step = 1.0 / 60
     self.motion_state1 = bullet.btDefaultMotionState()
     self.motion_state2 = bullet.btDefaultMotionState()
     self.radius = 1.0
     self.inertia = bullet.btVector3(1, 1, 1)
     self.sphere_shape = bullet.btSphereShape(self.radius)
     self.points = [
         bullet.btVector3(-1, -1, -1),
         bullet.btVector3(-1, 1, -1),
         bullet.btVector3(-1, -1, 1),
         bullet.btVector3(-1, 1, 1),
         bullet.btVector3(1, 1, 1),
         bullet.btVector3(1, -1, 1),
         bullet.btVector3(1, -1, -1),
         bullet.btVector3(1, 1, -1)
     ]
     self.hull = bullet.btConvexHullShape(self.points)
     self.info = bullet.btRigidBodyConstructionInfo(1.0, self.motion_state1,
                                                    self.sphere_shape,
                                                    self.inertia)
     self.v1 = bullet.btVector3(0, 0, 0)
     self.v2 = bullet.btVector3(0, 0, 0)
     self.v3 = bullet.btVector3(0, 0, 0)
     self.t1 = bullet.btTransform.identity
     self.t2 = bullet.btTransform.identity
     self.body1 = bullet.btRigidBody(self.info)
     self.body2 = bullet.btRigidBody(1.0, self.motion_state2, self.hull,
                                     self.v1)
     self.m1 = bullet.btMatrix3x3.identity
     self.m2 = bullet.btMatrix3x3.identity
 def setUp(self):
     self.step = 1.0/60
     self.motion_state1 = bullet.btDefaultMotionState()
     self.motion_state2 = bullet.btDefaultMotionState()
     self.radius = 1.0
     self.inertia = bullet.btVector3(1, 1, 1)
     self.sphere_shape = bullet.btSphereShape(self.radius)
     self.points = [
         bullet.btVector3(-1, -1, -1),
         bullet.btVector3(-1, 1, -1),
         bullet.btVector3(-1, -1, 1),
         bullet.btVector3(-1, 1, 1),
         bullet.btVector3(1, 1, 1),
         bullet.btVector3(1, -1, 1),
         bullet.btVector3(1, -1, -1),
         bullet.btVector3(1, 1, -1)
     ]
     self.hull = bullet.btConvexHullShape(self.points)
     self.info = bullet.btRigidBodyConstructionInfo(
         1.0,
         self.motion_state1,
         self.sphere_shape,
         self.inertia
     )
     self.v1 = bullet.btVector3(0, 0, 0)
     self.v2 = bullet.btVector3(0, 0, 0)
     self.v3 = bullet.btVector3(0, 0, 0)
     self.t1 = bullet.btTransform.identity
     self.t2 = bullet.btTransform.identity
     self.body1 = bullet.btRigidBody(self.info)
     self.body2 = bullet.btRigidBody(1.0, self.motion_state2,
                                     self.hull, self.v1)
     self.m1 = bullet.btMatrix3x3.identity
     self.m2 = bullet.btMatrix3x3.identity
示例#3
0
    def	localCreateRigidBody(self, mass, startTransform, shape):
        assert((not shape or shape.getShapeType() != bullet.INVALID_SHAPE_PROXYTYPE));

        # rigidbody is dynamic if and only if mass is non zero, otherwise static
        isDynamic = (mass != 0.0);

        localInertia=(0,0,0);
        if (isDynamic):
            shape.calculateLocalInertia(mass,localInertia);

        # using motionstate is recommended,
        # it provides interpolation capabilities,
        # and only synchronizes 'active' objects

        myMotionState = bullet.btDefaultMotionState(startTransform);

        cInfo=bullet.btRigidBodyConstructionInfo (mass,myMotionState,shape,localInertia);

        body = bullet.btRigidBody(cInfo);
        body.setContactProcessingThreshold(self.m_defaultContactProcessingThreshold);

        self.m_dynamicsWorld.addRigidBody(body);

        self.m_keep.append((myMotionState, cInfo, body, shape))

        return body;
示例#4
0
    def localCreateRigidBody(self, mass, startTransform, shape):
        assert ((not shape
                 or shape.getShapeType() != bullet.INVALID_SHAPE_PROXYTYPE))

        # rigidbody is dynamic if and only if mass is non zero, otherwise static
        isDynamic = (mass != 0.0)

        localInertia = (0, 0, 0)
        if (isDynamic):
            shape.calculateLocalInertia(mass, localInertia)

        # using motionstate is recommended,
        # it provides interpolation capabilities,
        # and only synchronizes 'active' objects

        myMotionState = bullet.btDefaultMotionState(startTransform)

        cInfo = bullet.btRigidBodyConstructionInfo(mass, myMotionState, shape,
                                                   localInertia)

        body = bullet.btRigidBody(cInfo)
        body.setContactProcessingThreshold(
            self.m_defaultContactProcessingThreshold)

        self.m_dynamicsWorld.addRigidBody(body)

        self.m_keep.append((myMotionState, cInfo, body, shape))

        return body
 def test_add_ground(self):
     self.ground_shape = bullet.btStaticPlaneShape(
         bullet.btVector3(0, 1, 0), 1)
     self.ground_motion_state = bullet.btDefaultMotionState(
         bullet.btTransform(bullet.btQuaternion.identity,
                            bullet.btVector3(0, -1, 0)))
     self.ground_rigid_body_cinfo = bullet.btRigidBodyConstructionInfo(
         0, self.ground_motion_state, self.ground_shape,
         bullet.btVector3(0, 0, 0))
     self.ground_rigid_body = \
         bullet.btRigidBody(self.ground_rigid_body_cinfo)
     self.dynamics_world.add_rigid_body(self.ground_rigid_body)
 def test_add_sphere(self, pos=bullet.btVector3(0, 0, 0)):
     self.sphere_shape = bullet.btSphereShape(1)
     self.sphere_motion_state = bullet.btDefaultMotionState(
         bullet.btTransform(bullet.btQuaternion.identity, pos))
     self.sphere_mass = 1.0
     self.fall_inertia = bullet.btVector3(0, 0, 0)
     self.sphere_shape.calculate_local_inertia(self.sphere_mass,
                                               self.fall_inertia)
     self.sphere_rigid_body_cinfo = bullet.btRigidBodyConstructionInfo(
         self.sphere_mass, self.sphere_motion_state, self.sphere_shape,
         self.fall_inertia)
     self.sphere_rigid_body = \
         bullet.btRigidBody(self.sphere_rigid_body_cinfo)
     self.dynamics_world.add_rigid_body(self.sphere_rigid_body)
 def test_add_ground(self):
     self.ground_shape = bullet.btStaticPlaneShape(
         bullet.btVector3(0, 1, 0), 1
     )
     self.ground_motion_state = bullet.btDefaultMotionState(
         bullet.btTransform(bullet.btQuaternion.identity,
                            bullet.btVector3(0, -1, 0))
     )
     self.ground_rigid_body_cinfo = bullet.btRigidBodyConstructionInfo(
         0, self.ground_motion_state, self.ground_shape,
         bullet.btVector3(0, 0, 0)
     )
     self.ground_rigid_body = \
         bullet.btRigidBody(self.ground_rigid_body_cinfo)
     self.dynamics_world.add_rigid_body(self.ground_rigid_body)
 def test_add_sphere(self, pos=bullet.btVector3(0, 0, 0)):
     self.sphere_shape = bullet.btSphereShape(1)
     self.sphere_motion_state = bullet.btDefaultMotionState(
         bullet.btTransform(bullet.btQuaternion.identity,
                            pos)
     )
     self.sphere_mass = 1.0
     self.fall_inertia = bullet.btVector3(0, 0, 0)
     self.sphere_shape.calculate_local_inertia(self.sphere_mass,
                                               self.fall_inertia)
     self.sphere_rigid_body_cinfo = bullet.btRigidBodyConstructionInfo(
         self.sphere_mass, self.sphere_motion_state, self.sphere_shape,
         self.fall_inertia
     )
     self.sphere_rigid_body = \
         bullet.btRigidBody(self.sphere_rigid_body_cinfo)
     self.dynamics_world.add_rigid_body(self.sphere_rigid_body)
示例#9
0
文件: BasicDemo.py 项目: asumin/onibi
    def createAndAppendBody(self, shape, mass, transform):
        # rigidbody is dynamic if and only if mass is non zero, otherwise static
        isDynamic = (mass != 0.0)

        localInertia = (0, 0, 0)
        if (isDynamic):
            shape.calculateLocalInertia(mass, localInertia)

        # using motionstate is recommended,
        # it provides interpolation capabilities, and only synchronizes 'active' objects
        myMotionState = bullet.btDefaultMotionState(transform)
        rbInfo = bullet.btRigidBodyConstructionInfo(mass, myMotionState, shape,
                                                    localInertia)
        body = bullet.btRigidBody(rbInfo)

        # add the body to the dynamics world
        self.m_dynamicsWorld.addRigidBody(body)
        self.m_keep.append((shape, myMotionState, body))
示例#10
0
文件: BasicDemo.py 项目: asumin/onibi
    def createAndAppendBody(self, shape, mass, transform):
        # rigidbody is dynamic if and only if mass is non zero, otherwise static
        isDynamic = (mass != 0.0);

        localInertia=(0,0,0);
        if (isDynamic):
            shape.calculateLocalInertia(mass,localInertia);

        # using motionstate is recommended, 
        # it provides interpolation capabilities, and only synchronizes 'active' objects
        myMotionState = bullet.btDefaultMotionState(transform);
        rbInfo=bullet.btRigidBodyConstructionInfo(mass,
                myMotionState,
                shape,
                localInertia);
        body = bullet.btRigidBody(rbInfo);

        # add the body to the dynamics world
        self.m_dynamicsWorld.addRigidBody(body);
        self.m_keep.append((shape, myMotionState, body));
示例#11
0
            dispatcher, broadphase, solver, collisionConfiguration);

    dynamicsWorld.setGravity((0,-10,0));

    groundShape = bullet.btStaticPlaneShape((0,1,0), 1);

    fallShape = bullet.btSphereShape(1);

    groundMotionState = bullet.btDefaultMotionState(
            bullet.btTransform(
                bullet.btQuaternion(0,0,0,1),
                (0,-1,0)
                )
            );

    groundRigidBodyCI=bullet.btRigidBodyConstructionInfo(0,
            groundMotionState, groundShape, (0,0,0));
    groundRigidBody = bullet.btRigidBody(groundRigidBodyCI);
    dynamicsWorld.addRigidBody(groundRigidBody);
 
    fallMotionState = bullet.btDefaultMotionState(
            bullet.btTransform(
                bullet.btQuaternion(0,0,0,1),
                (0,50,0)
                )
            );

    mass = 1;
    fallInertia=(0,0,0);
    fallShape.calculateLocalInertia(mass,fallInertia);
    fallRigidBodyCI=bullet.btRigidBodyConstructionInfo(mass,fallMotionState,fallShape,fallInertia);
    fallRigidBody = bullet.btRigidBody(fallRigidBodyCI);
示例#12
0
    solver = bullet.btSequentialImpulseConstraintSolver()
    dynamicsWorld = bullet.btDiscreteDynamicsWorld(dispatcher, broadphase,
                                                   solver,
                                                   collisionConfiguration)

    dynamicsWorld.setGravity((0, -10, 0))

    groundShape = bullet.btStaticPlaneShape((0, 1, 0), 1)

    fallShape = bullet.btSphereShape(1)

    groundMotionState = bullet.btDefaultMotionState(
        bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), (0, -1, 0)))

    groundRigidBodyCI = bullet.btRigidBodyConstructionInfo(
        0, groundMotionState, groundShape, (0, 0, 0))
    groundRigidBody = bullet.btRigidBody(groundRigidBodyCI)
    dynamicsWorld.addRigidBody(groundRigidBody)

    fallMotionState = bullet.btDefaultMotionState(
        bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), (0, 50, 0)))

    mass = 1
    fallInertia = (0, 0, 0)
    fallShape.calculateLocalInertia(mass, fallInertia)
    fallRigidBodyCI = bullet.btRigidBodyConstructionInfo(
        mass, fallMotionState, fallShape, fallInertia)
    fallRigidBody = bullet.btRigidBody(fallRigidBodyCI)
    dynamicsWorld.addRigidBody(fallRigidBody)

    for i in range(300):