开发者

How come the bounding box isn't being set properly in this mesh?

I have some Irrlicht code that generates a rectangular mesh given a width and height. Here is the code that generates the vertices and indices:

int iNumVertices = (width + 1) * (height + 1);
S3DVertex * vertices = new S3DVertex[iNumVertices];
memset(vertices,0,sizeof(S3DVertex) * iNumVertices);

for(int i=0;i<=height;++i)
{
  开发者_运维百科  for(int j=0;j<=width;++j)
    {
        int iIndex = (i*(width + 1)) + j;

        vertices[iIndex].Pos.X = i * 2.0f;
        vertices[iIndex].Pos.Y = 0.0f;
        vertices[iIndex].Pos.Z = j * 2.0f;
        vertices[iIndex].Color.color = 0xFFFFFFFF;

        vertices[iIndex].TCoords.X = i;
        vertices[iIndex].TCoords.Y = j;
    }
}

int iNumIndices = 6 * width * height;
u16 * indices = new u16[iNumIndices];

for(int i=0;i<height;++i)
{
    for(int j=0;j<width;++j)
    {
        int iIndex = ((i*width) + j) * 6;

        int tmp_offset = j + (i * (width + 1));

        indices[iIndex + 0] = tmp_offset + 1;
        indices[iIndex + 1] = tmp_offset + width + 1;
        indices[iIndex + 2] = tmp_offset;
        indices[iIndex + 3] = tmp_offset + 1;
        indices[iIndex + 4] = tmp_offset + width + 2;
        indices[iIndex + 5] = tmp_offset + width + 1;
    }
}

Then the vertices and indices are added to the mesh and the bounding box is recalculated:

SMeshBuffer * buffer = new SMeshBuffer();
buffer->append(vertices,iNumVertices,indices,iNumIndices);

buffer->recalculateBoundingBox();

However, when rendered, the bounding box is nowhere close to the right size:

How come the bounding box isn't being set properly in this mesh?

The end result of this is that the mesh doesn't get rendered when the small bounding box goes behind the camera.


Turns out that the problem was that I was calling recalculateBoundingBox() on the buffer instead of the mesh.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜