Game Development Reference
In-Depth Information
the camera transformation represents a “physical” location and orientation for the camera,
in order for the camera to transform geometry into view space, the camera's world space
transform needs to be inverted.
4.2.4 Camera Interface
A camera object is a wrapper around the view and projection matrix that provides an intu-
itive interface for manipulating what the player can see of the game world.
These matrices are wrapped within a class that we will call camera , any operation we do
with the camera will update these transformations. This means we can implement different
camerasthatexhibitdifferentbehaviors,suchasfirstpersoncameras,orbitingcamerasthat
follow objects from a certain distance, cameras that have a rigid body to allow collision
with the environment, etc. by deriving from the camera class.
The first operation we want to be able to with a camera is to configure the projection set-
tings. Projection rarely changes on a given camera during its lifetime in most games,
though there is no reason why it cannot, so we will want to provide a function that sets a
custom perspective projection, but we should also provide some preset functions to set dif-
ferent projections by just providing the parameters we need.
void camera::SetProjection(const math::matrix& projection)
{
m_projection = projection;
}
void camera::SetPerspectiveProjection(float yfov, float aspectRatio, float nearPlane, float farPlane)
{
m_near = nearPlane;
m_far = farPlane;
m_projection = math::lefthanded::PerspectiveFOV(yfov, aspectRatio, nearPlane, farPlane);
}
The next operation we want to do is tell the camera where to look.
void camera::LookAt(const vector3& from, const vector3& to, const vector3& up)
{
m_view = lefthanded::LookAt(from, to, up);
}
It's a fairly straightforward function because the actual math to create the view matrix is
implemented within the matrix class itself, this is because it's a useful function whose do-
main is not strictly tied to cameras. And we create the camera's world transformation by
translating the camera into the “from” position in world space.
Search WWH ::




Custom Search