summaryrefslogtreecommitdiff
path: root/src/renderer/Camera.zig
diff options
context:
space:
mode:
authorLorenzo Torres <torres@sideros.org>2025-03-29 14:51:31 +0100
committerLorenzo Torres <torres@sideros.org>2025-03-29 14:51:31 +0100
commitfd7973173f163e068deb0ae8f9d6ff0fc31fc71b (patch)
tree3d4af1de3a1d1eab487da6368b32fb3dca9e5f69 /src/renderer/Camera.zig
parent4a43e564d7a137097a8403f807b63a2998e0c090 (diff)
Added cursor input management
Diffstat (limited to 'src/renderer/Camera.zig')
-rw-r--r--src/renderer/Camera.zig26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/renderer/Camera.zig b/src/renderer/Camera.zig
index 9794da3..9ab305c 100644
--- a/src/renderer/Camera.zig
+++ b/src/renderer/Camera.zig
@@ -15,7 +15,31 @@ position: @Vector(3, f32),
target: @Vector(3, f32),
direction: @Vector(3, f32),
right: @Vector(3, f32),
+front: @Vector(3, f32),
up: @Vector(3, f32),
+speed: f32 = 2.5,
-fn input(pool: *ecs.Pool) void {
+fn getProjection(width: usize, height: usize) math.Matrix {
+ return math.Matrix.perspective(math.rad(45.0), (@as(f32, @floatFromInt(width)) / @as(f32, @floatFromInt(height))), 0.1, 10.0);
+}
+
+fn getView(self: Camera) math.Matrix {
+ math.lookAt(self.position, self.position + self.front, self.up);
+}
+
+fn moveCamera(pool: *ecs.Pool) void {
+ const input = pool.resources.input;
+ const camera = pool.resources.camera;
+ if (input.isKeyDown(.w)) {
+ camera.position += (camera.front * (camera.speed * pool.resources.delta_time));
+ }
+ if (input.isKeyDown(.s)) {
+ camera.position -= (camera.front * (camera.speed * pool.resources.delta_time));
+ }
+ if (input.isKeyDown(.a)) {
+ camera.position -= math.normalize(math.cross(camera.front, camera.up)) * (camera.speed * pool.resources.delta_time);
+ }
+ if (input.isKeyDown(.d)) {
+ camera.position += math.normalize(math.cross(camera.front, camera.up)) * (camera.speed * pool.resources.delta_time);
+ }
}