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.rs18
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)]