From 96e21eadad8f97194ce257a46b86147282a05d9c Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Fri, 29 Nov 2024 10:40:43 -0800 Subject: [PATCH] fix gizmos, make them a feature --- Cargo.toml | 3 ++- src/lib.rs | 30 +++++++++++++++--------------- src/main.rs | 9 ++++++++- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index af39349..f57e795 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,8 @@ name = "audubon" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +gizmos = [] [dependencies] argh = "0.1" diff --git a/src/lib.rs b/src/lib.rs index 8c6468f..7617e82 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,9 @@ use argh::FromArgs; use bevy::{ prelude::{ - BuildChildren, ButtonInput, Camera, ChildBuild, Color, Commands, Component, Deref, - DerefMut, Entity, Gizmos, Handle, KeyCode, Quat, Query, Res, ResMut, Resource, Scene, - SceneRoot, Time, Transform, Vec3, Visibility, With, + BuildChildren, ButtonInput, Camera, ChildBuild, Commands, Component, Deref, DerefMut, + Entity, Gizmos, Handle, KeyCode, Quat, Query, Res, ResMut, Resource, Scene, SceneRoot, + Time, Transform, Vec3, Visibility, With, }, utils::{HashMap, HashSet}, }; @@ -47,6 +47,9 @@ pub struct Toid { pub buddies: usize, } +#[derive(Component)] +pub struct Gizmoid; + #[derive(Resource, Debug, Deref, DerefMut, Clone, Default)] pub struct Paused(bool); @@ -73,11 +76,15 @@ pub fn turkey_time( commands .spawn(spatial_bundle) - .insert((Velocity(dir), Buddies::default(), Toid { speed, buddies })) + .insert(( + Velocity(dir), + Buddies::default(), + Toid { speed, buddies }, + Gizmoid, + )) .with_children(|t| { t.spawn(SceneRoot(scene.to_owned())) .insert(Transform::from_rotation(boid_rot)); - //.insert(Transform::default()); }) .id() } @@ -204,16 +211,9 @@ pub fn update_buddies( } } -pub fn update_gizmos(toids: Query<&Transform, With>, mut gizmos: Gizmos) { - for toid in toids.iter() { - let pos = toid.translation; - //dbg!(toid); - let up = toid.up().as_vec3(); - let forward = toid.forward().as_vec3(); - let right = toid.right().as_vec3(); - gizmos.ray(pos, pos + forward, Color::srgb_u8(255, 0, 0)); - gizmos.ray(pos, pos + up, Color::srgb_u8(0, 0, 255)); - gizmos.ray(pos, pos + right, Color::srgb_u8(0, 255, 0)); +pub fn update_gizmos(toids: Query<&Transform, With>, mut gizmos: Gizmos) { + for &toid in &toids { + gizmos.axes(toid, 0.7); } } diff --git a/src/main.rs b/src/main.rs index c3a273d..f41a3d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,12 +35,12 @@ fn main() { .insert_resource(LookAt::default()) .insert_resource(Paused::default()) .add_systems(Startup, (setup, setup_ambient_light)) - //.add_systems(Update, update_gizmos) .add_systems( Update, (update_pos, update_buddies, update_vel).run_if(not_paused), ) .add_systems(Update, (rotate_camera, close_on_esc)) + .add_systems(Update, update_gizmos.run_if(do_gizmos)) .run(); } @@ -123,3 +123,10 @@ fn setup_ambient_light(mut ambient_light: ResMut) { fn not_paused(paused: Option>) -> bool { !paused.map(|p| **p).unwrap_or(false) } + +fn do_gizmos() -> bool { + #[cfg(feature = "gizmos")] + return true; + + false +}