Wednesday, September 26, 2012

Project 1


Objective: Create an OpenGL implementation that loads a file and renders it while also providing the ability for the user to Zoom, Pan, and view the object from all angles.

Syntax will be all in C++ with little mixes of C here and there.

Thoughts: It seems as though current OpenGL is mostly in C which doesn't have the structured classes that c++ provides, with this being said I will attempt to outsource as much as I can to the c++ classes.

All code will be uploaded to a public git repository at https://github.com/popasquat89/ME4573.git

The files contained within the project include:

LoadedObject.h && LoadedObject.cpp - This is our object that will be loaded, containing the vertice and elements within its private members. (Also contains mutators and accessors as well as render function for the object)

FileLoader.h && FileLoader.cpp - This is our file loader that will take in argv and a pointer to a LoadedObject. The file loads the file by creating dynamic vertice and elements then passing them to the LoadedObject.

Plane.cpp && Plane.h - A ported version of the plane.h and plane.c found on UTIL3D.

GLObjects.h - Contains the structs for the vertice and elements as well as a vertice for a plane backdrop.

keys.h - Simple header file containing definitions for different keys.

main.cpp - The main file for the program, containing all glut methods used for the main loop.

Process:

The layout of the program is pretty straightforward when compared to the examples showed in class, some of the code presented is based off the code presented to the class. Most of the glut functions were taken directly then modified slightly, with that being said I will lay out the structure of the program.

The program starts in the main with regular initializations with one slight difference. When the FileLoader object is initialized it automatically loads the file that was sent as a param via argv[].

The program then proceeds to call the startup method which will enable all of our GL enums that we plan on using such as lighting and depth test. It is important to note that whatever we plan on rendering in the display function needs to be created here. Since we are rendering one object as well as a plane we will create them here.

Once back from startup, main sets all of our glut functions such as keyboard, mouse, etc.

We then proceed to call the glutMainLoop() which is the heart of the program in essence, this will call all of our functions that we have registered as callbacks. It is important to note, the logic check for glewInit (if(glewInit() == GLEW_OK)) is not used because glew is a natural implementation in the Mac OS X system whereas it's a extension in Windows and Linux.

glutKeyboardFunc - This function will have a case statement that will switch on our keys that are defined in keys.h. This function will change the variables rotation_ and call the glutPostRedisplay() so that the display function will be called.

glutDisplayFunc - This will be in charge of all the rendering and transforming, anytime one of the variables that a call in this function contains changes it is standard to call glutPostRedisplay() to update the information.

glutMotionFunc - Anytime there is motion in the program this is the callback function that handles, in our case this is the function that handles when the click button is either a single or double click. Should it be a single click there will be rotation and translation, double click the zoom will be adjusted. This function gets its variables from the params as well as the mouse function.

glutMouseFunc - Anytime there is interaction from the mouse this callback will receive the button and state as well as where the event happened.

glutIdleFunc - For when the process lays idle this callback will keep the program processing tasks even when the program is not receiving events.


ScreenShots:

Standard Teapot Diffuse && Specular Enabled:


Standard Teapot Diffuse On Specular off:



Standard 747 w/ Logging - Diffuse on Specular Off:


Standard 747 from different angle Specular && Diffuse enabled:






Last image shows the error checking that is in place should the file path be incorrect.



Interaction:

Keys :

w - Rotate +x
a - Rotate +y
s - Rotate -x
d - Rotate -y
e - Rotate +z
c - Rotate -z

Left Click + Drag - Will Rotate and Zoom (Pan Effect)
Right Click + Drag - Zoom