从TRI列表到TRI带的高度图的DirectX顶点
DirectX vertices for heightmap from tri list to tri strip
我有一个在高度图中加载的程序,然后使用三角形列表方法将顶点分组到数组中,我的问题是我如何将其更改为三角形条?我希望它是一条条,所以第一行将向左到右,第二行向左到左等。使用循环进行此操作。
到目前为止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
}
}
*代码未经测试
相关文章:
- 如何循环打印顶点结构
- D3D11-将混合权重和索引传递到顶点着色器
- 从返回的顶点缓冲区查询顶点结构
- Vulkan 中的动态顶点缓冲区格式设置
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 如何将一半传递给顶点着色器?
- 在 DirectX 11 中从 GPU 读回顶点缓冲区(并获取顶点)
- QT QOpenGLWidget:如何在不使用数据块复制的情况下修改VBO中的单个顶点值?
- 使用 OpenGL 4.5 更改所选顶点的颜色
- Direct3D 11 - HLSL - 获取顶点索引 ID
- 创建异构顶点数据数组的可移植方法
- 使用 glvertex4i 传递网格面索引时的顶点着色器错误
- 无法从 cso 文件创建顶点着色器(从 fx 文件创建)
- OpenGL 相机移动程序顶点着色器问题
- 使用 std::list 存储顶点并使用 SFML 绘制它们
- 为什么顶点数组对象会导致错误?
- 从 CGAL 3D 网格生成中获取顶点坐标的 -6.27744e+66:mesh_implicit_sphere示例
- 将顶点位置从顶点传递到片段着色器 - 仅在使用 Nsight 进行调试时有效
- FBX SDK 在预期 3 个顶点时返回 4 个顶点
- 从TRI列表到TRI带的高度图的DirectX顶点