C++ 从tri列表到tri strip的高度贴图的DirectX顶点

C++ 从tri列表到tri strip的高度贴图的DirectX顶点,c++,directx,C++,Directx,我有一个程序可以加载到一个高度图中,然后我用三角形列表的方法将顶点排序到一个数组中,我的问题是如何将它改为三角形带?我希望它是一条带,所以第一行从左到右,第二行从右到左,等等,使用for循环 到目前为止,我的试用列表方法代码(没有显示高度贴图加载程序或顶点数定义,也显示法线计算器,但我不需要任何帮助): for(int l=0;l

我有一个程序可以加载到一个高度图中,然后我用三角形列表的方法将顶点排序到一个数组中,我的问题是如何将它改为三角形带?我希望它是一条带,所以第一行从左到右,第二行从右到左,等等,使用for循环

到目前为止,我的试用列表方法代码(没有显示高度贴图加载程序或顶点数定义,也显示法线计算器,但我不需要任何帮助):

for(int l=0;l
mapIndex++


for循环是我的主要问题,要将其更改为strip,我已经在纸上绘制了顶点,这是我的主要问题,任何见解都非常值得赞赏。

我假设
m\u pHeightMap
是一个3d向量

该条带将如下所示:

+--+--+--+--+
|/ |/ |/ |/ |
+--+--+--+--+
| \| \| \| \|
+--+--+--+--+
我们将从左下角开始,继续向右,然后向上一行,然后继续向左。但让我们先看看如何为单行定义条带:

for(int x = 0; i < m_HeightMapWidth; ++x)
{
    add m_pHeightMap[x + y * m_HeightMapWidth]; //bottom vertex
    add m_pHeightMap[x + (y + 1) * m_HeightMapWidth]; //top vertex
}
对于上面的行,我们从右向左添加顶点:

for(int x = m_HeightMapWidth - 1; i >= 0; --x)
{
    add m_pHeightMap[x + y * m_HeightMapWidth]; //bottom vertex
    add m_pHeightMap[x + (y + 1 ) * m_HeightMapWidth]; //top vertex
}
请注意,第一个顶点是我们已经添加了两次的顶点。第三次添加它将保留三角形的方向

我们对每一行都这样做。所以一起:

for(int y = 0; y < m_HeightMapHeight - 1; ++y)
{
    if(y % 2 == 0)
    {
        for(int x = 0; i < m_HeightMapWidth; ++x)
        {
            add m_pHeightMap[x + y * m_HeightMapWidth]; //bottom vertex
            add m_pHeightMap[x + (y + 1) * m_HeightMapWidth]; //top vertex
        }
        add m_pHeightMap[(y + 2) * m_HeightMapWidth - 1]; //once again the last vertex
    }
    else
    {
        for(int x = m_HeightMapWidth - 1; i >= 0; --x)
        {
            add m_pHeightMap[x + y * m_HeightMapWidth]; //bottom vertex
            add m_pHeightMap[x + (y + 1 ) * m_HeightMapWidth]; //top vertex
        }
        add m_pHeightMap[(y + 1) * m_HeightMapWidth]; //once again the last vertex
    }
}
for(int y=0;y=0;--x)
{
添加m_pHeightMap[x+y*m_HeightMapWidth];//底部顶点
添加m_pHeightMap[x+(y+1)*m_HeightMapWidth];//顶部顶点
}
添加m_pHeightMap[(y+1)*m_HeightMapWidth];//再次添加最后一个顶点
}
}

*该代码未经测试

,只需稍加调整即可基本正常工作,现在可以对法线进行排序。谢谢
for(int x = m_HeightMapWidth - 1; i >= 0; --x)
{
    add m_pHeightMap[x + y * m_HeightMapWidth]; //bottom vertex
    add m_pHeightMap[x + (y + 1 ) * m_HeightMapWidth]; //top vertex
}
for(int y = 0; y < m_HeightMapHeight - 1; ++y)
{
    if(y % 2 == 0)
    {
        for(int x = 0; i < m_HeightMapWidth; ++x)
        {
            add m_pHeightMap[x + y * m_HeightMapWidth]; //bottom vertex
            add m_pHeightMap[x + (y + 1) * m_HeightMapWidth]; //top vertex
        }
        add m_pHeightMap[(y + 2) * m_HeightMapWidth - 1]; //once again the last vertex
    }
    else
    {
        for(int x = m_HeightMapWidth - 1; i >= 0; --x)
        {
            add m_pHeightMap[x + y * m_HeightMapWidth]; //bottom vertex
            add m_pHeightMap[x + (y + 1 ) * m_HeightMapWidth]; //top vertex
        }
        add m_pHeightMap[(y + 1) * m_HeightMapWidth]; //once again the last vertex
    }
}