fix gizmos, make them a feature
This commit is contained in:
parent
84d0bec5f1
commit
96e21eadad
3 changed files with 25 additions and 17 deletions
|
@ -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"
|
||||
|
|
30
src/lib.rs
30
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<Toid>>, 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<Gizmoid>>, mut gizmos: Gizmos) {
|
||||
for &toid in &toids {
|
||||
gizmos.axes(toid, 0.7);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<AmbientLight>) {
|
|||
fn not_paused(paused: Option<Res<Paused>>) -> bool {
|
||||
!paused.map(|p| **p).unwrap_or(false)
|
||||
}
|
||||
|
||||
fn do_gizmos() -> bool {
|
||||
#[cfg(feature = "gizmos")]
|
||||
return true;
|
||||
|
||||
false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue