From 513e3d89eff870fb5658225acae1c8ae0563a545 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 19 Apr 2024 03:54:17 +0200 Subject: [PATCH] center map around targeted object --- src/camera.rs | 10 ++++++++-- src/world.rs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index e0b3e18..e7b0ee8 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -115,6 +115,7 @@ pub fn update_map_camera( mut mapcam: ResMut, mut q_camera: Query<&mut Transform, (With, Without)>, q_playercam: Query<&Transform, (With, Without)>, + q_target: Query<&Transform, (With, Without, Without)>, mut mouse_events: EventReader, keyboard_input: Res>, ) { @@ -123,6 +124,11 @@ pub fn update_map_camera( } let mut camera_transform = q_camera.get_single_mut().unwrap(); let player_transform = q_playercam.get_single().unwrap(); + let target = if let Ok(target) = q_target.get_single() { + target + } else { + player_transform + }; // Get mouse movement let mut mouse_delta = Vec2::ZERO; @@ -151,8 +157,8 @@ pub fn update_map_camera( let point_of_view = pov_rotation * (mapcam.zoom_level * Vec3::new(1.0, 0.0, 0.0)); // Apply updates to camera - camera_transform.translation = player_transform.translation + point_of_view; - camera_transform.look_at(player_transform.translation, Vec3::Y); + camera_transform.translation = target.translation + point_of_view; + camera_transform.look_at(target.translation, Vec3::Y); } pub fn update_fov( diff --git a/src/world.rs b/src/world.rs index 14f62a7..f38a8f3 100644 --- a/src/world.rs +++ b/src/world.rs @@ -116,7 +116,7 @@ pub fn setup( let sphere_handle = meshes.add(Sphere::new(1.0).mesh().uv(16, 16)); let mut starcount = 0; for (index, star) in nature::STARS.iter().enumerate() { - let (x, y, z, mag, absmag, color_index, radius, name) = *star; + let (x, y, z, mag, _absmag, color_index, name) = *star; if mag > STARS_MAX_MAGNITUDE { continue; }