J'ai un code Irrlicht qui génère un maillage rectangulaire donné en largeur et en hauteur. Voici le code qui génère les sommets et indices:Comment se fait-il que la zone de délimitation ne soit pas définie correctement dans ce maillage?
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;
}
}
Ensuite, les sommets et les indices sont ajoutés à la maille et la boîte de sélection est recalculé:
SMeshBuffer * buffer = new SMeshBuffer();
buffer->append(vertices,iNumVertices,indices,iNumIndices);
buffer->recalculateBoundingBox();
Cependant, lorsqu'ils sont rendus, la zone de délimitation est nulle part près de la bonne taille:
le résultat final est que le maillage ne soit rendu pas lorsque le sma La boîte englobante passe derrière la caméra.
Comment calculez-vous 'width' et' height'? – casablanca
@casablanca: C'est juste passé en paramètre. Dans ce cas, [25x10]. –