CS 4554- Computer Graphics I: Instructions for Assignment 2
Assignment Description:
You are going to create a simple 3D wireframe display system. This will require loading external models, create your own data structure for
3D model, performing model and viewing transformation using OpenGL.
Requirements
1. Read in the geometric object file and create a data structure of vertex points and associated polygon list. The detailed description of geometric model is listed below.
2. Implement basic 3D wireframe display system using OpenGL functions. Some of the useful OpenGL functions are listed below.
3. Use the mouse or Keyboad to translate, rotate, and scale the object.
4. Add basic surface shading of the filled object by enabling lighting in OpenGL and drawing the polygons in filled mode.
Notes:
1) From model geometry collection site, you can download geometry files in a format ( .d ). The format contains geometry information, such as
the number of vertices, the number of polygons, list of vertex coordinates, and the surface information.
e.g.) lbox.d
data 12 8 -.5 0.0 -.5 0.0 0.0 -.5 0.0 .5 -.5 .5 .5 -.5 .5 -.5 -.5 -.5 -.5 -.5 -.5 0.0 .5 0.0 0.0 .5 0.0 .5 .5 .5 .5 .5 .5 -.5 .5 -.5 -.5 .5 4 3 9 10 4 4 1 7 8 2 4 12 6 5 11 4 7 1 6 12 4 9 3 2 8 4 10 11 5 4 6 9 8 7 12 11 10 6 4 5 6 1 2 3 From the beginning, the above file has 12 : number of vertices 8 : number of polygons 12 lines of vertex coordinates (x, y, z order) 8 lines of polygon list (number of vertices in the polygon, vertex indices) For example, in the above geometry, the first polygon contains four vertices of index number 3, 9, 10, and 4.
2) To initialize 3D display system, you need to add some OpenGL functions to your program.
The common way is to add viewport, and projection to the reshape functions.
Add the following command to the main() function: glutReshapeFunc(reshape);
Create a function named as reshape
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h); // Create a view port with w(width) and h(height)
glMatrixMode(GL_PROJECTION); //Matrix mode set as projection matrix
glLoadIdentity();
gluPerspective(field_of_view_angle, (GLfloat) w / (GLfloat) h, near_clippling, far_clipping); //Define perspective projection Matrix
glMatrixMode(GL_MODELVIEW); //Matrix Mode set as Model View Matrix Mode
glLoadIdentity();
}
3) gluLookAt() can be used to specify the camera position, reference position and viewing up vector.
glTranslatef(), glRotatef(). glScalef() can also be used to translate, rotate and scale the object.
4) glutDisplayFunc(render); In the render() fumction, use glBegin(GL_LINES); ...... glEnd() to draw line of polygon edge.
5) You should refer to the OpenGL books or resources for detailed use of listed OpenGL functions.
If you feel like going above and beyond the call of duty, you may do the following:
You may read in several objects, moving the several objects at the same time. Using Bounding Box to avoid collision between Objects.