Game Development Reference
In-Depth Information
•
For the UV map, if we apply a texture to this geometry, we should have a
texture coordinate per vertex.
•
To generate vertices, we also need the width and height of the plane. Hence,
to generate the information to render the geometry shown in the preceding
diagram, we need the following:
° Plane width
° Plane height
° Width segments
° Height segments
Terrain is one of the most important components for most
games. The plane geometry computation logic is a very
standard algorithm that is implemented in most WebGL
libraries, and we have covered its implementation to
understand the topic height maps better.
• Also, for our formulas to generate the vertex information from the preceding
data, we assume that the plane is placed at the world center and lies in the
XY plane (
z
= 0). The preceding diagram also shows that for
n
segments, we
have
n
+ 1 vertices on each side and we certainly want our number of vertices
to be even and in the power of 2.
• Let's start with our first formula to generate vertices. Let's say that if the
plane is a grid of 4 x 4 vertices and each side's width and height is 16 units
and the image center is (0, 0), then the coordinates for vertices are shown in
the following table:
Vertices
Coordinates
(0, 0)
(-32, 32, 0)
These coordinates are calculated as (-32 + 64 * 0/3,
32 - 64 * 0/3, 0)
(1,0)
(-32 + 64/3, 32, 0)
(2, 0)
(-32 + 64 * 2/3, 32, 0)
(3, 0)
(-32 + 64 * 3/3, 32, 0)
(0, 1)
(-32 + 64 * 0/3, 32 - 64/3, 0)
(1, 1)
(-32 + 64 * 1/3, 32 - 64/3, 0)
(2, 1)
(-32 + 64 * 2/3, 32 - 64/3, 0)
(3, 1)
(-32 + 64 * 3/3, 32 - 64/3, 0)
(0, 2)
(-32 + 64 * 0/3, 32 - 64 * 2/3, 0)