Game Development Reference
In-Depth Information
The height map is not the same size as the terrain; however, we can always map
a coordinate of the terrain to the height map:
x coordinate on the height map = width HM/width Terrain * x value terrain
y coordinate on the height map = height HM/height Terrain * y value terrain
After we get the corresponding coordinate on the height map, we can calculate the
height at a location by retrieving the color value on the coordinate and multiplying it
with the maximum height difference of the terrain:
Height at a coordinate = min_height + (color value / (max_color - min_color)) *
(max_height-min_height)
So, you can modify the modifyGeometry code to read the height map and return the
z value for a particular segment.
Summary
Realistic games are impossible to create without physics engines. This chapter
introduced you to the most exciting areas in game development using WebGL and
physics. We started our journey by creating terrain geometry and finished it by
making the geometry an active physics static rigid body. We also covered how a
physics engine is decoupled from the rendering code and demonstrated how 3D
graphics objects are linked to the physics object. The concepts such as collisions,
forces, and impulse are in the core of each game.
We used JigLib as a reference library to implement physics in our game.
In the next chapter, we will introduce you to your enemy Mr. Green and animate his
body using bones and joints.
 
Search WWH ::




Custom Search