center map around targeted object
This commit is contained in:
parent
7d85a93449
commit
513e3d89ef
|
@ -115,6 +115,7 @@ pub fn update_map_camera(
|
||||||
mut mapcam: ResMut<MapCam>,
|
mut mapcam: ResMut<MapCam>,
|
||||||
mut q_camera: Query<&mut Transform, (With<Camera>, Without<actor::PlayerCamera>)>,
|
mut q_camera: Query<&mut Transform, (With<Camera>, Without<actor::PlayerCamera>)>,
|
||||||
q_playercam: Query<&Transform, (With<actor::PlayerCamera>, Without<Camera>)>,
|
q_playercam: Query<&Transform, (With<actor::PlayerCamera>, Without<Camera>)>,
|
||||||
|
q_target: Query<&Transform, (With<hud::IsTargeted>, Without<Camera>, Without<actor::PlayerCamera>)>,
|
||||||
mut mouse_events: EventReader<MouseMotion>,
|
mut mouse_events: EventReader<MouseMotion>,
|
||||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
|
@ -123,6 +124,11 @@ pub fn update_map_camera(
|
||||||
}
|
}
|
||||||
let mut camera_transform = q_camera.get_single_mut().unwrap();
|
let mut camera_transform = q_camera.get_single_mut().unwrap();
|
||||||
let player_transform = q_playercam.get_single().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
|
// Get mouse movement
|
||||||
let mut mouse_delta = Vec2::ZERO;
|
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));
|
let point_of_view = pov_rotation * (mapcam.zoom_level * Vec3::new(1.0, 0.0, 0.0));
|
||||||
|
|
||||||
// Apply updates to camera
|
// Apply updates to camera
|
||||||
camera_transform.translation = player_transform.translation + point_of_view;
|
camera_transform.translation = target.translation + point_of_view;
|
||||||
camera_transform.look_at(player_transform.translation, Vec3::Y);
|
camera_transform.look_at(target.translation, Vec3::Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_fov(
|
pub fn update_fov(
|
||||||
|
|
|
@ -116,7 +116,7 @@ pub fn setup(
|
||||||
let sphere_handle = meshes.add(Sphere::new(1.0).mesh().uv(16, 16));
|
let sphere_handle = meshes.add(Sphere::new(1.0).mesh().uv(16, 16));
|
||||||
let mut starcount = 0;
|
let mut starcount = 0;
|
||||||
for (index, star) in nature::STARS.iter().enumerate() {
|
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 {
|
if mag > STARS_MAX_MAGNITUDE {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue