diff options
| author | HampusM <hampus@hampusmat.com> | 2026-08-21 22:38:45 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-08-21 22:38:45 +0200 |
| commit | 908ef391e407b59a0526ca1b2aa149eb6e4c498c (patch) | |
| tree | 9b507955f5b360f312e056a0dbe01a423cfbe400 /engine/src/camera | |
| parent | ffbbe51561393e559b6e70d9e9b39bc025f77d1c (diff) | |
feat(engine): add fns for conversion between vec3 & euler angles
Diffstat (limited to 'engine/src/camera')
| -rw-r--r-- | engine/src/camera/fly.rs | 25 |
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(); |
