C++ (Ogre3d/PhysX/C+;+;)-如何进行绘图调试可视化

C++ (Ogre3d/PhysX/C+;+;)-如何进行绘图调试可视化,c++,ogre3d,physx,C++,Ogre3d,Physx,你能帮我吗。我无法理解如何在Ogre3D中绘制PhysX调试可视化以及普通对象 我有OpenGL的代码,但无法将其转换为Ogre3d: void RenderData(const PxRenderBuffer & data) { glLineWidth(1.0f); glDisable(GL_LIGHTING); //----------Render Points------------------ unsigned int NbPoints = dat

你能帮我吗。我无法理解如何在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);
}
void RenderData(常量PxRenderBuffer&data)
{
glLineWidth(1.0f);
glDisable(GLU照明);
//----------渲染点------------------
unsigned int NbPoints=data.getNbPoints();
若有(NB点)
{
浮动*pVertList=新浮动[NbPoints*3];
float*pColorList=新的float[NbPoints*4];
int vertIndex=0;
int colorIndex=0;
const PxDebugPoint*Points=data.getPoints();
而(NbPoints--)
{
pVertList[vertIndex++]=点->位置x;
pVertList[vertIndex++]=点->位置y;
pVertList[vertIndex++]=点->位置z;
pColorList[colorIndex++]=(浮点)(点->颜色>>16)和0xff)/255.0f;
pColorList[colorIndex++]=(浮点)(点->颜色>>8)和0xff)/255.0f;
pColorList[colorIndex++]=(浮点)(点->颜色&0xff)/255.0f;
pColorList[colorIndex++]=1.0f;
积分++;
}
RenderBuffer(pVertList、pColorList、GL_POINTS、data.getNbPoints());
删除[]pVertList;
删除[]pColorList;
}
//----------渲染线------------------
unsigned int NbLines=data.getNbLines();
如果(NbLines)
{
float*pVertList=新的float[NbLines*3*2];
float*pColorList=新的float[NbLines*4*2];
int vertIndex=0;
int colorIndex=0;
const PxDebugLine*Lines=data.getLines();
而(n行--)
{
pVertList[vertIndex++]=行->pos0.x;
pVertList[vertIndex++]=行->pos0.y;
pVertList[vertIndex++]=行->pos0.z;
pColorList[colorIndex++]=(float)((线条->颜色0>>16)和0xff)/255.0f;
pColorList[colorIndex++]=(float)((线条->颜色0>>8)和0xff)/255.0f;
pColorList[colorIndex++]=(float)(行->color0&0xff)/255.0f;
pColorList[colorIndex++]=1.0f;
pVertList[vertIndex++]=行->pos1.x;
pVertList[vertIndex++]=行->pos1.y;
pVertList[vertIndex++]=行->pos1.z;
pColorList[colorIndex++]=(float)((线条->颜色0>>16)和0xff)/255.0f;
pColorList[colorIndex++]=(float)((线条->颜色0>>8)和0xff)/255.0f;
pColorList[colorIndex++]=(float)(行->color0&0xff)/255.0f;
pColorList[colorIndex++]=1.0f;
行++;
}
RenderBuffer(pVertList、pColorList、GL_行、data.getNbLines()*2);
删除[]pVertList;
删除[]pColorList;
}
//----------渲染三角形------------------
unsigned int NbTris=data.getNbTriangles();
如果(NbTris)
{
float*pVertList=新的float[NbTris*3*3];
float*pColorList=新的float[NbTris*4*3];
int vertIndex=0;
int colorIndex=0;
const PxDebugTriangle*Triangles=data.getTriangles();
而(NbTris--)
{
pVertList[vertIndex++]=三角形->pos0.x;
pVertList[vertIndex++]=三角形->位置0.y;
pVertList[vertIndex++]=三角形->位置0.z;
pVertList[vertIndex++]=三角形->位置1.x;
pVertList[vertIndex++]=三角形->位置1.y;
pVertList[vertIndex++]=三角形->位置1.z;
pVertList[vertIndex++]=三角形->pos2.x;
pVertList[vertIndex++]=三角形->位置2.y;
pVertList[vertIndex++]=三角形->pos2.z;
对于(int i=0;icolor0>>16)&0xff)/255.0f;
pColorList[colorIndex++]=(float)((三角形->彩色0>>8)和0xff)/255.0f;
pColorList[colorIndex++]=(float)(三角形->color0&0xff)/255.0f;
pColorList[colorIndex++]=1.0f;
}
三角形++;
}
RenderBuffer(pVertList、pColorList、GL_三角形、data.getNbTriangles()*3);
删除[]pVertList;
删除[]pColorList;
}
glEnable(德国劳埃德大学照明);
glColor4f(1.0f、1.0f、1.0f、1.0f);
}
void RenderBuffer(float*pVertList,float*pColorList,int-type,int-num)
{
glEnableClientState(GL_顶点_数组);
glVertexPointer(3,GL_FLOAT,0,pVertList);
glEnableClientState(GL_颜色_阵列);
glColorPointer(4,GL_FLOAT,0,pColorList);
gldrawArray(类型,0,num);
glDisableClientState(GL_颜色_数组);
glDisableClientState(GL_顶点_数组);
}

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

看看名为“NxOgre”的Ogre3D PhysX包装器(与Critter结合,后者是通往Ogre3D的真正桥梁)是如何工作的。一个很好的起点是

大致轮廓: 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();
}
最相关的部分:

  • =从PhysX收集数据,并存储在结构中,以传递给Ogre3D渲染器
  • =先前存储的数据被传递到Ogre3D顶点缓冲区