C++ 为什么边界框不是';在这个网格中设置不正确吗?
我有一些Irrlicht代码,可以生成给定宽度和高度的矩形网格。以下是生成顶点和索引的代码:C++ 为什么边界框不是';在这个网格中设置不正确吗?,c++,bounding-box,irrlicht,C++,Bounding Box,Irrlicht,我有一些Irrlicht代码,可以生成给定宽度和高度的矩形网格。以下是生成顶点和索引的代码: 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&
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;
}
}
但是,渲染时,边界框的大小与正确的大小相差甚远:
这样做的最终结果是,当小边界框位于摄影机后面时,网格不会被渲染。结果表明,问题在于我调用了
重新计算边界框()
在缓冲区上而不是网格上。如何计算宽度
和高度
?@casablanca:它只是作为参数传入的。在这种情况下,[25x10]。
SMeshBuffer * buffer = new SMeshBuffer();
buffer->append(vertices,iNumVertices,indices,iNumIndices);
buffer->recalculateBoundingBox();