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"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
[features]
|
||||||
|
gizmos = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
argh = "0.1"
|
argh = "0.1"
|
||||||
|
|
30
src/lib.rs
30
src/lib.rs
|
@ -1,9 +1,9 @@
|
||||||
use argh::FromArgs;
|
use argh::FromArgs;
|
||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::{
|
prelude::{
|
||||||
BuildChildren, ButtonInput, Camera, ChildBuild, Color, Commands, Component, Deref,
|
BuildChildren, ButtonInput, Camera, ChildBuild, Commands, Component, Deref, DerefMut,
|
||||||
DerefMut, Entity, Gizmos, Handle, KeyCode, Quat, Query, Res, ResMut, Resource, Scene,
|
Entity, Gizmos, Handle, KeyCode, Quat, Query, Res, ResMut, Resource, Scene, SceneRoot,
|
||||||
SceneRoot, Time, Transform, Vec3, Visibility, With,
|
Time, Transform, Vec3, Visibility, With,
|
||||||
},
|
},
|
||||||
utils::{HashMap, HashSet},
|
utils::{HashMap, HashSet},
|
||||||
};
|
};
|
||||||
|
@ -47,6 +47,9 @@ pub struct Toid {
|
||||||
pub buddies: usize,
|
pub buddies: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Gizmoid;
|
||||||
|
|
||||||
#[derive(Resource, Debug, Deref, DerefMut, Clone, Default)]
|
#[derive(Resource, Debug, Deref, DerefMut, Clone, Default)]
|
||||||
pub struct Paused(bool);
|
pub struct Paused(bool);
|
||||||
|
|
||||||
|
@ -73,11 +76,15 @@ pub fn turkey_time(
|
||||||
|
|
||||||
commands
|
commands
|
||||||
.spawn(spatial_bundle)
|
.spawn(spatial_bundle)
|
||||||
.insert((Velocity(dir), Buddies::default(), Toid { speed, buddies }))
|
.insert((
|
||||||
|
Velocity(dir),
|
||||||
|
Buddies::default(),
|
||||||
|
Toid { speed, buddies },
|
||||||
|
Gizmoid,
|
||||||
|
))
|
||||||
.with_children(|t| {
|
.with_children(|t| {
|
||||||
t.spawn(SceneRoot(scene.to_owned()))
|
t.spawn(SceneRoot(scene.to_owned()))
|
||||||
.insert(Transform::from_rotation(boid_rot));
|
.insert(Transform::from_rotation(boid_rot));
|
||||||
//.insert(Transform::default());
|
|
||||||
})
|
})
|
||||||
.id()
|
.id()
|
||||||
}
|
}
|
||||||
|
@ -204,16 +211,9 @@ pub fn update_buddies(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_gizmos(toids: Query<&Transform, With<Toid>>, mut gizmos: Gizmos) {
|
pub fn update_gizmos(toids: Query<&Transform, With<Gizmoid>>, mut gizmos: Gizmos) {
|
||||||
for toid in toids.iter() {
|
for &toid in &toids {
|
||||||
let pos = toid.translation;
|
gizmos.axes(toid, 0.7);
|
||||||
//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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,12 +35,12 @@ fn main() {
|
||||||
.insert_resource(LookAt::default())
|
.insert_resource(LookAt::default())
|
||||||
.insert_resource(Paused::default())
|
.insert_resource(Paused::default())
|
||||||
.add_systems(Startup, (setup, setup_ambient_light))
|
.add_systems(Startup, (setup, setup_ambient_light))
|
||||||
//.add_systems(Update, update_gizmos)
|
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(update_pos, update_buddies, update_vel).run_if(not_paused),
|
(update_pos, update_buddies, update_vel).run_if(not_paused),
|
||||||
)
|
)
|
||||||
.add_systems(Update, (rotate_camera, close_on_esc))
|
.add_systems(Update, (rotate_camera, close_on_esc))
|
||||||
|
.add_systems(Update, update_gizmos.run_if(do_gizmos))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,3 +123,10 @@ fn setup_ambient_light(mut ambient_light: ResMut<AmbientLight>) {
|
||||||
fn not_paused(paused: Option<Res<Paused>>) -> bool {
|
fn not_paused(paused: Option<Res<Paused>>) -> bool {
|
||||||
!paused.map(|p| **p).unwrap_or(false)
|
!paused.map(|p| **p).unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn do_gizmos() -> bool {
|
||||||
|
#[cfg(feature = "gizmos")]
|
||||||
|
return true;
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue