此函数用于生成GeoMipMap地形算法的索引Buffer,可以生成一个由参数指定的特定Patch的所引数据,生成的几何体为三角形条带,生成三角形中有部分退化三角形,用于三角形条带的连接。生成的三角形是CCW或者CW一致的。
pIndex :指向索引Buffer当前填充位置
wWidth :Patch的大小,取值范围9,17,33......
wLevel :Lod级别,取值范围0,1,2,3......,数字越小细节级越高,0为最高细节级
bUp,bDown,bLeft,bRight:上下左右四个方向是否连接低细节级Patch
返回值 :返回填充的索引数据个数,由于生成的是三角形条带,实际生成的三角形数目为返回值减2
int GenerateStripIndex(WORD* pIndex, WORD wWidth, WORD wLevel,
bool bUp,
bool bDown,
bool bLeft,
bool bRight)
{
WORD i, j;
WORD w1, w2;
WORD wPower = 1;
![](https://i-blog.csdnimg.cn/blog_migrate/587e34b10dcf5efbc0859b53470a2db3.gif)
for( i=0; i<wLevel; i++ )
wPower *= 2;
![](https://i-blog.csdnimg.cn/blog_migrate/587e34b10dcf5efbc0859b53470a2db3.gif)
WORD wGridWdith = (wWidth - 1) / wPower;
WORD wPitch = wGridWdith * 2 + 4;
WORD *p = pIndex;
w1 = 0;
![](https://i-blog.csdnimg.cn/blog_migrate/587e34b10dcf5efbc0859b53470a2db3.gif)
for( j=0; j < wGridWdith / 2; j++ )
![](https://i-blog.csdnimg.cn/blog_migrate/3112b7b6526db5bc83e275260ae60525.gif)
{
w2 = w1 + wWidth * wPower;
for( i=0; i < wGridWdith; i++)
![](https://i-blog.csdnimg.cn/blog_migrate/3112b7b6526db5bc83e275260ae60525.gif)
{
*p++ = w1;
*p++ = w2;
w1 += wPower;
w2 += wPower;
}
*p++ = w1;
*p++ = w2, *p++ = w2, *p++ = w2;
![](https://i-blog.csdnimg.cn/blog_migrate/587e34b10dcf5efbc0859b53470a2db3.gif)
w1 = w2 + wWidth * wPower;
for( i=0; i < wGridWdith; i++)
![](https://i-blog.csdnimg.cn/blog_migrate/3112b7b6526db5bc83e275260ae60525.gif)
{
*p++ = w1;
*p++ = w2;
w1 -= wPower;
w2 -= wPower;
}
*p++ = w1;
*p++ = w2, *p++ = w1, *p++ = w1;
}
![](https://i-blog.csdnimg.cn/blog_migrate/587e34b10dcf5efbc0859b53470a2db3.gif)
if( bDown )
![](https://i-blog.csdnimg.cn/blog_migrate/3112b7b6526db5bc83e275260ae60525.gif)
{
p = pIndex + 2;
for( i=0; i<wGridWdith / 2; i++)
![](https://i-blog.csdnimg.cn/blog_migrate/3112b7b6526db5bc83e275260ae60525.gif)
{
(*p) -= wPower;
p += 4;
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/587e34b10dcf5efbc0859b53470a2db3.gif)
if( bUp )
![](https://i-blog.csdnimg.cn/blog_migrate/3112b7b6526db5bc83e275260ae60525.gif)
{
p = pIndex + wPitch * (wGridWdith - 1) + 2;
for( i=0; i<wGridWdith / 2; i++)
![](https://i-blog.csdnimg.cn/blog_migrate/3112b7b6526db5bc83e275260ae60525.gif)
{
(*p) += wPower;
p += 4;
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/587e34b10dcf5efbc0859b53470a2db3.gif)
if( bRight )
![](https://i-blog.csdnimg.cn/blog_migrate/3112b7b6526db5bc83e275260ae60525.gif)
{
for( i=0; i<wGridWdith / 2; i++)
![](https://i-blog.csdnimg.cn/blog_migrate/3112b7b6526db5bc83e275260ae60525.gif)
{
p = pIndex + wPitch * 2 * i + wPitch - 3;
p[0] += wWidth * wPower;
p[1] += wWidth * wPower;
p[2] += wWidth * wPower;
p[4] += wWidth * wPower;
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/587e34b10dcf5efbc0859b53470a2db3.gif)
if( bLeft )
![](https://i-blog.csdnimg.cn/blog_migrate/3112b7b6526db5bc83e275260ae60525.gif)
{
for( i=0; i<wGridWdith / 2; i++)
![](https://i-blog.csdnimg.cn/blog_migrate/3112b7b6526db5bc83e275260ae60525.gif)
{
p = pIndex + wPitch * 2 * i;
p[1] = p[0];
p[wPitch * 2 - 3] -= wWidth * wPower;
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/587e34b10dcf5efbc0859b53470a2db3.gif)
return (wGridWdith * 2 + 4) * wGridWdith - 2;
}