Prospective Projection
- I'm going to skip the derivation of the prospective projection.
- There is a really nice presentation here if you wish.
- The book discussion 18.1.2 is not the best.
- There is an alternative to glFrustum
-
- This is from the GL Utility Library (glu)
- You need to link with -lGLU
-
- These images are indirectly from an old copy of the "Red Book".
- There is one more useful transformation
- void gluLookAt( GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ);
- (eyex, eyey, eyez) are the location of the camera
- (centerx, centery, centerz) is the center of projection.
- (upx, upy, upz) specify the up direction for the camera.
- This command will generate a matrix
The eye position is at the origin.
- LookAt: (eyex, eyey, eyez) to (centerx, centery, centerz) define an axis along which the shot will be performed (the Z axis)
- Up: (eyex, eyey, eyez) to (upx, upy, upz) define the y axis or up direction for the camera.
- LookAt and Up should be orthogonal.
- To specify a complete system, a third vector is required (the x axis)
- This achieved by the cross product: left = up × lookAt
- Frequently, one does not trust up and lookAt to be orthogonal, so after the first cross product, a second is performed up = lookAt × left
- These concepts, while not in use in OpenGL 3+, are still valid
- The Red Book contains code, which includes:
- mat.h
- Look for
- RotateX, ... Translate, Scale
- Orhto
- Frustum, Perspective, LookAt