
GDE::UINT32
CGround::GenerateIndices(GDE::UINT32** ppIndices)
{
GDE::UINT32 numTriangles = (kiWidth * 2) * (kiLength * 2);
GDE::UINT32 numIndices = numTriangles * 3;
*ppIndices = new GDE::UINT32[numIndices];
GDE::UINT32 index = 0;
GDE::UINT32 startVertex = 0;
for(int z = 0; z < kiLength; ++z)
{
for(int x = 0; x < kiWidth; ++x)
{
(*ppIndices)[index] = startVertex + 0;
(*ppIndices)[index + 1] = startVertex + 1;
(*ppIndices)[index + 2] = startVertex + 2;
index += 3;
(*ppIndices)[index] = startVertex + 1;
(*ppIndices)[index + 1] = startVertex + kiWidth + 1;
(*ppIndices)[index + 2] = startVertex + kiWidth;
index += 3;
++startVertex;
}
++startVertex;
}
return(startVertex);
}
void
CGround::GenerateVertices(SFVertex** ppVertices)
{
*ppVertices = new SFVertex[kiWidth * kiLength];
GDE::UINT32 count = 0;
FLOAT32 WorldZPos = 0.0f;
for(int z = 0; z < kiLength; ++z)
{
FLOAT32 WorldXPos = 0.0f;
for(int x = 0; x < kiWidth; ++x)
{
(*ppVertices)[count] = SFVertex(WorldXPos, 0.0f, WorldZPos, 0xFF000000);
++count;
WorldXPos += 8.0f;
}
WorldZPos += 8.0f;
}
}
貌似是indices的问题,Terrain会变成这样。。CGround::GenerateIndices(GDE::UINT32** ppIndices)
{
GDE::UINT32 numTriangles = (kiWidth * 2) * (kiLength * 2);
GDE::UINT32 numIndices = numTriangles * 3;
*ppIndices = new GDE::UINT32[numIndices];
GDE::UINT32 index = 0;
GDE::UINT32 startVertex = 0;
for(int z = 0; z < kiLength; ++z)
{
for(int x = 0; x < kiWidth; ++x)
{
(*ppIndices)[index] = startVertex + 0;
(*ppIndices)[index + 1] = startVertex + 1;
(*ppIndices)[index + 2] = startVertex + 2;
index += 3;
(*ppIndices)[index] = startVertex + 1;
(*ppIndices)[index + 1] = startVertex + kiWidth + 1;
(*ppIndices)[index + 2] = startVertex + kiWidth;
index += 3;
++startVertex;
}
++startVertex;
}
return(startVertex);
}
void
CGround::GenerateVertices(SFVertex** ppVertices)
{
*ppVertices = new SFVertex[kiWidth * kiLength];
GDE::UINT32 count = 0;
FLOAT32 WorldZPos = 0.0f;
for(int z = 0; z < kiLength; ++z)
{
FLOAT32 WorldXPos = 0.0f;
for(int x = 0; x < kiWidth; ++x)
{
(*ppVertices)[count] = SFVertex(WorldXPos, 0.0f, WorldZPos, 0xFF000000);
++count;
WorldXPos += 8.0f;
}
WorldZPos += 8.0f;
}
}
现在头晕的厉害,实在是想不出来了。
麻烦高人解答。这个是Dx的Vertex和index Buffer.
Triangle strip.
只有本站会员才能查看附件,请 登录
[ 本帖最后由 天蝎殿 于 2011-8-22 14:05 编辑 ]