gearlib-cpp/src/camera.cpp
2024-05-16 22:37:46 +12:00

28 lines
822 B
C++

#include <gearlib.h>
#include <stdlib.h>
Camera* create_camera(vec2 pos) {
Camera* camera = new Camera();
camera->position = vec3(pos.x, pos.y, -3.0f);
camera->m = new CameraMatrices();
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;
}
}