Posted by: Justin on: October 25, 2008
This week I (the class) looked at Spaces & Cameras. This was necessary in order to create the Camera class for my renderer. So, lets get into the theory behind the programming.
There are different coordinate systems/spaces used in the computer graphics pipeline to render the images on screen. Here they are explained briefly:
A virtual camera renders 3D graphics on a 2D screen in world space and can be split into two components. One component is the external camera properties; the other is the internal camera properties.
External properties include orientation and the position of the virtual camera in world space. An object’s position is its location and is defined by a point of reference; in most cases, the origin. Orientation is a term used to describe the direction the object is facing. Terms such as pitch (x – object forward and backward), yaw (y – way object is facing) and roll (z – move side to side) are used for orientation and are used to transform the coordinate space.
As mentioned before there are different “spaces”. If you had a circular ball and a cube, they both have their own object spaces. You would need to use other coordinate spaces to refer to the other object. To do this we have to express the location in that coordinate space into another location for another space, which is known as coordinate space transform. So just to clarify we’re using different origins for different spaces.
Transforming techniques depend upon the coordinate space used.
The Inverse Camera Transform (View Matrix) is a technique used to transform the world space to the camera space. In other words, moving the world space to suit the camera’s position. This may be implemented if a particular angle was needed for the camera projection. I think this is done by:
- Multiplying the Z Rotation by Y Rotation
- Multiplying your new matrix by X Rotation
- Transposing the outcome (it helps to create the inverse)
- Multiplying this by the Translation matrix
This has to be implemented into my camera class later.
Unfortunately, there is a bug with this method called Gimble Lock. As the axis’ are rotated, translated, transformed, in some circumstances one axis may become equal to another. For example, if X became the same as Z, whenever Z was transformed, it would take X along with it, so you would lose one degree of axis in effect. Here is a nice video to explain it.
Internal properties are the camera’s frustum, its projection and its image.
A camera frustum (also called viewing volume) is the volume of space that is visible in the camera’s projection. The frustum has 6 planes (top, left, bottom, right, far clip plane, near clip plane). The near clip plane is the plane nearest to the camera, and if it comes to close to the camera, it is chopped off so the rest is visible. The far clip plane controls the distance of how far the camera can see it. It is chopped off once the the object goes too far away from the camera, shrinking and shrinking until it cannot be seen from the camera anymore.
The field of view (FOV), is a property just like position and orientation which a camera has. The FOV is the angle inside the frustum. There are two angles; one for the horizontal FOV and one for the vertical FOV. The FOV angle can be changed to increase the field of view or limit it. Zoom zoom zoom…. is a measurement, which measures the ratio of objects relative to a 90 degree field of view. If I wanted to zoom in by 2.0, the object’s size would double making it look larger and closer.
Here is the equation for converting between field of view and zoom:
zoom = 1 / tan(FOV / 2)
FOV = 2 atan (1/zoom)
The camera has two popular ways of projecting onto world space. Orthographic / Parallel and Perspective Projection.
Orthographic Projection is referred to as Parallel Projection since the lines from the original points to the projected points are parallel. Perspective Projection on the other hand operates differently and does not project parallely. Instead, it projects onto a plane in a center of projection, so all lines intersect when they reach the plane. The lines close in to the center of projection and give off a perspective feel.