Lab 6: Camera Overview

CSC385 - Computer Graphics



Goal: Learn the basics of camera control in OpenGL.

Action:

0. To start, download the starting code from Blackboard. Create a new visual studio project then build and run the executable. The program draws a set of coordinate axis centered at the origin.

1. Your first challenge is to allow the user to change the viewpoint using the mouse.

OpenGL requires that we specify the viewpoint position, p, center of attention, c, and the "up" direction. The up vector is always set to (0,1,0). The current viewpoint is specified relative to c by angles θ and φ, measured in degrees as illustrated in the following figure.

Left and right movement of the mouse should control the angle phi while up and down movements shouold contol theta. You need to decide how to convert mouse movement into changes in these angles and implement your scheme in the method motion(), which is the callback for glutMotionFunc(). Note: You only need to complete a few lines of code but you probably will need to tune them so that the control feels natural. Also, in order to prevent the view vector (from the viewpoint to the center of attention) from coinciding with our up vector, we constrain θ to be between -85 and 85 degrees.

Note the use of "glutPostRedisplay" in the motion function. Read up on this in the glut specs.

2. Your next challenge is to allow the user to zoom in or out. Implement some sort of keyboard control on the distance from the viewpoint to the center of attention. (You'll probably want to use glutPostRedisplay() in your keyboard function.)

3. Incorporate your camera code into your last lab so that you can view your floor/sphere from any directions. Is there anything strange about the lights? Can you fix the problem? (Try or explain why not in comments)

4. Finally, add controls to change the center of attention. Are you happy with the result? How could you improve on them for project 3? (Describe in comments)

Deliverables: Email a your .cpp to me and hand in a hard-copy in class next Tuesday.