|
|||||||||||||||
|
Timely Task Tidbits:
The Camera In OpenGL, "vertices and normals are transformed by the modelview and projection matrices before they're used to produce an image in the framebuffer" (taken from your OpenGL help file - use it).
To make this a perspective projection (unlike the orthographic we have been using so far), we use the command gluPerspective(), applied to the projection matrix:
The viewangle is theta in diagram b) above, and the nearplane and farplane
parameters are obvious from these pictures. In order to get different views of a scene, it is possible to move the camera around, rotating and translating it, which form part of the modelview matrix. This is done with gluLookAt();
It is helpful to give the camera its own coordinate system, as described by the figure above. u, v and n are simply clones of x, y and z. To orient our camera, we move and rotate these axes. Relative movements can be done by setting the camera's pitch, roll and heading (a change in heading is referred to as yaw) - see figure below.
The following diagram should be helpful in visualising the relationship between gluLookAt(eye,look,up) and the camera coordinates u,v and n.
Given the points eye and look and the vector up:
Check with eye = (-2,2,0), look = (0,0,0) and up = (0,1,0) that: Normalizing these three vectors will give us our camera's coordinate system. gluLookAt() then transforms the camera's
coordinate system into the generic position for the camera (in x, y and
z). We create a class 'camera', which is given to you in the code at the bottom as camera.cpp & camera.h. To move our camera in a scene, we can add functions to the camera class
for slide (moving the camera forwards or backwards), roll, pitch and yaw.
After each of these adjustments, setModelViewMatrix()
is called, which loads the new (camera) matrix into the modelview matrix.
To remember which order to do the cross product in, you can use your right hand coordinate system and know:
The source code example below was compiled from various parts of the
text to implement a movable camera in conjunction with the mesh loader
of chapter 6. It uses several files to hold the various classes and functions
required. |
|
||||||||||||||