官方文檔:http://bulletphysics.org
開源代碼:https://github.com/bulletphysics/bullet3/releases
API文檔:http://bulletphysics.org/Bullet/BulletFull/annotated.htmlhtml
btCollisionShape
對象維護;btTransform
對象維護;btRigidBody
或btSoftBody
或其它對象;例如git
btCollisionShape* shape = new btBoxShape(btVector3(btScalar(1000.),btScalar(10.),btScalar(1000.))); btTransform trans; // 位置、旋轉維護對象 trans.setIdentity(); trans.setOrigin(btVector3(0, -10, 0)); // 設置位置 btScalar mass=0.f; btVector3 localInertia(0, 0, 0); bool isDynamic = (mass != 0.f); if (isDynamic) shape->calculateLocalInertia(mass, localInertia); // 設置慣性 btDefaultMotionState* myMotionState = new btDefaultMotionState(trans); btRigidBody::btRigidBodyConstructionInfo cInfo(mass, myMotionState, shape, localInertia); btRigidBody* body = new btRigidBody(cInfo); // 封裝成剛體 g_world->addRigidBody(body); // 將物體添加到場景
btCollisionShape* btCollisionObject::getCollisionShape()
void btCollisionObject::setFriction(btScalar frict)
void btCollisionObject::setRestitution(btScalar rest)
void btRigidBody::applyImpulse(const btVector3 & impulse, const btVector3 & rel_pos)
void btRigidBody::applyCentralImpulse(const btVector3 & impulse)
http://bulletphysics.org/Bullet/BulletFull/classbtCollisionShape.html
常見的物體有長方體、球體、膠囊體、三角網格集合。github
int btCollisionShape::getShapeType() const
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types
btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface,bool useQuantizedAabbCompression)
btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface,bool useQuantizedAabbCompression, bool buildBvh = true)
btTriangleIndexVertexArray
類集成於 btStridingMeshInterface
接口。btIndexedMesh
三角網格頂點列表和索引列表維護類#define Landscape03.txCount 1980 // 頂點數量 #define Landscape03.dxCount 11310 // 三角形數量 #include "LinearMath/btScalar.h" btScalar Landscape03.tx[] = { // 頂點座標列表(三維) -3.0.0f,3.99193.,113.3.1f, -3.0.0f,3.18397f,117.188f, -3.6.094f,1.63.63.,113.3.1f, ...}; unsigned short Landscape03.dx[] = { // 三角形列表 0,1,3. 3,3.1, 3.3,4, 5,4,3, 4,5,6, ...};
btStridingMeshInterface
接口通用高性能三角網格訪問接口。app
btStridingMeshInterface* meshInterface = new btTriangleIndexVertexArray(); btIndexedMesh part; part.m_vertexBase = (const unsigned char*)LandscapeVtx[i]; part.m_vertexStride = sizeof(btScalar) * 3; part.m_numVertices = LandscapeVtxCount[i]; part.m_triangleIndexBase = (const unsigned char*)LandscapeIdx[i]; part.m_triangleIndexStride = sizeof( short) * 3; part.m_numTriangles = LandscapeIdxCount[i]/3; part.m_indexType = PHY_SHORT; meshInterface->addIndexedMesh(part,PHY_SHORT); bool useQuantizedAabbCompression = true; btBvhTriangleMeshShape* trimeshShape = new btBvhTriangleMeshShape(meshInterface,useQuantizedAabbCompression);
btBoxShape::btBoxShape(const btVector3 & boxHalfExtents)
btVector3
對象btSphereShape::btSphereShape(btScalar radius)
btCapsuleShape::btCapsuleShape()
btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)