# class hiro::Camera

## Overview

Denotes view on a scene. More…

    #include <Camera.h>

    class Camera {
    public:
        // structs

        struct Pose;

        // construction

        Camera(hiro::draw::Scene* scene);
        Camera(const hiro::Camera& cp);
        ~Camera();

        // methods

        Camera& operator=(const hiro::Camera& cp);
        glm::vec3 GetPosition() const;
        void SetPosition(const glm::vec3& camera_position);
        glm::vec3 GetTarget() const;
        void SetTarget(const glm::vec3& poi);
        glm::vec3 GetForward() const;
        glm::vec3 GetRight() const;
        glm::vec3 GetUp() const;
        void AlignUp(const glm::vec3& up);
        void Zoom(float factor);
        bool IsFixedRotationEnabled() const;
        void SetFixedRotationEnabled(bool state);
        const glm::vec3& GetFixedRotationAxis() const;
        void SetFixedRotationAxis(const glm::vec3& axis);
        void ScreenRotate(const glm::vec2& last_mouse_pos, const glm::vec2& mouse_pos);
        void ScreenRoll(const glm::vec2& last_mouse_pos, const glm::vec2& mouse_pos);
        void ScreenMove(const glm::vec2& last_mouse_pos, const glm::vec2& mouse_pos);
        void ScreenDolly(const glm::vec2& last_mouse_pos, const glm::vec2& mouse_pos);
        void SubscribeChange(const std::function<void(void)>& callback);
        void CopyView(const hiro::Camera& source_camera);
        void ReadFromStream(std::istream& str);
        void WriteToStream(std::ostream& str);
        void Reset();
        hiro::Camera::Pose GetPose();
        void SetPose(const hiro::Camera::Pose& pose);
        cogs::Frustum ComputeViewFrustum() const;
        const glm_ext::TransMat4& GetViewMatrix() const;
    };

## Detailed Documentation

Denotes view on a scene.

Camera pose is denoted by two points: camera position and “target” point. While both points can be set individually, the forward direction of the camera is always oriented towards the target.

The camera can rotate in two modes. Free rotation and fixed rotation, denoted by property “fixed rotation enabled”. When the camera uses fixed rotation, up direction is always aligned with fixed rotation axis, that can be also set manually.

### Methods

    glm::vec3 GetPosition() const

Returns the position of the camera.

    void SetPosition(const glm::vec3& camera_position)

Set position of the camera. The view direction is corrected automatically.

    glm::vec3 GetTarget() const

Returns point of interest.

    void SetTarget(const glm::vec3& poi)

Changes point of interest. The view direction is corrected automatically.

    glm::vec3 GetForward() const

Returns forward direction.

    glm::vec3 GetRight() const

Returns right direction.

    glm::vec3 GetUp() const

Returns up direction.

    void AlignUp(const glm::vec3& up)

Aligns up direction of camera to match the specified vector.

    void Zoom(float factor)

Modulates distance of camera position to target.

Parameters:

factor | A factor by which the distance is multiplied.

    bool IsFixedRotationEnabled() const

Checks whether fixed rotation mode is enabled.

    void SetFixedRotationEnabled(bool state)

Set whether to enable fixed rotation mode. By default disabled.

Axis of fixed rotation can be specified using SetFixedRotationAxis function.

    const glm::vec3& GetFixedRotationAxis() const

Returns axis of fixed rotation.

    void SetFixedRotationAxis(const glm::vec3& axis)

Sets fixed rotation axis to specified. By default Y axis.

Used only when fixed rotation enabled using SetFixedRotationEnabled function.

    void ScreenRotate(const glm::vec2& last_mouse_pos, const glm::vec2& mouse_pos)

Rotates the camera using mouse movement over screen.

    void ScreenRoll(const glm::vec2& last_mouse_pos, const glm::vec2& mouse_pos)

Rotates around view direction, counter-clockwise using mouse movement over screen.

    void ScreenMove(const glm::vec2& last_mouse_pos, const glm::vec2& mouse_pos)

Moves camera left and up relatively using mouse movement over screen.

    void ScreenDolly(const glm::vec2& last_mouse_pos, const glm::vec2& mouse_pos)

Moves forward using mouse movement over screen.

    void SubscribeChange(const std::function<void(void)>& callback)

Sets up callback function, called every time a scene camera changes it’s state.

    void CopyView(const hiro::Camera& source_camera)

Sets up camera pose to exactly match the source camera.

    void ReadFromStream(std::istream& str)

Loads camera pose from stream.

    void WriteToStream(std::ostream& str)

Saves camera pose to stream.

    void Reset()

Resets camera pose to an initial state.

    hiro::Camera::Pose GetPose()

Returns current camera pose.

    void SetPose(const hiro::Camera::Pose& pose)

Sets camera pose.

    cogs::Frustum ComputeViewFrustum() const

Computes the camera’s view frustum.

    const glm_ext::TransMat4& GetViewMatrix() const

Returns current view matrix.