summaryrefslogtreecommitdiff
path: root/src/3d/camera.h
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-01 10:51:15 +0100
committerskal <pascal.massimino@gmail.com>2026-02-01 10:51:15 +0100
commit8bdc4754647c9c6691130fa91d51fee93c5fc88f (patch)
tree2cfd7f72a21541c488ea48629eef47a6774fc2c4 /src/3d/camera.h
parent7905abd9f7ad35231289e729b42e3ad57a943ff5 (diff)
feat: Implement 3D system and procedural texture manager
- Extended mini_math.h with mat4 multiplication and affine transforms. - Implemented TextureManager for runtime procedural texture generation and GPU upload. - Added 3D system components: Camera, Object, Scene, and Renderer3D. - Created test_3d_render mini-demo for interactive 3D verification. - Fixed WebGPU validation errors regarding depthSlice and unimplemented WaitAny.
Diffstat (limited to 'src/3d/camera.h')
-rw-r--r--src/3d/camera.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/3d/camera.h b/src/3d/camera.h
new file mode 100644
index 0000000..23e26d6
--- /dev/null
+++ b/src/3d/camera.h
@@ -0,0 +1,39 @@
+// This file is part of the 64k demo project.
+// It defines the Camera class for 3D navigation and rendering.
+// Handles view and projection matrix generation.
+
+#pragma once
+
+#include "util/mini_math.h"
+
+class Camera {
+ public:
+ vec3 position;
+ vec3 target;
+ vec3 up;
+
+ float fov_y_rad;
+ float aspect_ratio;
+ float near_plane;
+ float far_plane;
+
+ Camera()
+ : position(0, 0, 5), target(0, 0, 0), up(0, 1, 0), fov_y_rad(0.785398f),
+ aspect_ratio(1.777f), near_plane(0.1f), far_plane(100.0f) {
+ }
+
+ mat4 get_view_matrix() const {
+ return mat4::look_at(position, target, up);
+ }
+
+ mat4 get_projection_matrix() const {
+ return mat4::perspective(fov_y_rad, aspect_ratio, near_plane, far_plane);
+ }
+
+ // Helper to move camera
+ void set_look_at(vec3 pos, vec3 tgt, vec3 up_vec = vec3(0, 1, 0)) {
+ position = pos;
+ target = tgt;
+ up = up_vec;
+ }
+};