Game Development Reference
In-Depth Information
But what about the matrices that we need for the camera? Those are provided using
the XMMATRIX data type. In most cases you will use a couple of key methods to cre-
ate and manipulate these matrices, as shown in the following code snippet:
XMMATRIX XMMatrixMultiply(XMMATRIX M1, XMMATRIX
M2);
// World & View Matrices
XMMATRIX XMMatrixTranslation(float x, float y,
float z);
XMMATRIX XMMatrixScaling(float x, float y,
float z);
XMMATRIX XMMatrixRotationRollPitchYaw(float
pitch, float yaw,
float roll);
XMMATRIX XMMatrixPerspectiveFovRH(float fov,
float aspectRatio,
float nearZ, float farZ);
Most of these are straightforward, but, the last one may have some new concepts.
A perspective projection requires some information to correctly warp the scene so
that we have vanishing points and a horizon. To do this, we need to provide the field
of view ( fov ) and aspectRatio of the camera. In this particular case the field of
view refers to the vertical field of view rather than the horizontal field of view that you
may be used to.
The nearZ and farZ parameters refer to how far the two clipping planes are from
the position of the camera. A clipping plane is the point where objects are no
longer rendered. This prevents weird-rendering artefacts when models cross over
the position of the camera, and allows you to define the farthest point from the cam-
era—which is required for the depth parameter that is stored as a value from 0.0f to
1.0f.
These parameters combine to give you a matrix that defines a shape called a frust-
um , which contains everything visible in the scene.
Search WWH ::




Custom Search