From 6516d7c756f9f5aaeaaae2e871a7e53c65174cc3 Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Sat, 29 Nov 2025 12:47:28 -0600 Subject: [PATCH] fix: orbit indicator is continuous --- crates/unified/src/client/mod.rs | 3 ++- crates/unified/src/client/rendering/mod.rs | 8 ++++---- crates/unified/src/client/starguide/orbit.rs | 19 +++++++++++++------ crates/unified/src/ecs.rs | 3 +++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/crates/unified/src/client/mod.rs b/crates/unified/src/client/mod.rs index 099e9e4d3888c421b50e42828e302b0c95660bc9..0f7a626804bc450844e0de3495e718ed7146c1cd 100644 --- a/crates/unified/src/client/mod.rs +++ b/crates/unified/src/client/mod.rs @@ -7,7 +7,7 @@ use crate::client::ui::ui_plugin; use crate::client::zoom::zoom_plugin; use crate::client::starguide::init::starguide_init_plugin; use crate::client::starguide::input::starguide_input_plugin; -use crate::ecs::{Hi, Part, Player}; +use crate::ecs::{Hi, Part, Player, StarguideGizmos}; use aeronet_websocket::client::WebSocketClient; use bevy::dev_tools::picking_debug::DebugPickingMode; use crate::prelude::*; @@ -46,6 +46,7 @@ impl Plugin for ClientPlugin { .spawn(Name::new("default-session")) .queue(WebSocketClient::connect(config, server.clone())); }) + .init_gizmo_group::() .add_plugins(rendering::render_plugin) .add_plugins(input::input_plugin) .add_plugins(ship::thrusters::client_thrusters_plugin) diff --git a/crates/unified/src/client/rendering/mod.rs b/crates/unified/src/client/rendering/mod.rs index 464a33b69e0b38ebfe05636336330b4fd017549a..9683859aaf8cc2defc685020a90fdf5ce5046b58 100644 --- a/crates/unified/src/client/rendering/mod.rs +++ b/crates/unified/src/client/rendering/mod.rs @@ -2,7 +2,7 @@ use bevy::anti_alias::fxaa::Fxaa; use bevy::app::{App, Startup}; use bevy::core_pipeline::tonemapping::DebandDither; use bevy::post_process::bloom::Bloom; -use crate::ecs::{GameplayState, MAIN_LAYER, MAIN_STAR_LAYERS, MainCamera, Me, StarguideCamera}; +use crate::ecs::{GameplayState, MAIN_LAYER, MAIN_STAR_LAYERS, MainCamera, Me, STARGUIDE_LAYER, StarguideCamera, StarguideGizmos}; use crate::prelude::*; pub fn render_plugin(app: &mut App) { @@ -24,9 +24,9 @@ pub fn setup_graphics(mut config_store: ResMut, mut commands: .insert(DebandDither::Enabled) .insert(Fxaa::default()) .insert(MainCamera); - for (_, config, _) in config_store.iter_mut() { - config.render_layers = MAIN_STAR_LAYERS.clone(); - } + let (gizmo_config, _) = config_store.config_mut::(); + gizmo_config.render_layers = STARGUIDE_LAYER; + gizmo_config.depth_bias = 1.0; } fn follow_camera( diff --git a/crates/unified/src/client/starguide/orbit.rs b/crates/unified/src/client/starguide/orbit.rs index 051d675c6f3668ad61f8b4876dd0b6f9127e2a33..262c9b57b952f2dc7908abe2a6c27aa29852b633 100644 --- a/crates/unified/src/client/starguide/orbit.rs +++ b/crates/unified/src/client/starguide/orbit.rs @@ -2,7 +2,7 @@ use std::{f32::consts::PI, ops::Range}; use bevy::window::WindowResized; -use crate::{config::planet::Planet, ecs::{Me, StarguideCamera, StarguideOrbit, StarguideOrbitImage}, prelude::*, world_config::WorldConfigResource}; +use crate::{config::planet::Planet, ecs::{Me, StarguideCamera, StarguideGizmos, StarguideOrbit, StarguideOrbitImage}, prelude::*, world_config::WorldConfigResource}; use bevy::render::render_resource::Extent3d; pub fn starguide_orbit_plugin(app: &mut App) { @@ -16,7 +16,7 @@ fn update_orbits( camera: Single<(&Camera, &GlobalTransform, &Projection), With>, me: Single<(&Transform, &LinearVelocity), (With, Without)>, //orbit: Single<&Transform, (With, Without, Without)>, - mut gizmos: Gizmos, + mut gizmos: Gizmos, world_config: Res, planets: Query<(&Mass, &Planet, &Transform)>, ) { @@ -61,11 +61,14 @@ fn update_orbits( let f_y = -2.0*a*e_y; // 200 steps in the revolution - let mut last_pos = Vec2::ZERO; + let mut first_pos = None; + let mut last_pos = None; for i in 0..200 { let theta = 2.0*PI*(i as f32)/200.0; let r = (1.0/2.0) * ((f_x*f_x + f_y*f_y - 4.0*a*a) / (-2.0*a - f_x*theta.cos() - f_y*theta.sin())); + if r < 0.0 { continue } + // convert r to image coords let pos = Vec2::new(r*theta.cos(), r*theta.sin()) + p_transform.translation.truncate(); /*let pos = pos + p_transform.translation.truncate() - orbit.translation.truncate(); @@ -74,10 +77,14 @@ fn update_orbits( let pos = pos + image.size_f32()/2.0;*/ //if !(pos.x as u32 >= image.size().x || pos.y as u32 >= image.size().y) && i != 0 { - if i != 0 { - gizmos.line_2d(last_pos, pos, Color::linear_rgb(1.0, 0.0, 0.0)); + if last_pos.is_some() { + gizmos.line_2d(last_pos.unwrap(), pos, Color::linear_rgb(1.0, 0.0, 0.0)); } - last_pos = pos; + if first_pos.is_none() { first_pos = Some(pos) } + last_pos = Some(pos); + } + if first_pos.is_some() && last_pos.is_some() { + gizmos.line_2d(first_pos.unwrap(), last_pos.unwrap(), Color::linear_rgb(1.0, 0.0, 0.0)); } } diff --git a/crates/unified/src/ecs.rs b/crates/unified/src/ecs.rs index 55dd47b2c3526e2a9dc05cc87bccb98411d3a237..35e3a17d0f34b59346d596a6451ac6d840f76ec3 100644 --- a/crates/unified/src/ecs.rs +++ b/crates/unified/src/ecs.rs @@ -29,6 +29,9 @@ pub struct StarguideCamera; #[derive(Component)] pub struct OrbitCamera; +#[derive(Default, Reflect, GizmoConfigGroup)] +pub struct StarguideGizmos; + #[derive(Component)] pub struct StarfieldFront; #[derive(Component)]