Surface Tessellation: Assignment #5
Due: Wednesday, December 10, 2003, 11:59pm
Overview
The task of this assignment is to create polygonal surface tessellations
of two different objects: fractals and spheres. You will use OpenGL
to render your surfaces. As in the ray tracing assignment, you will use
the CLI command language routines to read descriptions of these surfaces
from a file.
Provided Commands
The following standard matrix manipulation and viewing commands are
already provided in the example code:
-
fov angle
translate tx ty tz
scale sx sy sz
rotate angle ax ay az
lookat fx fy fz ax ay az ux uy uz
push
pop
Each of the above commands is implemented simply by calling
the appropriate OpenGL commands, such as glTranslate3f, gluLookAt, etc.
In addition to these standard transformation commands, you will also
need a few additional commands:
-
clear
-
This already-provided command clears the screen.
-
light x y z
-
This command specifies the location of the light source. It is actually
provided in the sample code.
-
color r g b
-
Specifies the ambient and diffuse color of a surface. We will use a very
simple lighting model for this project.
-
begin
vertex x y z
vertex x y z
...
end
-
The above commands describe a polygon. As usual, the current transformation
matrix transforms the polygon vertices. You should look at the code that
implements this command carefully because you will do something similar to
create polygons that tessellate the sphere. Pay particular attention
to the surface normals.
-
Commands You Will Write
The following commands are those that you will implement.
-
sphere x y z radius
-
This command should cause your program to create a sphere at the given
location and radius. You should NOT use the GLUT sphere command, but
instead create your own sphere out of polygons. You can do this in
any manner you wish-- latitude/longitude or subdivided icosahedrons
are two possibilities.
-
roughness first_offset scale_factor max_depth
-
This command specifies two parameters for the fractals that are specified
following this command. The "first_offset" parameter specifies the upper
bound on the range of height offsets for the y-axis vertical displacement of
the first midpoints. If "first_offset" is zero, created fractals will just
be flat triangles. The random values that you add in the vertical direction
should be in the range of [-first_offset, +first_offset], that is, your
random number ranges should be centered at zero. The "scale_factor"
specifies a multiplying factor (which should be less than one) with which to
multiply the current offset for the next midpoints in the recursive fractal
creation. The "max_depth" parameter (an integer) specifies how many levels
of triangle subdivision to perform. A "max_depth" value of zero will result
in no triangle subdivision.
-
seed int_value
-
This command allows you to specify an integer value that will be added
to each of the random number seeds that you use to create your fractals.
The default value of this seed should be zero, which means that your
fractals will look exactly the same each time you run your program. By
specifying a different seed, however, you can create fractals that take
on a variety of different looks.
-
fractal x1 y1 z1 x2 y2 z2 x3 y3 z3
-
This command specifies the (x,y,z) location for three vertices of a
triangle that will be subdivided to create a fractal. Use the standard
recursive midpoint subdivison that splits each triangle into four new
triangles.
-
The last component of this assignment is for you to create some form of
color variation for your fractal moutains. You are free to choose your
own method for varying the color of the polygons. One common method is
to use some function of the height to change the moutain colors, with
white at the peaks and greens and browns lower down. Feel free to use
some form of randomness to add variation to the colors if you wish.
Note that when a fractal is drawn, the color given in the "color"
command is ignored.
Your Own Scene
In order for you to show off your sphere and fractal routines together,
you should create your own .cli file that incorporates one or more
spheres together with a fractal landscape. This will be one of the
files that you should turn in with your assignment. You could have a
sphere act as a sun or moon, or have spheres scattered through the
landscape.
Provided Code and Suggestions
All of the code that we provide is in the directory ~turk/public/cs4451/prog5.
Alas, the current version is written for Unix, and you should modify it
as necessary to get it to work under Windows.
The example code is called "surfaces.c". Note that the provide makefile
links this code to the CLI routines, but it does *not* link to the
GLUT commands. You must create your sphere and fractal commands from
the polygon drawing commands glBegin(GL_POLYGON), glVertex3f(x,y,z),
and glEnd(). You will find that in order to properly light your spheres,
you must specify the surface normals using the command glNormal3f() either
before each vertex (for smoothly shaded sphere) or each set of vertices
that make up a triangle for your fractals.
To draw a fractal, you should be able to write a straightforward recursive
procedure that takes three vertex positions and the current "depth" of the
recursion and decides whether to draw a triangle or to split the triangle
into four smaller fractal triangles (the recursion). Try out the
files "frac.cli" and "islands.cli".
The trickiest part of this assignment is to seed the random number generator
correctly in order to prevent cracks in your fractal surface. You can use
the routine "rand()" to give you random values that you should then scale to
the appropriate range. The routine "srand(seed)" will allow you to seed
the random number generator based on the position of the two vertices of the
side on which you are determining the new midpoint. Use the (x,y,z)
coordinates of the edge midpoint to come up with a unique, large integer
with which to seed the random number generator. Call "srand()" with this
seed value before using "rand()" to come up with the random height. Note
that your fractal images will not look exactly the same as the example
images because you will use a different seed function. The overall visual
characteristics, however, should be the same.
Authorship Rules
The code that you turn in must be your own. You are allowed to talk to
other members of the class and to the instructor and the TA about general
implementation of the routines for the assignment. It is also fine to seek
the help of others for general programming and makefile questions. You
may not, however, use code that anyone other than yourself has written.
Code that is explicitly not allowed includes code taken from the Web, from
books, or from any source other than yourself. The only exception to this
rule is that you should feel free to use any of the routines that we
provide. You should not show your code to other students. If you need help
debugging, seek the help of the TA or of the instructor.