Game Development Reference
In-Depth Information
void ProcessTiles (const set<Vertex2>& vertices,
const vector<vector<Vertex2>>& tiles,
vector<Vertex2>& terrVertices , vector<int>& terrIndices ,
vector<int>& terrAdjacencies)
{
map<Vertex2,int> vtxMap;
CreateVertexMap(vertices,vtxMap,terrVertices);
for (i = 0; i < tiles.size(); ++i) {
Triangulate(tiles[i],vtxMap,terrIndices ,terrAdjacencies);
}
Stitch(terrVertices ,terrIndices,terrAdjacencies);
}
Listing 10.6. High-level processing of tiles.
adjacent to edge
a 0 be its (nonnegative) triangle index. If
there is no neighbor to this edge, the convention is to set
3
t
+0
,
3
t
+1
,thenlet
a 0 =
1. Similarly,
a 1 is
the triangle index associated with a neighbor of edge
3
t
+1
,
3
t
+2
and
a 2 is the
triangle index associated with a neighbor of edge
.
In Listing 10.6, the vertex map vtxMap stores a unique index per vertex, and
the unique vertices themselves are copied in order to terrVertices . Listing 10.7
is the simple pseudocode for this process.
The Delaunay triangulation is encapsulated by Triangulate , as shown in List-
ing 10.8. This function also has the responsibility for updating the index and
adjacency arrays for the terrain. The pseudocode assumes the existence of a class
Delaunay2 that implements incremental Delaunay triangulation and that allows
you to read back the indices and adjacencies. The block of code at the end of
the function remaps the triangle indices to use the unique vertex indexing and to
3
t
+2
,
3
t
+0
void CreateVertexMap (const set<Vertex2>& vertices,
map<Vertex2,int>& vtxMap, vector<Vertex2>& terrVertices)
{
terrVertices.resize(vertices.size());
set<Vertex2>::iterator iter = vertices.begin();
set<Vertex2>::iterator end = vertices.end();
for (int i = 0;; iter != end; ++iter++, ++i) {
terrVertices[i] = *iter;
vtxMap[*iter] = i;
}
}
Listing 10.7. Creating the vertex map.
Search WWH ::




Custom Search