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)
但你不能抓住一个索引列表来按特定顺序绘制顶点!
| 归档时间: |
|
| 查看次数: |
5171 次 |
| 最近记录: |