implement camera rotation on chase camera

This commit is contained in:
2025-10-02 20:09:47 +02:00
parent fbe6077527
commit b2ffd30f07
2 changed files with 25 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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;
}
_ => { }
}
}