diff options
author | HampusM <hampus@hampusmat.com> | 2024-08-17 13:43:45 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-08-17 13:43:45 +0200 |
commit | 60f6a0b7783d6d3684f22f8def3c1097963aa3ff (patch) | |
tree | f5df89fd47a802c68d0717cdc144a891750780cd /engine/src/camera | |
parent | c4686c2992417545e7a05a6a40ee9f1a8bbf3b96 (diff) |
refactor(engine): remove position field from Camera component
Diffstat (limited to 'engine/src/camera')
-rw-r--r-- | engine/src/camera/fly.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/engine/src/camera/fly.rs b/engine/src/camera/fly.rs index ed41253..5b55cec 100644 --- a/engine/src/camera/fly.rs +++ b/engine/src/camera/fly.rs @@ -8,6 +8,7 @@ use crate::camera::Camera; use crate::delta_time::DeltaTime; use crate::event::Update as UpdateEvent; use crate::input::{Cursor, CursorFlags, Keys}; +use crate::transform::Position; use crate::vector::{Vec2, Vec3}; /// Fly camera extension. @@ -38,7 +39,7 @@ pub struct Options } fn update( - camera_query: Query<(Camera,)>, + camera_query: Query<(Camera, Position)>, keys: Single<Keys>, cursor: Single<Cursor>, cursor_flags: Single<CursorFlags>, @@ -47,7 +48,7 @@ fn update( options: Local<Options>, ) { - let Some((mut camera,)) = camera_query.iter().next() else { + let Some((mut camera, mut camera_pos)) = camera_query.iter().next() else { #[cfg(feature = "debug")] tracing::warn!("No camera"); @@ -91,26 +92,29 @@ fn update( camera.global_up = cam_right.cross(&direction).normalize(); if matches!(keys.get_key_state(Key::W), KeyState::Pressed) { - camera.position += direction * options.camera_speed * delta_time.as_secs_f32(); + camera_pos.position += + direction * options.camera_speed * delta_time.as_secs_f32(); } if matches!(keys.get_key_state(Key::S), KeyState::Pressed) { - camera.position -= direction * options.camera_speed * delta_time.as_secs_f32(); + camera_pos.position -= + direction * options.camera_speed * delta_time.as_secs_f32(); } if matches!(keys.get_key_state(Key::A), KeyState::Pressed) { let cam_left = -direction.cross(&Vec3::UP).normalize(); - camera.position += cam_left * options.camera_speed * delta_time.as_secs_f32(); + camera_pos.position += cam_left * options.camera_speed * delta_time.as_secs_f32(); } if matches!(keys.get_key_state(Key::D), KeyState::Pressed) { let cam_right = direction.cross(&Vec3::UP).normalize(); - camera.position += cam_right * options.camera_speed * delta_time.as_secs_f32(); + camera_pos.position += + cam_right * options.camera_speed * delta_time.as_secs_f32(); } - camera.target = camera.position + direction; + camera.target = camera_pos.position + direction; } #[derive(Debug, Component)] |