Game Development Reference
In-Depth Information
void CreateTerrain (int hxSize, int hySize, int** heights,
int dx, int dy, int vertexBudget ,
const vector<vector<Edge2 >>& roads,
vector<Vertex2>& terrVertices , vector<int>& terrIndices ,
vector<int>& terrAdjacencies)
{
set<Vertex2> vertices;
vector<vector<Vertex2>> tiles;
InsertRoads(roads,vertices);
InitialHeightVertices(hxSize,hySize,dx,dy,vertices);
AdaptiveQuadtreeDecomposition(hxSize,hySize,heights,dx,dy,
vertexBudget ,vertices);
PartitionVertices(vertices,hxSize,hySize,tiles);
ProcessTiles(vertices,tiles,terrVertices ,terrIndices,
terrAdjacencies);
}
Listing 10.10. Top-level call for decimation and triangulation to produce the terrain
mesh.
append the triangle indices into a single-index array. It also adjusts the adjacency
information to use the new triangle indexing.
The stitching of the triangulations of the tiles is shown in Listing 10.9. The tiles
are stitched by storing the shared edges and the triangle sharing them, followed by
a lot of typical mesh bookkeeping. The top-level summary of the algorithm is
Listing 10.10.
10.3 Processing the Lofted Roads
After the terrain is generated by the function CreateTerrain , the edges of the
road need to be inserted into the triangulation. The algorithm uses a constrained
Delaunay triangulation. Because we have already generated a Delaunay triangu-
lation that includes the road-edge vertices, all we need to do now is modify the
triangulation one edge at a time.
10.3.1 Inserting Edges into the Triangulation
Thebasicideaforinsertingedgesisillustratedin Figure10.3 . Theroadedge
to be inserted is
V 1 are vertices that were included in the
Delaunay triangulation. The common case is that a unique triangle strip connects
V 0 to
V 0 ,V 1
,where
V 0 and
V 1 , where each triangle of the strip is intersected by the road edge, and each
such intersection is an interior point of a triangle edge.
Search WWH ::




Custom Search