Bullet3 常見物體和初始化

2021-09-07 21:29:49 字數 2539 閱讀 2499

官方文件:

開源**:

api文件:/bullet/bulletfull/annotated.html

物體的形狀由btcollisionshape物件維護;

物體的位置,旋轉狀態由bttransform物件維護;

最終需要將物體封裝成btrigidbodybtsoftbody或其它物件;

然後將步驟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.1. 物體物件常用函式

void btcollisionobject::setfriction(btscalar frict)

void btcollisionobject::setrestitution(btscalar rest)

/bullet/bulletfull/classbtcollisionshape.html

常見的物體有長方體、球體、膠囊體、三角網格集合。

btboxshape

btsphereshape

btcapsuleshape

btbvh********meshshap

3.1. 物體物件常用函式

3.2. 三角網格

3.2.1. 三角網格資料假設格式如下

#define landscape03.txcount 1980      // 頂點數量

#define landscape03.dxcount 11310 // 三角形數量

#include "linearmath/btscalar.h"

btscalar landscape03.tx = ;

unsigned short landscape03.dx = ;

3.2.3.btstridingmeshinte***ce介面

通用高效能三角網格訪問介面。

btstridingmeshinte***ce* meshinte***ce = new bt********indexvertexarray();

btindexedmesh part;

part.m_vertexbase = (const unsigned char*)landscapevtx[i];

part.m_vertexstride = sizeof(btscalar) * 3;

part.m_numvertices = landscapevtxcount[i];

part.m_********indexbase = (const unsigned char*)landscapeidx[i];

part.m_********indexstride = sizeof( short) * 3;

part.m_num********s = landscapeidxcount[i]/3;

part.m_indextype = phy_short;

meshinte***ce->addindexedmesh(part,phy_short);

bool usequantizedaabbcompression = true;

btbvh********meshshape* trimeshshape = new btbvh********meshshape(meshinte***ce,usequantizedaabbcompression);

3.3. 長方體

3.4. 球

3.5. 膠囊體

Bullet3 常見物體和初始化

官方文件 開源 api文件 bullet bulletfull annotated.html 物體的形狀由btcollisionshape物件維護 物體的位置,旋轉狀態由bttransform物件維護 最終需要將物體封裝成btrigidbody或btsoftbody或其它物件 然後將步驟3的物件加入...

mysql初始化很慢 mysql 初始化常見問題

初始化mysql常見錯誤,都是缺少依賴包導致 1.報錯資訊 bash scripts mysql install db usr bin perl 壞的直譯器 沒有那個檔案或目錄 解決方法 yum install perl gcc kernel devel 2.報錯資訊 fatal error ple...

直接初始化和複製初始化

關於這個問題,國內外都有許多爭論,但我至今未找到滿意的答案,至於為為什麼,這就是今天要說明的。可能大家都有看過c primer,我看的是第四版,中文版,英文水平不怎麼樣。其中第13章,描述說,複製建構函式可用於 1.根據另乙個同型別的物件顯式或隱式初始化乙個物件 2.複製乙個物件,將它作為引數傳遞給...