0

我正在尝试加载高度图数据,但我正在努力弄清楚如何计算出法线。上网查了一下,好像没找到有用的。

我使用存储顶点

m_HeightMapVtxCount = (m_HeightMapLength - 1) * m_HeightMapWidth * 2;
m_pVertices = new XMFLOAT3[m_HeightMapVtxCount];

然后使用加载顶点

for (int l = 0; l < m_HeightMapLength - 1; ++l)
    {
        if(l % 2 == 0)  //for every second row - start at the bottom left corner, continue to the right, one row up and continue to the left
        {
            for(int w = 0; w < m_HeightMapWidth; ++w)
            {
                m_pVertices[i++] = XMFLOAT3(m_pHeightMap[w + l * m_HeightMapWidth]);        //bottom vertex
                m_pVertices[i++] = XMFLOAT3(m_pHeightMap[w + (l + 1) * m_HeightMapWidth]);  //top vertex
            }
        }
        else //for the row above, add the vertices from right to left
        {
            for(int w = m_HeightMapWidth - 1; w >= 0; --w)
            {
                m_pVertices[i++] = XMFLOAT3(m_pHeightMap[w + l * m_HeightMapWidth]);        //bottom vertex
                m_pVertices[i++] = XMFLOAT3(m_pHeightMap[w + (l + 1) * m_HeightMapWidth]);  //top vertex
            }
        }
    }

我能够使用三角形列表计算法线,这很简单,但不确定如何使用条带

4

0 回答 0