summaryrefslogtreecommitdiff
path: root/engine/src/camera/fly.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/camera/fly.rs')
-rw-r--r--engine/src/camera/fly.rs25
1 files changed, 7 insertions, 18 deletions
diff --git a/engine/src/camera/fly.rs b/engine/src/camera/fly.rs
index 0651e58..5f5ab4b 100644
--- a/engine/src/camera/fly.rs
+++ b/engine/src/camera/fly.rs
@@ -14,7 +14,7 @@ use crate::input::keyboard::{Key, Keyboard};
use crate::input::mouse::Mouse;
use crate::reflection::Reflection;
use crate::transform::Transform;
-use crate::vector::{Vec2, Vec3};
+use crate::vector::{Angles, Vec2, Vec3};
builder! {
/// A fly camera.
@@ -22,8 +22,7 @@ builder! {
#[derive(Debug, Component, Reflection)]
#[non_exhaustive]
pub struct Fly {
- pub current_pitch: f64,
- pub current_yaw: f64,
+ pub angles: Angles<f32>,
pub speed: f32,
}
}
@@ -50,8 +49,7 @@ impl Default for Builder
fn default() -> Self
{
Self {
- current_yaw: -90.0,
- current_pitch: 0.0,
+ angles: Vec3::BACK.into_deg_angles(),
speed: 3.0,
}
}
@@ -112,22 +110,13 @@ fn update(
let y_offset = (-mouse.curr_tick_position_delta.y)
* f64::from(options.mouse_sensitivity);
- fly_camera.current_yaw += x_offset;
- fly_camera.current_pitch += y_offset;
+ fly_camera.angles.yaw += x_offset as f32;
+ fly_camera.angles.pitch += y_offset as f32;
- fly_camera.current_pitch = fly_camera.current_pitch.clamp(-89.0, 89.0);
+ fly_camera.angles.pitch = fly_camera.angles.pitch.clamp(-89.0, 89.0);
}
- // TODO: This casting to a f32 from a f64 is horrible. fix it
- #[allow(clippy::cast_possible_truncation)]
- let direction = Vec3 {
- x: (fly_camera.current_yaw.to_radians().cos()
- * fly_camera.current_pitch.to_radians().cos()) as f32,
- y: fly_camera.current_pitch.to_radians().sin() as f32,
- z: (fly_camera.current_yaw.to_radians().sin()
- * fly_camera.current_pitch.to_radians().cos()) as f32,
- }
- .normalize();
+ let direction = Vec3::direction_from_deg_angles(fly_camera.angles);
let cam_right = direction.cross(&Vec3::UP).normalize();