For my final project I created a program that can take an image of a Digital Elevation Model (DEM) and generate a terrain using the image. I also created a simple physics engine that detects collisions with meshes and simulates balls bouncing.
The scene contains a square terrain mesh surrounded by walls.
The terrain box can be rotated with the 'A' and 'D' keys and raised and lowered with the 'Q' and 'E' keys.
The camera can be controlled using the 'W' and 'S' keys to move it foraward and backward along the z-axis, tilted up and down by scrolling up or down with the mouse and turned left and right by scrolling left or right.
|
The terrain box can toggle between 4 differrent generated terrains (plus a flat plane) on the fly using the 'R' key.
To generate a terrain, the program reads in an image file then maps the x and z coordinate of each vertex stored in the mesh to a pixel of the image and gets the color value of that pixel. The program then updates the vertex's y value to a new height value using that color. Then once all vertices are updated, the normals of each vertex are recalculated to match the new mesh.
These are the four DEM images used to generate the terrains.
|
My program uses a Blinn-Phong lighting model to light the scene. The light can be moved around using the 'I' and 'K' keys for forward and backward, the 'J' and 'L' keys for left and right, and the 'U' and 'O' keys for up and down.
Lastly my program implements a simple physics engine that can calculate collisions with meshes and simulates the motion of a bouncy ball.
Balls can be spawned with the 'R' key. The size of the ball spawned can be increased or decreased with the '1' and '2' keys. Likewise the 'bounciness' of the ball can be increased or decreased with the '3' and '4' keys.
The balls only detect collision with the terrain and are confined to the area above the terrain. Collisions are detected using 'collision spheres' by checking the distance from the center point of the physics object to each face of the terrain mesh and comparing that distance to the physics object's radius.