//
// Created by sebastian on 07.02.26.
//

#ifndef MATHUTILS_H
#define MATHUTILS_H
#include "../layer/entities/Camera.h"
#include "glm/mat4x4.hpp"
#include "glm/vec3.hpp"
#include "glm/ext/matrix_transform.hpp"


class Camera;

namespace MathUtils {
    inline static glm::mat4 createTransformationMatrix(const glm::vec3 translation, const float rx, const float ry, const float rz, const float scale) {
        auto matrix = glm::mat4(1.0f);
        matrix = glm::translate(matrix, translation);
        matrix = glm::rotate(matrix, glm::radians(rx), glm::vec3(1, 0, 0));
        matrix = glm::rotate(matrix, glm::radians(ry), glm::vec3(0, 1, 0));
        matrix = glm::rotate(matrix, glm::radians(rz), glm::vec3(0, 0, 1));
        matrix = glm::scale(matrix, glm::vec3(scale));
        return matrix;
    }

    inline static glm::mat4 createViewMatrix(const Camera& camera) {
        const glm::vec3& pos = camera.getPosition();

        glm::vec3 front;
        front.x = sin(glm::radians(camera.getYaw())) * cos(glm::radians(camera.getPitch()));
        front.y = sin(glm::radians(camera.getPitch()));
        front.z = -cos(glm::radians(camera.getYaw())) * cos(glm::radians(camera.getPitch()));
        front = glm::normalize(front);

        glm::vec3 up(0.0f, 1.0f, 0.0f);
        return glm::lookAt(pos, pos + front, up);
    }
}

#endif //MATHUTILS_H
