官方文档: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)