#include <gear/camera.h>
#include <sokol/sokol_app.h>

mat4 g_camera_matrix(g_camera* camera) {
    mat4 rotation_x = HMM_Rotate_RH(HMM_AngleDeg(camera->rotation.X), HMM_V3(1.0f, 0.0f, 0.0f));
    mat4 rotation_y = HMM_Rotate_RH(HMM_AngleDeg(camera->rotation.Y), HMM_V3(0.0f, 1.0f, 0.0f));
    mat4 rotation_z = HMM_Rotate_RH(HMM_AngleDeg(camera->rotation.Z), HMM_V3(0.0f, 0.0f, 1.0f));

    mat4 rotation = HMM_Mul(HMM_Mul(rotation_z, rotation_y), rotation_x);
    mat4 translation = HMM_Translate(camera->position);
    mat4 view = HMM_Mul(rotation, translation);

    mat4 projection = HMM_Perspective_RH_NO(HMM_AngleDeg(camera->fov), 
                                            sapp_widthf() / sapp_heightf(), camera->near, camera->far);

    
    HMM_Mat4 view_proj = HMM_Mul(projection, view);
    return view_proj;
}
