diff --git a/src/flycam.rs b/src/flycam.rs index cc301c3..cce5d94 100644 --- a/src/flycam.rs +++ b/src/flycam.rs @@ -10,7 +10,7 @@ use bevy_flycam::{FlyCam, KeyBindings, MovementSettings, NoCameraPlayerPlugin}; use big_space::{FloatingOrigin, FloatingOriginSettings}; use crate::geopos::EARTH_RADIUS; -use crate::GalacticGrid; +use crate::{GalacticGrid, GalacticTransform}; pub struct Plugin; @@ -126,11 +126,10 @@ fn setup( fn update_camera_speed( mut movement_settings: ResMut, - fly_cam: Query<(&Transform, &GalacticGrid), With>, + fly_cam: Query>, space: Res, ) { - let (transform, grid) = fly_cam.single(); - let elevation = space.grid_position_double(grid, transform).length() as f32; + let elevation = fly_cam.single().grid_position_double(&space).length() as f32; let speed = (1. * (elevation - crate::geopos::EARTH_RADIUS - 300.0)).max(100.0); movement_settings.speed = speed; } diff --git a/src/lib.rs b/src/lib.rs index ce98ccc..f2bd1e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ use std::f32::consts::FRAC_PI_2; use bevy::{ diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, + ecs::query::WorldQuery, pbr::NotShadowCaster, prelude::*, }; @@ -255,7 +256,7 @@ mod player; fn reposition_compass( mut compass: Query< - (&mut Transform, &mut GalacticGrid), + GalacticTransform, (With, Without, Without), >, mut commands: Commands, @@ -264,12 +265,12 @@ fn reposition_compass( server: Res, player: player::Player, ) { - if let Ok((mut pos, mut grid)) = compass.get_single_mut() { + if let Ok(mut compass) = compass.get_single_mut() { let player = player.pos(); let directions = player.directions(); - pos.translation = player.transform.translation - directions.up * 5.; - *grid = player.grid; - pos.look_to(directions.north, directions.up) + compass.transform.translation = player.transform.translation - directions.up * 5.; + *compass.grid = *player.grid; + compass.transform.look_to(directions.north, directions.up) } else { let mesh = shape::Plane::default(); let mesh = meshes.add(mesh.into()); @@ -298,34 +299,54 @@ fn reposition_compass( fn update_camera_orientations( mut movement_settings: ResMut, - fly_cam: Query<(&Transform, &GalacticGrid), With>, + fly_cam: Query>, space: Res, ) { - let (transform, grid) = fly_cam.single(); - movement_settings.up = space - .grid_position_double(grid, transform) + movement_settings.up = fly_cam + .single() + .grid_position_double(&space) .normalize() .as_vec3(); } fn pull_to_ground( time: Res