|
EXERCISES FOR WEEK 10
|
| week10-1 | The program movelight.cpp rotates a light source around an object. When the left mouse button is
pressed, the light position rotates an additional 30 degrees. A small,
unlit, wireframe cube is drawn to represent tthe position of the light
in the scene.
|
| week10-2 | Continuing with the program movelight.cpp,
try to create a light that moves along with the viewpoint. You need
to set the light position before the viewing transformation. Then
the viewing transformation affects both the light and the viewpoint in the
same way. In the following code, the light position is defined in init(), which stores the light position at (0,0,0) in eye coordinates.
In other words, the light is shining from the lens of the camera. GLfloat light_position() = {0.0, 0.0, 0.0, 1.0}; glViewport(0, 0, (GLint) w, (GLint) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40.0, (GLfloat) w/(GLfloat) h, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightfv(GL_LIGHT0, GL_POSITION, light_position); If the viewpoint is now moved, the light will move along with it, maintaining (0,0,0) distance, relative to the eye. Next, the global variables (ex,ey,ez) and (upx,upy,upz) control the position of the viewpoint and up vector. The display() routine that's called from the event loop to redraw the scene might be this: static GLdouble ex,ey,ez,upx,upy,upz; void display(void) { glClear(GL_COLOR|GL_DEPTH); glPushMatrix(); gluLookAt (ex,ey,ez,0.0, 0.0, 0.0, upx, upy, upz); glutSolidTorus (0.275, 0.85, 8, 15); glPopMatrix(); glFlush(); } when the lit torus is redrawn, both the light position and the viewpoint are moved to the same location. As the values passed to gluLookAt() change and the eye moves, the object will never appear dark, because it is always being illuminated from the eye position. This method of moving the light can be very useful for simulating carrying a candle or lantern. The light position specified by the call to glLightfv(GL_LIGHTi, GL_POSITION, position) would be the x,y, and z distance from the eye position to the illumination source. |
| week10-3 | Go through the recursive subdivide algorithm (by hand) and determine the vertices generated if the original
vertices are: v1 = (0,0); v2 = (4,4); v3 = (8,0) and the depth is 2. Sketch
the resulting figure. |
| week10-4 | Write a function subdivide( ) that
takes four input parameters: 3 vertices (double) and a depth (int) and
draws the resulting subdivided triangle. Test it out with various levels. |
| week10-5 | Copy the spotlight demo program in /classes/cs3014/files/Lighting/spotdemowall.cpp
|