From b2ffd30f076993d6d9d79bc47210ff3fe87d59c3 Mon Sep 17 00:00:00 2001 From: fredrikr79 Date: Thu, 2 Oct 2025 20:09:47 +0200 Subject: [PATCH] implement camera rotation on chase camera --- gloom-rs/src/draw.rs | 11 +++++++++++ gloom-rs/src/main.rs | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gloom-rs/src/draw.rs b/gloom-rs/src/draw.rs index 52c10a3..70f24b3 100644 --- a/gloom-rs/src/draw.rs +++ b/gloom-rs/src/draw.rs @@ -77,6 +77,17 @@ impl ChaseCamera { yaw: 0.0 } } + + pub fn forward(&self) -> glm::Vec3 { + let f_xz = glm::vec3(-self.yaw.sin(), self.yaw.cos(), 0.0); + glm::vec3(f_xz.x, f_xz.z, f_xz.y) + } + + pub fn right(&self) -> glm::Vec3 { + let f_xz = glm::vec3(-self.yaw.sin(), self.yaw.cos(), 0.0); + let r_xz = glm::rotation2d(glm::half_pi()) * f_xz; + glm::vec3(r_xz.x, r_xz.z, r_xz.y) + } } pub struct World { diff --git a/gloom-rs/src/main.rs b/gloom-rs/src/main.rs index f35d7b0..aa17d28 100644 --- a/gloom-rs/src/main.rs +++ b/gloom-rs/src/main.rs @@ -135,10 +135,24 @@ fn main() { } } + let translation_speed = 1.0; + // Handle keyboard input if let Ok(keys) = pressed_keys.lock() { for key in keys.iter() { match key { + VirtualKeyCode::Right => { + world.camera.position -= world.camera.right() * translation_speed; + } + VirtualKeyCode::Left => { + world.camera.position += world.camera.right() * translation_speed; + } + VirtualKeyCode::Down => { + world.camera.position.y -= translation_speed; + } + VirtualKeyCode::Up => { + world.camera.position.y += translation_speed; + } _ => { } } }