Game Development Reference
In-Depth Information
Vector F = (Fx, Fy, Fz) : The forward direction of the bike. This is the direction the bike moves in
when no turns are taken. It's a vector tangent to the surface at point P and is also perpendicular to
N. (More on how to find this vector to come.)
Both N and F need to be normalized to the length of 1.
To create the transformation, we first calculate the vector R:
R = N × F
Vector R, which stands for “right,” is composed of the elements (Rx, Ry, Rz). It is a vector tangent to the
surface, like F, and it points to the right-hand side of the bike.
With these vectors, we construct the 4 × 4 transformation matrix:
M=
( Fx Rx Nx Qx )
( Fy Ry Ny Qy )
( Fz Rz Nz Qx )
( 0 0 0 1 )
The vectors N, F, and R make the orthogonal coordinate base to which we want to transform the bike
model. They are copied to the first three columns of the matrix. The fourth and final “homogeneous”
column makes the translation to point Q.
To apply this transformation to the bike model, we use it like any other rotation or translation
transformation in the rendering engine. The transformation matrix is pushed to the model-view matrix
stack. This causes the transformation it represents to be applied to the vertices of the bike model in the
code of the vertex shader.
Transformation components
So far, we've defined the meaning of each of the components of the transformation, but the practice of
calculating them may still not be clear.
Normal vectors are usually provided with the model we're rendering for lighting purposes. If the model is
generated in code or does not contain normals, a good approximation of the normal data can be easily
computed from just the mesh triangles data. The general process for this is as follows:
1.
Calculate the normal of every triangle individually.
2.
Approximate the normals of the surface on each of the vertices of the mesh.
3.
From the vertices normals, smoothly approximate a normal vector for every point of the surface.
To understand this procedure, remember that the triangle mesh is considered as only a discrete sampling
of an ideal, smooth 3D surface. This is why normals on different parts of the same flat triangle may differ
slightly in direction and not be exactly equal to the triangle normal—the vector perpendicular to the triangle
plane. This effect is the most frequently used method to achieve real-time, smooth lighting in 3D rendering.
 
Search WWH ::




Custom Search