gpt4 book ai didi

c++ - (Ogre3d/PhysX/C++) - 如何绘制调试可视化

转载 作者:行者123 更新时间:2023-11-28 06:44:09 27 4
gpt4 key购买 nike

你能帮帮我吗?我不明白如何在 Ogre3D 中与普通对象一起绘制 PhysX 调试可视化。

我有 OpenGL 的代码,但我不能将它转换为 Ogre3d:

void RenderData(const PxRenderBuffer & data)
{
glLineWidth(1.0f);
glDisable(GL_LIGHTING);

//----------Render Points------------------
unsigned int NbPoints = data.getNbPoints();
if(NbPoints)
{
float* pVertList = new float[NbPoints*3];
float* pColorList = new float[NbPoints*4];
int vertIndex = 0;
int colorIndex = 0;
const PxDebugPoint* Points = data.getPoints();
while(NbPoints--)
{
pVertList[vertIndex++] = Points->pos.x;
pVertList[vertIndex++] = Points->pos.y;
pVertList[vertIndex++] = Points->pos.z;
pColorList[colorIndex++] = (float)((Points->color>>16)&0xff)/255.0f;
pColorList[colorIndex++] = (float)((Points->color>>8)&0xff)/255.0f;
pColorList[colorIndex++] = (float)(Points->color&0xff)/255.0f;
pColorList[colorIndex++] = 1.0f;
Points++;
}

RenderBuffer(pVertList, pColorList, GL_POINTS, data.getNbPoints());

delete[] pVertList;
delete[] pColorList;
}


//----------Render Lines------------------
unsigned int NbLines = data.getNbLines();
if(NbLines)
{
float* pVertList = new float[NbLines*3*2];
float* pColorList = new float[NbLines*4*2];
int vertIndex = 0;
int colorIndex = 0;
const PxDebugLine* Lines = data.getLines();
while(NbLines--)
{
pVertList[vertIndex++] = Lines->pos0.x;
pVertList[vertIndex++] = Lines->pos0.y;
pVertList[vertIndex++] = Lines->pos0.z;
pColorList[colorIndex++] = (float)((Lines->color0>>16)&0xff)/255.0f;
pColorList[colorIndex++] = (float)((Lines->color0>>8)&0xff)/255.0f;
pColorList[colorIndex++] = (float)(Lines->color0&0xff)/255.0f;
pColorList[colorIndex++] = 1.0f;

pVertList[vertIndex++] = Lines->pos1.x;
pVertList[vertIndex++] = Lines->pos1.y;
pVertList[vertIndex++] = Lines->pos1.z;
pColorList[colorIndex++] = (float)((Lines->color0>>16)&0xff)/255.0f;
pColorList[colorIndex++] = (float)((Lines->color0>>8)&0xff)/255.0f;
pColorList[colorIndex++] = (float)(Lines->color0&0xff)/255.0f;
pColorList[colorIndex++] = 1.0f;

Lines++;
}

RenderBuffer(pVertList, pColorList, GL_LINES, data.getNbLines()*2);

delete[] pVertList;
delete[] pColorList;
}


//----------Render Triangles------------------
unsigned int NbTris = data.getNbTriangles();
if(NbTris)
{
float* pVertList = new float[NbTris*3*3];
float* pColorList = new float[NbTris*4*3];
int vertIndex = 0;
int colorIndex = 0;
const PxDebugTriangle* Triangles = data.getTriangles();
while(NbTris--)
{
pVertList[vertIndex++] = Triangles->pos0.x;
pVertList[vertIndex++] = Triangles->pos0.y;
pVertList[vertIndex++] = Triangles->pos0.z;

pVertList[vertIndex++] = Triangles->pos1.x;
pVertList[vertIndex++] = Triangles->pos1.y;
pVertList[vertIndex++] = Triangles->pos1.z;

pVertList[vertIndex++] = Triangles->pos2.x;
pVertList[vertIndex++] = Triangles->pos2.y;
pVertList[vertIndex++] = Triangles->pos2.z;

for(int i=0;i<3;i++)
{
pColorList[colorIndex++] = (float)((Triangles->color0>>16)&0xff)/255.0f;
pColorList[colorIndex++] = (float)((Triangles->color0>>8)&0xff)/255.0f;
pColorList[colorIndex++] = (float)(Triangles->color0&0xff)/255.0f;
pColorList[colorIndex++] = 1.0f;
}

Triangles++;
}

RenderBuffer(pVertList, pColorList, GL_TRIANGLES, data.getNbTriangles()*3);

delete[] pVertList;
delete[] pColorList;
}
glEnable(GL_LIGHTING);
glColor4f(1.0f,1.0f,1.0f,1.0f);
}

void RenderBuffer(float* pVertList, float* pColorList, int type, int num)
{
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT, 0, pVertList);

glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_FLOAT, 0, pColorList);

glDrawArrays(type, 0, num);

glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}

当然,您不能使用此代码。我只想绘制 PhysX 调试可视化。

最佳答案

看看名为“NxOgre”的 Ogre3D PhysX 包装器(结合 Critter,它是 Ogre3D 的实际桥梁)是如何工作的。一个好的起点是 wiki tutorial page .

大纲:PhsyX 为每个世界中的每个场景提供调试渲染数据结构。这可以被采用并形成一个数据结构,可以在 Ogre3D 中使用以进行渲染。

for (World::SceneIterator iterator = mWorld->getScenes(); iterator != iterator.end(); iterator++)
{
const NxDebugRenderable* renderable = iterator->getScene()->getDebugRenderable();
if (renderable == 0)
continue;

unsigned int nbLines = renderable->getNbLines();
const NxDebugLine* lines = renderable->getLines();

while(nbLines--)
{
mMeshData->mLines.push_back(lines->p0.x);
mMeshData->mLines.push_back(lines->p0.y);
mMeshData->mLines.push_back(lines->p0.z);
mMeshData->mLines.push_back(lines->p1.x);
mMeshData->mLines.push_back(lines->p1.y);
mMeshData->mLines.push_back(lines->p1.z);
mMeshData->mColours.push_back(lines->color);
mMeshData->mColours.push_back(lines->color);
lines++;
}

mMeshData->mNbLines += renderable->getNbLines();
}

最相关的部分:

关于c++ - (Ogre3d/PhysX/C++) - 如何绘制调试可视化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25344410/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com