Game Development Reference
In-Depth Information
void InsertRoadVertices (vector<vector<Edge2 >>& roads,
set<Vertex2>& vertices)
{
for (int r = 0; r < roads.size(); ++r) {
const vector<Edge2 >& edges = roads[r];
for (int e = 0; e < edges.size(); ++e) {
vertices.insert(edges[e].GetVertex(0));
vertices.insert(edges[e].GetVertex(1));
}
}
}
Listing 10.1. The road vertices are always in the triangle mesh.
void InitialHeightVertices (int hxSize, int hySize,
int dx, int dy, set<Vertex2>& vertices)
{
for (int y = 0; y < hySize; y += dy) {
for (int x = 0; x < hxSize; x += dx) {
vertices.insert(Vertex2(x,y));
}
vertices.insert(Vertex2(hxSize-1,y));
}
for (int x = 0; x < hxSize; x += dx) {
vertices.insert(Vertex2(x,hySize-1));
}
vertices.insert(Vertex2(hxSize-1,hySize-1));
}
Listing 10.2. Initial vertex selection for the height field.
to guarantee that the final terrain mesh has some uniformity to it and that the
xy
-domain is rectangular.
10.2.2 Adaptive Quadtree Decomposition
The vertex selection for the terrain is based on an adaptive quadtree decomposition
in order to preserve the shape of the terrain as much as possible. The idea is easily
illustrated in the one-dimensional setting, where the height field is the graph of a
function. Figure10.1 s howsadecompositionofthedomainofacurvetoobtainan
approximationthatpreservestheshapeofthecurve.
Figure10.1(a ) showsthedomainasasetoffourblocksofvertices,eachblock
containing five vertices with adjacent blocks sharing a vertex. A linear interpola-
Search WWH ::




Custom Search