Camera Control

In the UDK, a camera is composed of three properties:

  • Position
  • Rotation
  • Field of View

Position

This defines the location in the world from which the view should be constructed. This position will be the location of the viewer.

Rotation

This defines the rotation from which the world is viewed.

Field of View

In a perspective camera (the default camera), this is a measure of the maximum angle that a light ray may deviate from the center directional line of the camera and still be visible. This may either be a measure of the horizontal deviation or the vertical deviation. Typically, the field of view is the angle of the entire field so the maximum deviation is half of the field of view. This is better explained using a diagram:

In the UDK, the field of view defaults to somewhere between 60 and 90 degrees. For our purposes, we can typically ignore this property and focus on position and rotation.

UDK Implementation

In the UDK, the simplest way to control the camera is to override the function CalcCamera on a derived UTPawn class.

CalcCamera

This function is found on all actors but made particularly useful in UTPawn. To make use of this, your controller must also derive from UTPlayerController and must be possessing the pawn in question.

function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )

Let's look at the signature of this function:

  • Return type: Bool
    • This function should return true if its calculations should control the camera
  • float fDeltaTime
    • The amount of time in seconds that has passed since the last frame/tick
  • out vector out_CamLoc
    • An out vector parameter that should hold the final position of the camera in the world
  • out rotator out_CamRot
    • An out rotator parameter that should hold the final rotation of the camera in the world
  • out float out_FOV
    • An out float parameter that should hold the final field of view of the camera in standard angles (ie 0-360). This defaults to a valid value

For example, the following UTPawn derived class positions the camera at the location (0, 0, 500) and rotates it to pitch upwards by 45 degrees:

class ExamplePawn extends UTPawn;

var rotator CamRot;
var vector CamLoc;

function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
{
    out_CamLoc = CamLoc;
    out_CamRot = CamRot;
    return True;
}

DefaultProperties
{
    CamLoc=(X=0, Y=0, Z=500)
    CamRot=(Pitch=8192, Roll=0, Yaw=0)
}