Program Listing for File Camera.hpp

↰ Return to documentation for file (engine/include/Cacao/Camera.hpp)

#pragma once

#include "EventManager.hpp"
#include "DllHelper.hpp"

#include "glm/glm.hpp"
#include "glm/gtc/quaternion.hpp"

namespace Cacao {
    class CACAO_API Camera {
      public:
        Camera();

        virtual ~Camera() {
            EventManager::Get().UnsubscribeConsumer("WindowResize", resizeConsumer);
        }

        glm::vec3 GetPosition() const {
            return position;
        }

        void SetPosition(glm::vec3 pos) {
            position = pos;
            RecalculateViewMatrix();
        }

        glm::quat GetRotation() const {
            return rotation;
        }

        glm::vec3 GetRotationEuler() const {
            return glm::degrees(glm::eulerAngles(rotation));
        }

        void SetRotation(glm::quat rot) {
            rotation = glm::normalize(rot);
            RecalculateViewMatrix();
        }

        void SetRotationEuler(glm::vec3 rot) {
            rotation = glm::normalize(glm::quat(glm::radians(rot)));
            RecalculateViewMatrix();
        }

        glm::mat4 GetProjectionMatrix() const {
            return projectionMatrix;
        }

        glm::mat4 GetViewMatrix() const {
            return viewMatrix;
        }

        glm::vec3 GetFrontVector() const {
            return frontVec;
        }

        glm::vec3 GetRightVector() const {
            return rightVec;
        }

        glm::vec3 GetUpVector() const {
            return upVec;
        }

        glm::vec3 GetLookTarget() const {
            return position + frontVec;
        }

        glm::u8vec3 GetClearColor() const {
            return clearColor;
        }

        void SetClearColor(glm::u8vec3 color) {
            clearColor = color;
        }

        void ResizeProjectionMatrix(Event& e);

      protected:
        EventConsumer resizeConsumer;
        glm::u8vec3 clearColor;

        glm::mat4 projectionMatrix, viewMatrix, viewProjectionMatrix;

        glm::vec3 position;
        glm::quat rotation;
        glm::vec3 frontVec, upVec, rightVec;

        glm::uvec2 displaySize;

        //Recalculates the view matrix based on a new position and rotation
        void RecalculateViewMatrix();
        //Recalculates the projection matrix
        virtual void RecalculateProjectionMatrix() = 0;
        //Recalculates camera rotation vectors
        void RecalculateCameraVectors();
    };
}