Game Development Reference
In-Depth Information
Projection transformation
Projection transformation is like setting/choosing the lens of the camera. You want
to determine the viewing volume of the scene. You want to determine how objects
appear and whether the objects are inside the viewing volume or not. The field of
view is the parameter that is used to define the viewing volume. Larger values mean
you will cover more objects in your game scene; smaller values are like a telephoto
lens (the objects will appear closer than they really are). There are two types of
projections; orthographic and perspective. In orthographic projection, the objects are
mapped directly on the screen without affecting their relative sizes. In perspective
projection, the distant objects appear smaller. In gaming, we always use perspective
projections. The following diagram explains how our primitive is projected on
the screen:
zFar
zNear
Now, to transform vertices with respect to their distance and chosen lens, we use the
projection matrix Vp = P * V . Here, Vp is the final vector, P is the [4 x 4] projection
matrix, and V is the vector corresponding to each vertex.
The following is the code to create a projection transformation:
mat4.perspective(out, fovy, aspect, near, far)
The parameters used in the preceding code are:
fovy : Field of view
aspect : Scene aspect ratio
near : Near plane to create the clipping region
far : Far plane to create the clipping region
 
Search WWH ::




Custom Search