#include <pch.hpp>

#include <orthographic_camera.hpp>

#include <glm/gtc/matrix_transform.hpp>
#include <glm/trigonometric.hpp>
#include <glm/glm.hpp>

namespace OpenEngine {
    OrthographicCamera::OrthographicCamera(float left, float right, float bottom, float top)
        : projection_matrix(glm::ortho(left, right, bottom, top, -1.0f, 1.0f)), view_matrix(1)
    {
        view_projection_matrix = projection_matrix * view_matrix;
    }

    void OrthographicCamera::SetProjection(float left, float right, float bottom, float top)
    {
        projection_matrix = glm::ortho(left, right, bottom, top, -1.0f, 1.0f);
        view_projection_matrix = projection_matrix * view_matrix;
    }

    void OrthographicCamera::RecalculateViewMatrix() {
        glm::mat4 transform = glm::translate(glm::mat4(1.0f), position);
        transform *= glm::rotate(glm::mat4(1.0f), glm::radians(rotation), glm::vec3(0.0f, 0.0f, 1.0f));

        view_matrix = glm::inverse(transform);
        view_projection_matrix = projection_matrix * view_matrix;
    }
}
