halfway through imgui, the context is really not ergonomic

This commit is contained in:
2021-02-14 18:07:26 -08:00
parent 60ab3bebd8
commit 2370ce4974
6 changed files with 209 additions and 94 deletions

View File

@@ -136,16 +136,14 @@ impl CameraController {
pub fn update_camera(&mut self, camera: &mut Camera, dt: f32) {
// Move forward/backward and left/right
let (yaw_sin, yaw_cos) = camera.yaw.0.sin_cos();
let forward = Vector3::new(yaw_cos, 0.0, yaw_sin).normalize();
let right = Vector3::new(-yaw_sin, 0.0, yaw_cos).normalize();
let view_vector = Vector3::new(
(1.0 * camera.pitch.0.sin() * camera.yaw.0.sin()),
(1.0 * camera.pitch.0.cos()),
(1.0 * camera.pitch.0.sin() * camera.yaw.0.cos()),
);
// Offset the yaw 90 degrees and set the pitch to level for our
// right / left hand translation vectors
let offset = camera.yaw.0 + PI/2.0;
let pitch = PI/2.0;
let left_vector = Vector3::new(
@@ -156,19 +154,12 @@ impl CameraController {
camera.position += view_vector * (self.amount_forward - self.amount_backward) * self.speed * dt;
camera.position += left_vector * (self.amount_left - self.amount_right) * self.speed * dt;
// Move up/down. Since we don't use roll, we can just
// modify the y coordinate directly.
camera.position.y += (self.amount_up - self.amount_down) * self.speed * dt;
// Rotate
camera.yaw += Rad(self.rotate_horizontal) * self.sensitivity * dt;
camera.pitch += Rad(self.rotate_vertical) * self.sensitivity * dt;
// If process_mouse isn't called every frame, these values
// will not get set to zero, and the camera will rotate
// when moving in a non cardinal direction.
self.rotate_horizontal = 0.0;
self.rotate_vertical = 0.0;