我尝试使用Directx9绘制地形。 我设置了顶点和索引,但是效果不佳。 某些多边形不可见,如这张图片。 为什么不绘制某些多边形?我该如何解决此问题。 请帮助我。
下面的代码是解锁后顶点和索引缓冲区的一部分。
MYINDEX结构包含每个单词类型的三个索引。
TERRAINVERTEX结构包含DXVECTOR3用于位置 和DXVECTOR2作为uv坐标。
TERRAINVERTEX v;
pv = (TERRAINVERTEX *)pVertices;
MYINDEX i;
pi = (MYINDEX*)pIndices;
int offSet = 0;
for (int z = 0; z < m_iCz-1; ++z)
{
for (int x = 0; x < m_iCx-1; ++x)
{
// left top
v.point.x = (float)((x - m_iCx / 2) * m_vfScale.x);
v.point.z = -(float)((z - m_iCz / 2) * m_vfScale.z);
v.point.y = 0.0f;
v.texture.x = 0;
v.texture.y = 0;
pi->i_0 = offSet++;
*pv++ = v;
//right top
v.point.x = (float)(((x+1 - m_iCx / 2) * m_vfScale.x));
v.point.z = -(float)((z - m_iCz / 2) * m_vfScale.z);
v.point.y = 0.0f;
v.texture.x = 1;
v.texture.y = 0;
pi->i_1 = offSet++;
*pv++ = v;
//left down
v.point.x = (float)(((x - m_iCx / 2) * m_vfScale.x));
v.point.z = -(float)((z + 1 - m_iCz / 2) * m_vfScale.z);
v.point.y = 0.0f;
v.texture.x = 0;
v.texture.y = 1;
pi->i_2 = offSet++;
*pv++ = v;
++pi;
//right down
v.point.x = (float)(((x + 1 - m_iCx / 2) * m_vfScale.x));
v.point.z = -(float)((z + 1 - m_iCz / 2) * m_vfScale.z);
v.point.y = 0.0f;
v.texture.x = 1;
v.texture.y = 1;
pi->i_0 = offSet++;
*pv++ = v;
//left down
v.point.x = (float)(((x + 1 - m_iCx / 2) * m_vfScale.x));
v.point.z = -(float)((z + 1 - m_iCz / 2) * m_vfScale.z);
v.point.y = 0.0f;
v.texture.x = 0;
v.texture.y = 1;
pi->i_1 = offSet++;
*pv++ = v;
//right top
v.point.x = (float)(((x + 1 - m_iCx / 2) * m_vfScale.x));
v.point.z = -(float)((z - m_iCz / 2) * m_vfScale.z);
v.point.y = 0.0f;
v.texture.x = 1;
v.texture.y = 0;
pi->i_2 = offSet++;
*pv++ = v;
++pi;
}
}