Bouncing Balls in a Dynamic Generated Terrain
Author: Eric Sunalp
Email: cyberplx@cats.ucsc.edu
CMPS161
Winter 2002
Example Movies
Click here for a link
to example movie 1
Click here for a link
to example movie 2
Description
This program has two parts, the terrain generator
and the ball-bouncing simulator. The user first starts by launching the
terrain generator. The user can either ask for a random terrain of a specified
size based on mathematical equations (like the one above) or the user can
generate a terrain from a grayscale image.
A Grayscale Image
Example Of The Terrain Generated
Once the terrain has been generated the user can launch
the simulator. The simulator will ask for a terrain file and then display
it in the main window. From there the user can place any amount of balls
above the terrain. The user can then start the animation and the balls
will start falling down and you can watch them interact with the complex
terrains.
Approach
I designed the terrain generator by outputting x
y z and values to a text file based on a mathematical equation. I also
added in the ability to convert grayscale images to complex terrain data.
Height values are determines based on their RGB value.
When the terrains are read in I first load the vertices
from the file and then create triangles for all the vertices in the grid.
The next step is to generate all the normal vectors for each triangle plan
in order to get the proper lighting in the scene. These normals are also
used later to determine the bounce direction of the balls.
When a ball is dropped it gains a constant velocity
due to gravity. A direction vector for each ball is also instantiated at
this time. The ball continues to fall, at every step checking to see if
it has collided with its complex terrain. The check is made by only looking
at neighboring triangles in the terrain and seeing if the ball is above
their depth values. Note that this includes the balls radius. Once the
ball collides with the terrain a calculation is made with the direction
vector of the ball and the normal vector of the triangle and the ball bounces
in the correct direction. Also note that important physics are implemented
such as reducing the balls velocity (energy) when it hits an object.
How to use terrain Generator
Launch with: "terrainGen -r 50 50 0.5 file"
-r
will use a random math function to generate the
terrain
50 50
will make a terrain 50 by 50
0.5
is the resolution and should be from 0 to 1
file
is the output file to save the generated terrain
or
Launch with: "terrainGen -I image 0.5 file"
-I
tells the program to use an image file to generate
the terrain.
Image
is the name of the image file. This should be of
type .sgi or .rgb
0.5
is
the resolution and should be from 0 to 1
file
is the output file to save the generated terrain
How to use the simulator
Launch the simulator by typing "final"
Once the app is launched you can type any of the
following command:
Escape
will quit the app
Q
will quit the app
L
will ask you for a terrain file to load in the terminal
R
will reset your view
Z
will cause the first mouse button to rotate the
world around the z axis
A
will ask you to add a new ball in the terminal
S
will start the animation and ask you for a time
step in the terminal
B
will reset the balls positions
You can also use the mouse to orient the world
LEFT BUTTON
will rotate the world
MIDDLE BUTTON
will translate the world along the z axis
RIGHT BUTTON
will translate the world along the x and y axis
More Images