Homework 4: Due Friday, October 3, 2003, 9AM (11/100 points)
Homework 4 Overview
In this project, we're trying to improve the 3D models we created in homework 3. In particular, we shall improve our homework 3 SDL castle program to include reading and rendering of meshes, and add more realism by doing elaborate shading, lighting and material properties. We will also begin to include flexible camera control and allow a user the ability to fly around our scenes and do clipping based on a 3D view volume.Important Note: At this point, you should be comfortable enough in miniGL to do any necessary extensions in any cases where the commands you need have not been included yet. So, it's your responsibility to extend miniGL where necessary. Do not try to type in straight openGL calls without using miniGL. The only exception (see below) is that you can use pure OpenGL calls from within SDL.cpp and SDL.h
- Preparation: A good place to start the homework is to make sure your homework 3 is working and reasonably clean as far as the design and the code. Also, you should read sections 6.1 and 6.2 of Hill on how to read polygonal meshes, in 3vn format. Also make sure that the miniGL examples (bounce, gears, etc) still work well. If there are any known shortcomings of your homework 3 models that you cannot fix, you should note these in your documentation so that you do not lose points for them.
.3vn files: The meshes you will render are in .3vn format. Here are a few .3vn files to work with.
basicBarn.3vn
bucky.3vn
cubes3.3vn
diamond.3vn
Dodeca.3vn
icosa.3vn
octa.3vn
pawn.3vn
Tetra.3vn
wineglass.3vn
- Add keystroke 'P' to your homework 3 program: Response draws a polygonal mesh scene: Create an SDL scene which uses at least 6 of the meshes given in the .3vn files. A basic scene could simply have these mesh models on a floor or table, but you can also get creative. The first time the user hits the 'P' key, the mesh scene is drawn using solid models. If the user hits the 'P' key again, the same mesh scene is redrawn using wireframe models. In summary, your 'P' key should have a toggle feature whereby repeatedly hitting the 'P' key toggles between your solid and wireframe models. The M and S keystrokes should still work as described in homework 3. Note that a mesh class is already implemented in SDL. However, only the solid mesh drawing function is implemented. YOu have to implement a very similar function in SDL for creating a wireframe drawing (i.e. the drawEdges( ) method in sdl.cpp). Hint: drawEdges is very similar to drawMesh( )
- SDL castle enhancement: Add 4 of the .3vn files above to your SDL castle ('S' keystroke). You should use your creativity to select which .3vn files you use and where you put them to enhance your castle.
- Lighting, colors, material properties and shading: Apply some interesting colors, lighting and shading to your SDL castle scene (keystroke S). Make sure you have at least 3 light sources and use interesting colors to make your scene interesting. Also use interesting material properties to bring your scenes to life. Note that SDL supports many more material properties than you can use for this project. Specifically, the ambient, diffuse, specular and emissive properties of materials are supported and you can pass these in your SDL .dat files. However, textures and material properties like speedOfLight, transparency and reflectivity are used in ray tracing and you should NOT try to set these.
- Flexible Camera Control: In this part of the project, we want to allow the user to move the camera and view our SDL castle scene from various points. The minimal controls/keystrokes are as follows:
"z": move camera 1 unit in the +ve z direction "Z": move camera 1 unit in the -ve z direction "y": move camera 1 unit in the +ve y direction "Y": move camera 1 unit in the -ve y direction "x": move camera 1 unit in the +ve x direction "X": move camera 1 unit in the -ve x direction "j": increase camera yaw by 2 degrees in the +ve direction "J": decrease camera yaw by 2 degrees in the -ve direction "k": increase camera roll by 2 degrees in the +ve direction "K": decrease camera roll by 2 degrees in the -ve direction "l": increase camera pitch by 2 degrees in the +ve direction "L": decrease camera pitch by 2 degrees in the -ve directionNote that all movements and rotations are with respect to the camera's axes. Your navigation will be made much more intelligible if you cover the horizontal plane with a set of grid lines, as in figure 7.24. To add these grid lines, a simple loop shown below will help:for(int x = -100; x < 100;x++) { glBegin(GL_LINES); glVertex3d(x,0,100); glVertex3d(x,0,-100); glEnd( ); }You should also add both horizontal and vertical grid lines. Hint: You may need to develop a camera class.
- Extra Credit: Improve your miniGL castle from homework 3 by adding lighting, colors, material properties and shading.
More Hints and Notes:
- Read section 7.3 of Hill. It describes how to implement a camera class and flying.
- Hill explains all the camera movement and gives you code for the slide and the roll. You should be able to figure out the pitch and yaw.
- The signature for the setShape method takes the arguments vAng for view angle, asp for aspect ratio, near and far planes distances. A good value for view angle is your choice. Values like 45 degrees should be a good starting point but this depends on how you have set up your camera and scene.
- In order to type in the examples in the book, you may have to change the vector classes that come with miniGL and SDL (Vector3) slightly. For instance, check the arguments of constructors and methods to make sure it matches what you are calling it with. (e.g. the set and cross methods)
- SDL already implements meshes in sdl.h. You should use that. The mesh keyword in the SDL input file should work.
- The drawEdges( ) method in the SDL mesh class is NOT implemented but is easy to implement. You should implement it. Modify our Vector class (you'd have to modify the SDL Vector3 class in a similar way, since the set method in Vector3 takes a Vector3&) or change the code snippet in the book
- Some function signatures from the book do NOT take mgl or mglut references so you have to modify them to do so.
- If you make modifications to your SDL.h or SDL.cpp files, you can call OpenGL/GLUT/GLU directly. (E.g. gluPerspective, glLoadMatrixf)
Note: Create documentation for your programs and submit them along with the projects. Make sure the old examples (bounce, gears, etc) work. The documentation does not have to be unnecessarily long. Simply explain briefly what each file does, how to run it and tie things in nicely.