From 268047aaf3cc14686d94757d6232fc5083cc2d49 Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Fri, 28 Nov 2025 16:22:44 -0600 Subject: [PATCH] fix: orbit predictor is now actually positioned correctly on the screen --- crates/unified/src/client/starguide/init.rs | 2 +- crates/unified/src/client/starguide/orbit.rs | 27 ++++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/crates/unified/src/client/starguide/init.rs b/crates/unified/src/client/starguide/init.rs index 48026fef48bcecd7d60ccaba42cb6b06edd90df5..9a8b0e7b5c7545901c4f940797fe1a378c625ed6 100644 --- a/crates/unified/src/client/starguide/init.rs +++ b/crates/unified/src/client/starguide/init.rs @@ -47,7 +47,7 @@ pub fn init_starguide( height: window.height() as u32, depth_or_array_layers: 1, }, TextureDimension::D2, - &(Color::BLACK.to_srgba().to_u8_array()), + &(Color::WHITE.to_srgba().to_u8_array()), TextureFormat::Rgba8UnormSrgb, RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD, ); diff --git a/crates/unified/src/client/starguide/orbit.rs b/crates/unified/src/client/starguide/orbit.rs index fbcb38c931ba77ca447f3d359c9440b0d508b49d..2c0d9f93b9c1a3791ce3dee495362ac0834c9991 100644 --- a/crates/unified/src/client/starguide/orbit.rs +++ b/crates/unified/src/client/starguide/orbit.rs @@ -1,6 +1,6 @@ use bevy::window::WindowResized; -use crate::{ecs::{StarguideCamera, StarguideOrbitImage}, prelude::*}; +use crate::{ecs::{Me, StarguideCamera, StarguideOrbit, StarguideOrbitImage}, prelude::*}; use bevy::render::render_resource::Extent3d; pub fn starguide_orbit_plugin(app: &mut App) { @@ -11,16 +11,27 @@ pub fn starguide_orbit_plugin(app: &mut App) { fn update_orbits( orbit_image: Res, mut images: ResMut>, - camera: Single<&Camera, With>, + camera: Single<(&Camera, &GlobalTransform, &Projection), With>, + me: Single<&Transform, (With, Without)>, + orbit: Single<&Transform, (With, Without, Without)>, ) { let Some(image) = images.get_mut(&orbit_image.0) else { error!("Orbit prediction image not found"); return }; - image.clear(&(Color::BLACK.to_srgba().to_u8_array())); + let Projection::Orthographic(ref projection) = camera.2.clone() else { return }; + image.clear(&(Color::WHITE.to_srgba().to_u8_array())); + + let player_pos = me.translation - orbit.translation; + let player_pos = Vec3::new(player_pos.x, -player_pos.y, player_pos.z); + let player_pos = (player_pos / projection.scale).truncate(); + let player_pos = player_pos + image.size_f32()/2.0; + let player_pos = player_pos.as_uvec2(); - for i in 0..100 { - image.set_color_at(i, 100, Color::linear_rgb(1.0, 0.0, 0.0)).unwrap(); + for i in (player_pos.x)..(player_pos.x+100) { + if !(i >= image.size().x || player_pos.y >= image.size().y) { + image.set_color_at(i, player_pos.y, Color::linear_rgb(1.0, 0.0, 0.0)).unwrap(); + } } } @@ -35,12 +46,12 @@ fn window_resize( return }; for _ in resize_ev.read() { - let Some(UVec2 {x: width, y: height}) = camera.physical_target_size() else { + let Some(Vec2 {x: width, y: height}) = camera.logical_viewport_size() else { continue }; image.resize(Extent3d { - width: width, - height: height, + width: width as u32, + height: height as u32, depth_or_array_layers: 1, }); }