~starkingdoms/starkingdoms

268047aaf3cc14686d94757d6232fc5083cc2d49 — ghostly_zsh 17 days ago f5b36bb
fix: orbit predictor is now actually positioned correctly on the screen
M crates/unified/src/client/starguide/init.rs => crates/unified/src/client/starguide/init.rs +1 -1
@@ 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,
    );

M crates/unified/src/client/starguide/orbit.rs => crates/unified/src/client/starguide/orbit.rs +19 -8
@@ 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<StarguideOrbitImage>,
    mut images: ResMut<Assets<Image>>,
    camera: Single<&Camera, With<StarguideCamera>>,
    camera: Single<(&Camera, &GlobalTransform, &Projection), With<StarguideCamera>>,
    me: Single<&Transform, (With<Me>, Without<StarguideCamera>)>,
    orbit: Single<&Transform, (With<StarguideOrbit>, Without<Me>, Without<StarguideCamera>)>,
) {
    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,
        });
    }