2014-06-16 23 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