从TRI列表到TRI带的高度图的DirectX顶点

DirectX vertices for heightmap from tri list to tri strip

本文关键字:TRI 顶点 高度 DirectX 列表      更新时间:2023-10-16

我有一个在高度图中加载的程序,然后使用三角形列表方法将顶点分组到数组中,我的问题是我如何将其更改为三角形条?我希望它是一条条,所以第一行将向左到右,第二行向左到左等。使用循环进行此操作。

到目前为止
for( int l = 0; l < m_HeightMapLength; ++l )
{
    for( int w = 0; w < m_HeightMapWidth; ++w )
    {   
        if( w < m_HeightMapWidth-1 && l < m_HeightMapLength-1 )
        {
            /*v0 = m_pHeightMap[mapIndex];
            v1 = m_pHeightMap[mapIndex+m_HeightMapWidth];
            v2 = m_pHeightMap[mapIndex+1];
            v3 = m_pHeightMap[mapIndex+m_HeightMapWidth+1];
            D3DXVECTOR3 vA = v0 - v1;
            D3DXVECTOR3 vB = v1 - v2;
            D3DXVECTOR3 vC = v3 - v1;
            D3DXVECTOR3 vN1;
            D3DXVec3Cross(&vN1, &vA, &vB);
            D3DXVECTOR3 vN2;
            D3DXVec3Cross(&vN2, &vB, &vC);*/
            //D3DXVec3Normalize( &vN1, &vN1);
            //D3DXVec3Normalize( &vN2, &vN2);
            //T Left, Bot Left, T Right, T Right, Bot Left, Bot Right
            //m_pMapVtxs[i++] = Vertex_Pos3fColour4ubNormal3f(D3DXVECTOR3( m_pHeightMap[mapIndex].x, m_pHeightMap[mapIndex].y,  m_pHeightMap[mapIndex].z), MAP_COLOUR, D3DXVECTOR3(vN1.x, vN1.y, vN1.z));
            //m_pMapVtxs[i++] = Vertex_Pos3fColour4ubNormal3f(D3DXVECTOR3( m_pHeightMap[mapIndex + m_HeightMapWidth].x, m_pHeightMap[mapIndex + m_HeightMapWidth].y,  m_pHeightMap[mapIndex + m_HeightMapWidth].z), MAP_COLOUR, D3DXVECTOR3(vN1.x, vN1.y, vN1.z));
            //m_pMapVtxs[i++] = Vertex_Pos3fColour4ubNormal3f(D3DXVECTOR3( m_pHeightMap[mapIndex+1].x, m_pHeightMap[mapIndex+1].y,  m_pHeightMap[mapIndex+1].z), MAP_COLOUR, D3DXVECTOR3(vN1.x, vN1.y, vN1.z));
            //m_pMapVtxs[i++] = Vertex_Pos3fColour4ubNormal3f(D3DXVECTOR3( m_pHeightMap[mapIndex+1].x, m_pHeightMap[mapIndex+1].y,  m_pHeightMap[mapIndex+1].z), MAP_COLOUR, D3DXVECTOR3(vN2.x,  vN2.y, vN2.z));
            //m_pMapVtxs[i++] = Vertex_Pos3fColour4ubNormal3f(D3DXVECTOR3( m_pHeightMap[mapIndex + m_HeightMapWidth].x, m_pHeightMap[mapIndex + m_HeightMapWidth].y,  m_pHeightMap[mapIndex + m_HeightMapWidth].z), MAP_COLOUR, D3DXVECTOR3(vN2.x,  vN2.y, vN2.z));
            //m_pMapVtxs[i++] = Vertex_Pos3fColour4ubNormal3f(D3DXVECTOR3( m_pHeightMap[mapIndex + m_HeightMapWidth+1].x, m_pHeightMap[mapIndex + m_HeightMapWidth+1].y,  m_pHeightMap[mapIndex + m_HeightMapWidth+1].z), MAP_COLOUR, D3DXVECTOR3(vN2.x,  vN2.y, vN2.z));

mapIndex ;

for循环是我将其更改为剥离的主要问题,我已经在纸上绘制了顶点,所以这是我的主要问题,任何洞察力都非常感谢。

我假设m_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
}

这适用于每一行。最后一个顶点将是该行的右上顶点。在那里,我们必须添加一个退化的三角形。这是一个三角形的区域0,将导致行分开。所以:

add m_pHeightMap[m_HeightMapWidth + m_HeightMapWidth - 1]; //once again the last 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
    }
}

*代码未经测试