implement camera rotation on chase camera
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
_ => { }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user