[Bullet3]常见物体和初始化
来源:互联网 发布:淘宝费用预算 编辑:程序博客网 时间:2024/06/06 08:57
官方文档:http://bulletphysics.org
开源代码:https://github.com/bulletphysics/bullet3/releases
API文档:http://bulletphysics.org/Bullet/BulletFull/annotated.html
1. 初始化物体
- 物体的形状由
btCollisionShape
对象维护; - 物体的位置,旋转状态由
btTransform
对象维护; - 最终需要将物体封装成
btRigidBody
或btSoftBody
或其它对象; - 然后将步骤3的对象加入到场景中。
例如
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); // 将物体添加到场景
2. 常见物体对象
- btCollisionObject 基类
- btRigidBody 刚体
- btSoftBody 流体
2.1. 物体对象常用函数
btCollisionShape* btCollisionObject::getCollisionShape()
- btCollisionObject对象中获取形状维护对象
void btCollisionObject::setFriction(btScalar frict)
- 设置摩擦力
- 默认值:0
void btCollisionObject::setRestitution(btScalar rest)
- 设置碰撞反弹系数
- 默认值:0
void btRigidBody::applyImpulse(const btVector3 & impulse, const btVector3 & rel_pos)
- 设置冲量/动量(通过这个设置初始速度)
void btRigidBody::applyCentralImpulse(const btVector3 & impulse)
- 设置冲量/动量(通过这个设置初始速度)
- 默认值:0
3. 初始化常见物体形状
http://bulletphysics.org/Bullet/BulletFull/classbtCollisionShape.html
常见的物体有长方体、球体、胶囊体、三角网格集合。
- btCollisionShap
- 基类
- btBoxShape
- 长方体
- BOX_SHAPE_PROXYTYPE
- btSphereShape
- 球体
- SPHERE_SHAPE_PROXYTYPE
- btCapsuleShape
- 胶囊体
- CAPSULE_SHAPE_PROXYTYPE
- btBvhTriangleMeshShap
- 三角网格
- TRIANGLE_MESH_SHAPE_PROXYTYPE
3.1. 物体对象常用函数
int btCollisionShape::getShapeType() const
- 获取物品类型,类型参考以下枚举
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types
3.2. 三角网格
- 构造函数
btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface,bool useQuantizedAabbCompression)
- 构造函数
btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface,bool useQuantizedAabbCompression, bool buildBvh = true)
btTriangleIndexVertexArray
类集成于btStridingMeshInterface
接口。btIndexedMesh
三角网格顶点列表和索引列表维护类
3.2.1. 三角网格数据假设格式如下
- 顶点表 Vertex Buff
- 三角形表 Index Buff
#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,...};
3.2.3. btStridingMeshInterface
接口
通用高性能三角网格访问接口。
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);
3.3. 长方体
- 构造函数
btBoxShape::btBoxShape(const btVector3 & boxHalfExtents)
- 长宽高,封装成
btVector3
对象
3.4. 球
- 构造函数
btSphereShape::btSphereShape(btScalar radius)
- radius xyz轴的半径,可以设置为椭圆球
3.5. 胶囊体
- 构造函数
btCapsuleShape::btCapsuleShape()
- 构造函数
btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
- radius 胶囊体半径,可以设置为椭圆球
- height 胶囊体长度,height为圆心之间的距离
- 胶囊体的aabb的边的长度为 {radius2, radius2, radius*2+height}
0 0
- [Bullet3]常见物体和初始化
- [Bullet3]常见物体和初始化
- [Bullet3]常见物体和初始化
- [Bullet3]常见物体和初始化
- 折射率-常见物体
- 【Unity】初始化物体赋予组件
- Bullet3之封装PhysicsWorld3D
- grub2下常见系统初始化错误的分析和解决
- 【Unity】初始化物体的旋转角度
- 物体移动和旋转
- 销毁物体和ExecuteInEditMode
- 常见网站CSS初始化
- 《初始化和反初始化》
- 动态生成和销毁物体
- 物体
- 物体
- 图像物体分类和物体检测算法的概括
- LINUX内核和驱动中常见的 C语法---》标记化 初始化
- Ubuntu 14.04keepalived环境搭建
- 原理:pinctrl基础
- java得用锁解决并发问题的简单示例
- Scala 的参数检查与断言: require, assert, assume 和 ensuring
- Mysql bigint类型 BUG
- [Bullet3]常见物体和初始化
- python基础之模块之os模块
- 打印fastjson对象时,如果内部键值为null,则该键不会打印出来
- Java基础--线程(2)
- [Android新手学习笔记17]-UI控件之ProgressDialog
- Struts2 Key Technologies Primer
- 29.日志路由组件(2)
- angularjs排序
- Java 的参数检查与断言 - Guava Preconditions