四邊形密鋪平面

任意四邊形能夠密鋪整個二維平面,這裏將給出其代碼實現.ui

void CTileQuadrangleGridDrawer::BuildTileQuadrangle(Vector3* v) { Vector2 vDis01 = m_quadPositions[0] - m_quadPositions[1]; Vector2 vDis32 = m_quadPositions[3] - m_quadPositions[2]; Vector2 vDis03 = m_quadPositions[0] - m_quadPositions[3]; Vector2 vDis12 = m_quadPositions[1] - m_quadPositions[2]; Vector2 vExtend = ((vDis01 + vDis32)*((float)m_uiCol) + (vDis03 + vDis12)*((float)m_uiRow))*0.5f; Vector2 vStart = -vExtend*0.5f; Vector2 vCurrentRow = vStart; Vector2 vCurrentCol; unsigned int index; for (unsigned int i = 0; i <= m_uiRow; i++) { vCurrentCol = vCurrentRow; for (Yuint j = 0; j <= m_uiCol; j++) { index = i*(m_uiCol + 1) + j; v[index].x = vCurrentCol.x; v[index].y = vCurrentCol.y; v[index].z = 0.0f; vCurrentCol += ((i+j)&1) ? vDis01 : vDis32; } vCurrentRow += (i&1) ? vDis03 : vDis12; } }

代碼中m_quadPositions表示四邊形的四個頂點.v爲計算輸出的頂點Mesh.spa

在窗體右下角有個四邊形,鼠標拖動四邊形的頂點,能夠改變四邊形的形狀,從而改變平鋪網格.3d

軟件下載地址:http://files.cnblogs.com/files/WhyEngine/TileQuadrangle.7zcode

這是個3D程序,鼠標右鍵的拖動能夠改變視角.
X用於恢復爲默認視角.
F11用於全屏切換.blog

相關文章
相關標籤/搜索