2014-06-16 22 views
1

我用子彈物理引擎使用btGImpactMeshShape .. 加載OBJ模型世界我很新的使用該引擎使用子彈物理加載OBJ模型btGImpactMeshShape但結果是錯誤的

這裏是我的代碼

//---------------------------------------// 

//   load from obj    // 

//---------------------------------------// 

ConvexDecomposition::WavefrontObj wobj; 
printf("load first try"); fflush(stdout); 
std::string filename("bunny.obj"); 
int result = wobj.loadObj("bunny.obj"); 
if(!result) 
{ 
printf("first try fail\n"); fflush(stdout); 
printf("load second try"); fflush(stdout); 
result = wobj.loadObj("../bunny.obj"); 
} 

printf("--load status %d\n", result); 
printf("--triangle: %d\n", wobj.mTriCount); 
printf("--vertex: %d\n", wobj.mVertexCount); 


btTriangleIndexVertexArray* colonVertexArrays = new btTriangleIndexVertexArray(
wobj.mTriCount, 
wobj.mIndices, 
       3*sizeof(int), 
       wobj.mVertexCount, 
       wobj.mVertices, 
       3*sizeof(float) 
       ); 

btGImpactMeshShape* bunnymesh = new btGImpactMeshShape(colonVertexArrays); 
bunnymesh ->setLocalScaling(btVector3(0.5f, 0.5f, 0.5f)); 
bunnymesh ->updateBound(); 
startTransform.setOrigin(btVector3(0.0, 0.0, 0.0)); 
startTransform.getBasis().setEulerZYX(0, 0, 0); 
localCreateRigidBody(bunnymesh , startTransform, 0.0); 
printf("Load done...\n"); 

在這裏,在該予加載..............此兔子已於MAC

original bunny model viewed by Meshlab

使用MeshLab觀察的模型

我試圖改變各種參數的步幅,然而,這是從我的程序

using bullet to view Bunny Console output

的結果,你有什麼建議,有什麼不好的代碼?

回答

0

是不是wobj.mVertices指向雙數組的指針? btTriangleIndexVertexArray需要一個指向浮動,所以你必須創建一個新的int數組,複製並投了頂點。

+0

感謝您的建議。但是,我怎麼能設置指針浮動。問題與我的模型有關嗎?或者我必須更改我的代碼的任何部分。 – MooMoo

0

攪拌機命名其指數從1開始,而子彈物理爲0 開始作爲一個例證,在這裏低於從Blender導出的立方體網格,然後呈現爲btGImpactMeshShape和3個立方體呈現爲btBoxShape。同樣在下面,btTriangleIndexVertexArray的頂點和索引應該如何用於立方體網格物體,以在子彈物理中正確呈現爲btGImpactMeshShape。如需更多信息,點擊鏈接上看到Bullet Physics forum.

類似的線程要了解更多關於btTriangleIndexVertexArraybtGImpactMeshShape,也看到了子彈物理SDK,展示了一個圓環和...斯坦福兔子的GimpactTestDemo。

const int NUMBER_VERTICES = 8; 
const int NUMBER_TRIANGLES = 12; 

static float cubeVertices[NUMBER_VERTICES * 3] = { 
    1.000000, -1.000000, -1.000000, 
    1.000000, -1.000000, 1.000000, 
    -1.000000, -1.000000, 1.000000, 
    -1.000000, -1.000000, -1.000000, 
    1.000000, 1.000000, -0.999999, 
    0.999999, 1.000000, 1.000001, 
    -1.000000, 1.000000, 1.000000, 
    -1.000000, 1.000000, -1.000000 
}; 

static int cubeIndices[NUMBER_TRIANGLES][3] = { 
    { 1, 3, 0 }, 
    { 7, 5, 4 }, 
    { 4, 1, 0 }, 
    { 5, 2, 1 }, 
    { 2, 7, 3 }, 
    { 0, 7, 4 }, 
    { 1, 2, 3 }, 
    { 7, 6, 5 }, 
    { 4, 5, 1 }, 
    { 5, 6, 2 }, 
    { 2, 6, 7 }, 
    { 0, 3, 7 } 
}; 

enter image description here