You are to create an interactive program for drawing a Sierpinski tetrahedron using both a deterministic recursive function to define the tetrahedron and a three dimensional generalization of the Iterated Function System method given for the Sierpinski gasket in two dimensions in the example program gasket.c from Chapter 2 of the text. Your Sierpinski tetrahedron should be composed of 4 equilateral triangles of unit length sides and should be centered at the origin. By centered at the origin, I mean that the origin is equidistant from each of the tetrahedron's vertices.
You should assign colors to the vertices of the tetrahedron that make it easy to see its shape in three dimensions. For instance letting one vertex be red, another green, another blue, and the final one white, and interpolating colors among these would do the job, but this is not the only such scheme that you could use. Devise one that makes each vertex look distinct.
You should provide a user interface similar to that in the program cube.c from the text. That is, the tetrahedron should rotate about one of the principal coordinate axes. Which one depends on what mouse buttons have been clicked. In cube.c, the left mouse means rotate around the x axis, the middle button means rotate about the y axis, and the right button means rotate about the z axis (initially, the cube is rotating about the z axis). In your program, only the left and middle mouse buttons should affect rotation axes. The left mouse button will cause the rotation to go about the "next" axis, in the order x -> y -> z -> x, and the middle button will switch rotation to the "previous" axis in the same ordering. The right mouse button is reserved for menu operations. You should have a menu with commands to draw and IFS tetrahedron, draw a recursive tetrahedron, and quit. You should also have commands to double the number of IFS points drawn per frame, halve the number of IFS points drawn per frame, add one level to the recursive tetrahedron, and subtract one level from the recursive tetrahedron. When you execute the command to draw a particular type of tetrahedron, you should erase the old display and draw the new type at the current rotation angle, continuing in this mode until a new command is given. When you double or halve the number of IFS points, the resulting number of points per frame should be drawn until a further command is given. Likewise when you add or subtract a recursion level for the recursive tetrahedron, this level should be used in each frame drawn until a new command is given. Commands to change the number of IFS points while drawing recursive tetrahedra should have no effect. Likewise commands to change recursion level while drawing IFS tetrahedra.
You should always view the tetrahedron from a fixed point of view using perspective viewing. The viewpoint should be at (1,1,1) and you should be looking at the origin. Experiment with viewing frustum parameters until you get a view that nearly fills the screen and doesn't clip the tetrahedron.
You should draw the axes of the world coordinate system, and these should stay fixed while the tetrahedron rotates. You should draw everything using hidden surface removal. You should use fog to make the axes dimmer with distance, but do not affect the tetrahedron with the fog. You should use text to label the positive x, y and z axes.
You should undertake to implement this program in stages. Start with the example program gasket.c, and extend it to work in three dimensions as described in the book. Make sure you use the tetrahedron I prescribed above and not the one resulting from the book's parameters (the same algorithm works, you just need to use the right tetrahedron vertices). You can use orthographic viewing at this stage. Next, add rotation of the tetrahedron, using the scheme in cube.c, but drawing the tetrahedron instead of the cube in each frame. Then modify this to change the meanings of the mouse buttons, and add the basic menu controls for IFS drawing and to quit the program, referring to the code in paint.c Add the code to draw the axes and fog them, and convert the viewing parameters to perspective from orthographic viewing. Finally, devise a recursive program for drawing the tetrahedron, and add the menu controls to switch between this and the IFS tetrahedron. Once complete, you will have good familiarity with many of the basic features of 3-d programming in OpenGL.