Game Development Reference
In-Depth Information
calculated. Most 3D libraries provide a function that can automatically calculate
the look-at matrix for you. But if you don't have such a library, it's not that hard to
calculate manually.
Three inputs are needed to construct the look-at matrix: the eye , or the position of
the camera, the position of the target the camera is looking at, and the up vector
of the camera. Although in some cases the camera's up vector will correspond to
the world's up vector, that's not always the case. In any event, given these three
inputs, it is possible to calculate the four vectors:
Click here to view code image
function CreateLookAt( Vector3 eye , Vector3 target ,
Vector3 Up )
Vector3 F = Normalize( target - eye )
Vector3 L = Normalize(CrossProduct( Up , F ))
Vector3 U = CrossProduct( F , L )
Vector3 T
T.x = -DotProduct( L , eye )
T.y = -DotProduct( U , eye )
T.z = -DotProduct( F , eye )
// Create and return look-at matrix from F, L,
U, and T
end
Once the view space matrix is applied, the entire world is now transformed to be
shown through the eyes of the camera. However, it is still a 3D world that needs
to be converted into 2D for display purposes.
Projection Space
Projection space , sometimes also referred to as screen space, is the coordinate
spacewherethe3Dscenegetsflattenedintoa2Done.A3Dscenecanbeflattened
into 2D in several different ways, but the two most common are orthographic pro-
jection and perspective projection.
In an orthographic projection , the entire world is squeezed into a 2D image with
no depth perception. This means that objects further away from the camera are the
same size as objects closer to the camera. Any pure 2D game can be thought of
as using an orthographic projection. However, some games that do convey 3D in-
Search WWH ::




Custom Search