summaryrefslogtreecommitdiff
path: root/src/core/camera.c
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-07-11 18:03:29 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-07-11 18:03:29 +1000
commit65d74bdb26af833b5380046dec204f685f745cc1 (patch)
tree6a913e8b47787fff9f4650963074ea3f8ab5de27 /src/core/camera.c
parent3103f383751a12f8a0bdb22309704f1f826d204c (diff)
changing styles plus simplifying a bit
Diffstat (limited to 'src/core/camera.c')
-rw-r--r--src/core/camera.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/core/camera.c b/src/core/camera.c
new file mode 100644
index 0000000..50c4054
--- /dev/null
+++ b/src/core/camera.c
@@ -0,0 +1,22 @@
+#include "camera.h"
+
+#include "maths.h"
+
+Camera Camera_Create(vec3 pos, vec3 front, vec3 up, f32 fov) {
+ Camera c = { .position = pos, .front = front, .up = up, .fov = fov };
+ return c;
+}
+
+mat4 Camera_ViewProj(Camera *c, f32 lens_height, f32 lens_width, mat4 *out_view,
+ mat4 *out_proj) {
+ mat4 proj = mat4_perspective(c->fov, lens_width / lens_height, 0.1, 100.0);
+ vec3 camera_direction = vec3_add(c->position, c->front);
+ mat4 view = mat4_look_at(c->position, camera_direction, c->up);
+ if (out_view) {
+ *out_view = view;
+ }
+ if (out_proj) {
+ *out_proj = proj;
+ }
+ return mat4_mult(view, proj);
+}