Homework 5: Due October 10, 2003
Homework 5 Background
Up till this point, we have been able to accomplish several tasks required to render a 3D model, mostly using pure openGL commands. Our miniGL commands simply called the pure OpenGL commands. E.g. mgl.mglRotate simply called glRotate. In this project, we are trying to explore implementations of portions of the graphics pipeline in the absence of openGL. Previously, you ran your cs4731 executable with the -openGL option so that the miniGL wrapper would simply called the pure OpenGL calls. For instance, mgl.mglTranslate simply called glTranslate when you ran your cs4731 executable using the -openGL command-line option. In this homework, you will be required to use the -cs4731GL option which should call your own command implementations. Specifically, you will be required to write your graphics commands like myglScale, myglTranslate, myglRotate which have the same behavior as glScale, glTranslate and glRotate. To accomplish this you will build and maintain your own matrices for use by your application.
As an implementation note, your implemented commands should have the same "feel" to the user as if they were making openGL calls. So, for example, if the programmer uses mgl.mgltranslate in his/her program, it should have the same exact behavior whether it his/her program is run using the -openGL switch (pure openGL glTranslate) or the -cs4731GL option (your myglTranslate). Your castle or scenes should not exhibit dislocations or any different looks when your implementations are invoked.
Your homework 3 miniGL castle which we previously implemented using pure openGL commands will be tested using your command implementations and should work the same way as before. In order to keep the project to a manageable size, we will implement only a portion of the pipeline. Specifically, we will implement only commands for selecting matrix modes (e.g. glMatrixMode) or changing the modelview or projection matrices. Thus, while you will implement your versions of some commands, some commands will continue to be handled using pure OpenGL implementations.
Homework 5 Overview
The specific goal of this homework is to work with matrices. You are going to build and maintain your own MODELVIEW_MATRIX and PROJECTION_MATRIX matrix stacks. You will set OpenGL's actual MODELVIEW_MATRIX or PROJECTION_MATRIX whenever your MODELVIEW_MATRIX or PROJECTION_MATRIX changes. The actual transform and rendering operations in OpenGL should work as they did previously since all you are doing is building and maintaining two of OpenGL's matrix stacks. For instance, assuming that you run your homework 3 castle program using the -cs4731GL option, when your homework 3 miniGL castle program calls mgl.mglTranslate, mgl.mglTranslate should call your myglTranslate (your own implementation). In myglTranslate, you should build the necessary translate matrix and update your MODELVIEW_MATRIX. Before exitting your myglTranslate function, you should then update the actual OpenGL MODELVIEW matrix by calling glLoadMatrixf. See glLoadMatrix reference for more details on using glLoadMatrix.
Note that when you create a 3D model (e.g. glutWireCube), its vertices are stuffed into the OpenGL pipeline. In this homework, we will leave these vertices in the pipeline. However, we will simply help build and maintain the MODELVIEW and PROJECTION matrices which OpenGL will apply to the vertices.
You should use the Matrix.cpp and Matrix.h files. You will need to augment or/and change the provided matrix class to construct arbitrary scale, rotate and translate matrices (the translate is provided as an example).
Note that the sdl.cpp and sdl.h files I gave you already contain some matrix manipulation utilities which may ease your work. Please do not use these utilities. You can look at the code for the affine stack which may give you some ideas on how to proceed. Note that if you have already used the SDL.cpp or SDL.h files functions for your camera class, you can leave it and will not get penalized.
- Preparation: A good place to start the homework is to make sure your miniGL castle from homework 3 is working and reasonably clean as far as the design and the code. Make sure at least some minimal lighting and shading is on.
Requirements:
- Implement glRotate, glScale, glTranslate methods which modify the MODELVIEW_MATRIX stack.
- Implement glMatrixMode which selects either the MODELVIEW_MATRIX or the PROJECTION_MATRIX and the glPushMatrix, glPopMatrix and glLoadIdentity methods to complete the MODELVIEW_MATRIX stack.
- You will need to augment the provided matrix class to construct orthographic and perspective transformations. These will replace the remaining pipeline projection calls related to matrices that have been previously done by openGL. You will need to handle at least one glFrustrum (or gluPerspective) and glOrtho call. Once the basic infrastructure is in place, the difference between glFrustrum and glOrtho is negligible (simply using a different matrix).
- Everytime you handle any commands (e.g. glTranslate, glRotate, etc) which change your modelview or projection matrices, you should update the actual OpenGL modelview or projection matrix. You simply use the glLoadMatrixf command to update the actual OpenGL matrix whenever your version of the matrices change.
- Once your methods are working, remove all of the openGL calls you have replaced. Do not comment them out or ifdef them out. Completely delete them from the file. This reduces confusion during grading. In fact, when you submit your code, the only pure OpenGL commands allowed in your command implementations are commands to load (update) the OpenGL matrices.
- Make sure ALL the old miniGL castle code from HW3 works after you integrate your code. Theoretically, all you've simply included some homegrown code in portions of the pipeline. It should all still work if your code meets the stipulated requirements and has the same feel.
HINT: You may need to record and check which matrix mode you are in for each operation!
HINT: You can determine if your matrices are correct by using the glGet routines to get matrix values constructed by openGL. The values should be approximately the same as yours. Once you have check make sure you remove the openGL calls.
HINT: You can plug in known values for the matrix operations and test that your matrix operations and multiplications work. For instance, one simple debug strategy may be to call both your myglTranslate and the pure glTranslate, then print and compare both values.
The homework is due at the start of class on Friday.
Extra Credit: None!!
Note: Create documentation for your programs and submit them along with the projects. 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.