#include <gearlib.h>
#include <stdlib.h>

Camera* create_camera(vec2 pos) {
    Camera* camera = calloc(sizeof(Camera), 1);
    camera->position = vec3(pos, -3.0f);
    camera->m = calloc(sizeof(CameraMatrices), 1);

    return camera;
}

void update_camera(Camera* camera, Window window) {
    int width, height;
    glfwGetWindowSize(window, &width, &height);

    assert(camera != NULL);

    camera->m->view = mat4Transpose(mat4Translate(vec3_spread(camera->position)));
    
    switch(camera->projection) {
    case CAMERA_ORTHOGRAPHIC:
        camera->m->projection = mat4Transpose(mat4Ortho(0.0f, width, height, 0.0f, 0.0f, 1000.0f));
        break;
    case CAMERA_PERSPECTIVE:
        camera->m->projection = mat4Transpose(mat4Perspective(45.0f * DEG2RAD, ((double)width / (double)height), 0.1f, 100.0f));
        break;
    }
}
