This assignment is about viewing and transformations in 3D. It also introduces you to the use of 3D models, and the creation of a simple animation. This assignment is due Wednesday, April 13.
Download this zip file. In the zip file you will find a demo program,
When you run the demo program, notice the following. The three sliders control the location of the camera. In this program, the camera is on the surface of an imaginary sphere and, at least initially, the camera is looking at the origin (the corner of the room in the scene). The top slider controls the radius of the sphere, so it moves the camera closer to, or further away from, the "look at" point. The second slider controls the longitude of the camera on the sphere, which means, more or less, that it moves the camera from side to side. The vertical slider controls the latitude of the camera, which means, more or less, that it moves the camera up and down. In mathematical terms, the sliders are controlling the spherical coordinates in space of the camera. But the
The "look at" point in the call to
The "look at" point used in Notice that you can use the keyboard to switch the program between perspective and orthogonal projections (using the 'p' and 'o' keys). My dimensions for the (perspective and orthogonal) view volume were plus or minus three for left, right, top, and bottom, two for near, and 100 for far.
When the program is running, the console window is used to output some information that might help you to understand how perspective and parallel projections work with When you write your program, first just draw the floor and two walls and look at them from a fixed camera location. Then add one model to the scene. Then have the sliders control the rectangular coordinates of the camera, so that you can move the camera around (make the top slider control the x-coordinate of the camera, the second slider the z-coordinate, and the vertical slider the y-coordinate). Then have the keyboard move the "look at" point. When that is working, start to work on having the sliders move the camera on the surface of a sphere. When that works, add the other models to the scene. Finally, animate the dolphins.
When you put a model in the scene, it helps to first call the function
All the models you need are contained in the subfolder Here is a reference that I used to find r,g,b values for the colors used in the scene. glColor3ub() (that is, use the "unsigned byte" data type).
Here is the code that I used to get the three sliders in place. // parent window, x, y, width, height, initial value, callback function gluiHorizontalSlider(window, 1, 0, -1, 20, sliderInit, slider1); // top edge gluiHorizontalSlider(window, 1, 20, -1, 20, sliderInit, slider2); gluiVerticalSlider (window, 0, 40, 20, -1, sliderInit, slider3); // left edge
To animate the movement of the dolphins, use a GLUT "idle" callback function. You register a GLUT idle callback function using loadAndAnimateModel.c , in the zip file demonstrating a simple animation.
Here is a function that will draw a lined surface for the floor and walls. Treat this as a model that can be transformed into place to form the two walls. void grid(int n, int m) { int i, j; glPushAttrib(GL_ALL_ATTRIB_BITS); glFrontFace(GL_CCW); glPolygonMode(GL_FRONT, GL_FILL); glPolygonMode(GL_BACK, GL_FILL); // Draw an n by m grid of (filled in) quads. glColor3f(1.0, 1.0, 1.0); // Draw in white. glBegin(GL_QUADS); for (i = 0; i <= m; i++) { for (j = 0; j <= n; j++) { glVertex3f( i, 0.0, j); glVertex3f(i+1, 0.0, j); glVertex3f(i+1, 0.0, j+1); glVertex3f( i, 0.0, j+1); } } glEnd(); // Now draw grid lines over the edges of the quads. glColor3f(0.7, 0.7, 0.7); // Draw in light gray. glBegin(GL_LINES); for (i = 0; i <= m; i++) { glVertex3f( i, 0.1, 0.0); // a tiny bit above the quads glVertex3f( i, 0.1, n); } for (i = 0; i <= n; i++) { glVertex3f(0.0, 0.1, i); glVertex3f( m, 0.1, i); } glEnd(); glPopAttrib(); }
Turn in a zip file called |