Camera view projection
View & Projection
Right-handed system
It is a convention.
- Stretch your right-arm along the positive y-axis with your hand up top.
- Let your thumb point to the right.
- Let your pointing finger point up.
- Now bend your middle finger downwards 90 degrees.
Global Picture of transformations
Model Transformation
It transform the object from its local coordinate system to the world coordinate system.
Usually this transformation is pre-applied to the model, so we don't use it here.
View/Camera Transformation
It transform both the camera and objects, until the camera is at the origin, up at Y axis and look at -Z axis. (from world coordinate system to camera coordinate system)
We should first apply this view transformation before we further apply projection transformation.
Projection Transformation
It projects 3D objects into a Clip space, such that we can transform it to the final 2D plane.
First, we project the objects (from camera coordinate system) into a canonical cuboid \([-1,1]^3\) (the normalized device coordinate system, NDC). Coordinates outside \([-1, 1]\) will be clipped, so the space is called Clip space.
Second, we perform viewport transform, i.e., simply look at -Z direction and get the 2D projection plane.
Orthographic projection
- Ignore Z axis.
- Translate & Scale X/Y axes to \([-1,1]^2\)
In implementation, we simply linear translate & scale the object's bounding box from \([l,r]\times[b,t]\times[-n,-f]\) into \([-1, 1]^3\):
(Note: since we look at -Z, we use \(-n\) and \(-f\) for near and far plane, so that \(0<n<f\).)
Perspective projection
Further objects should look smaller!
- squish the frustum into a cuboid.
- do orthographic projection.
In implementation, we should find the relationship between the transformed points and original points:
For Z axis, we observe:
- any point on the near plane will not change.
- any point's z on the far plane will not change.
Solve the equations and we have:
And finally:
In cases the view is symmetric (\(l= -r, b = -t\)), we have the most commonly used form: