コード例 #1
0
ファイル: demoapplication.py プロジェクト: insollo/swigbullet
    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;
コード例 #2
0
    broadphase = bullet.btDbvtBroadphase()
    collisionConfiguration = bullet.btDefaultCollisionConfiguration()
    dispatcher = bullet.btCollisionDispatcher(collisionConfiguration)

    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):
        dynamicsWorld.stepSimulation(1 / 60.0, 10)