如何绘制/渲染Bullet Physics碰撞体/形状?

And*_*oob 4 c++ android android-ndk bulletphysics opengl-es-2.0

我已经使用NDK将Bullet Physics引擎实现到我的android程序中(我使用的是Vuforia的 imagetarget示例,用于android),它已经设置并正常工作,但是我想渲染/绘制我的碰撞盒/飞机来查看我的刚体(btRigidBody)/碰撞形状(btCollisionShape),我很肯定这是可能的,但我找不到任何关于如何做的教程!

我已经在他们的wiki页面上接受了hello world Bullet物理教程并修改它以应用从坠落物理体到我在opengl es 2.0中查看碰撞体的3d对象的转换,这里是我用来渲染的代码反对:

void drawRigidBody(btRigidBody* body,QCAR::Matrix44F modelViewMatrix, unsigned int textureID)
{
btTransform trans;
body->getMotionState()->getWorldTransform(trans);
    LOG("sphere pos: (x %f , y %f, z %f)",trans.getOrigin().getX(),trans.getOrigin().getY(),trans.getOrigin().getZ());


    float physicsMatrix[16];
    trans.getOpenGLMatrix(physicsMatrix);

    SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
            &modelViewMatrix.data[0]);

    QCAR::Matrix44F modelViewProjection, objectMatrix;
    SampleUtils::multiplyMatrix(&modelViewMatrix.data[0], physicsMatrix, &objectMatrix.data[0]);
    SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &objectMatrix.data[0], &modelViewProjection.data[0]);



    glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
            (const GLvoid*) &signVerts[0]);
    glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
            (const GLvoid*) &signNormals[0]);
    glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
            (const GLvoid*) &signTexCoords[0]);

    glEnableVertexAttribArray(vertexHandle);
    glEnableVertexAttribArray(normalHandle);
    glEnableVertexAttribArray(textureCoordHandle);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, textureID);
    glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
            (GLfloat*)&modelViewProjection.data[0] );
    glDrawArrays(GL_TRIANGLES, 0, signNumVerts);
}
Run Code Online (Sandbox Code Playgroud)

编辑:看看btBoxShape的代码,我注意到你可以抓住框顶点和法线:

btVector3** vertices= wallShape->getVertices();
btVector3**normals = wallShape->getNormals();
Run Code Online (Sandbox Code Playgroud)

但你不能抓住一个索引列表来按特定顺序绘制顶点!

Tim*_*Tim 10

如果我没记错,这不是在Bullet中绘制调试形状的正确方法.您是否阅读了第16页的用户手册(PDF)

您应该实现自己的实现的调试抽屉类btIDebugDraw,并在此类中实现该drawLine方法.

您将此调试抽屉传递给项目符号setDebugDrawer,然后启用它world->getDebugDrawer->setDebugMode(debugMode);

为了吸引世界,请致电world->debugDrawWorld();

然后drawLine,这将多次调用您的自定义函数,直到绘制出物理世界的线框模型.