Camera controller entity

Language: C#

The camera controller class provide an unified way to manipulate a camera position.

This abstraction proved very useful for mapping user inputs to camera control, while switching between different camera types: by providing a controller, each camera defines its natural movement scheme.

Code sample

    /// <summary>
/// A controller for a 3D camera
/// </summary>
public abstract class CameraControler
{
    float m_speed = 1.0f;
    /// <summary>
    /// The controller movement speed
    /// </summary>
    public float Speed
    {
        get{ return m_speed; } 
        set{ m_speed = value; }
    }
 
    /// <summary>
    /// Move the camera along the forward vector
    /// <param name="amount">The amount of movement</param>
    /// </summary>
    protected abstract void MoveForward(float amount);
    public void Forward(float amount)
    {
        MoveForward(m_speed * amount);
    }
    public void Backward(float amount)
    {
        MoveForward( - m_speed * amount);
    }
 
    /// <summary>
    /// Move the camera vertically 
    /// <param name="amount">The amount of movement</param>
    /// </summary>
    protected abstract void MoveUp(float amount);
    public void Up(float amount)
    {
        MoveUp(m_speed * amount);
    }
    public void Down(float amount)
    {
        MoveUp( - m_speed * amount);
    }
 
    /// <summary>
    /// Move the camera horizontally
    /// <param name="amount">The amount of movement</param>
    /// </summary>
    protected abstract void MoveRight(float amount);
    public void Right(float amount)
    {
        MoveRight(m_speed * amount);
    }
    public void Left(float amount)
    {
        MoveRight( - m_speed * amount);
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License