Game Development Reference
In-Depth Information
Understanding the view transformation
The viewing transformation is analogous to the positioning and aiming of a
camera. In our code examples, the current matrix is set to the identity matrix using
mat4.identity(mvMatrix) . This step is necessary as most of the transformation
commands multiply the current matrix by the specified matrix and then set the result
to be the current matrix. So essentially, we can say that until now we were setting
our view matrix to the identity matrix. So, let's dive deep into the view matrix and
its calculations.
The view matrix is the most misunderstood concept in 3D game programming. The
camera transformation matrix defines the position and orientation of the camera in
the world space. However, we use the view matrix to transform the model's vertices
from world space to view space. The camera matrix and view matrix are not the same.
To understand it, let's define the two terms separately:
Camera transformation matrix : This is exactly like the model matrix. We
treat our camera like an object. It has a location and can be rotated in a scene.
The final transformation matrix is our camera matrix.
View matrix : This matrix is used to transform the vertices of a model
from world space to view space. This matrix is the inverse of the camera
transformation matrix. In the real world, you move the camera but in 3D
rendering, we say that the camera does not move but the world moves in the
opposite direction and orientation. Hence, to transform the model to view
space, we use the inverse of the camera matrix.
Understanding the camera matrix
The camera transformation matrix is exactly the same as the model transformation
matrix, except that we do not use the scale component to calculate it. Let's reiterate
the components used to calculate a model transformation matrix. A model matrix is
calculated using the translation, rotation, and scale functions. In the camera matrix,
we generally do not have a scale functions.
Hence, if R represents the rotation matrix of the camera and T represents the
translation matrix in world space, then the final transformation matrix M can be
computed by multiplying the two matrices, M = T*R . To get the position of the
camera in world-space (also called the eye position), from the matrix M , you simply
take the fourth row of the resulting 4 × 4 matrix, M = (M 41 , M 42 , M 43 , M 44 ).
 
Search WWH ::




Custom Search