use argh::FromArgs; use bevy::prelude::*; #[derive(Debug, FromArgs, Resource)] /// Toid Watching pub struct Config { /// how many Toids to spawn #[argh(option, short = 't', default = "100")] pub toids: usize, } pub type Point = (f32, f32, f32); pub type Toint = rstar::primitives::GeomWithData; pub trait Pointable { fn to_point(&self) -> Point; } impl Pointable for Vec3 { fn to_point(&self) -> Point { (self.x, self.y, self.z) } } #[derive(Resource, Deref, DerefMut)] pub struct Index(pub rstar::RTree); #[derive(Component, Debug, Clone, Deref, DerefMut, Default)] pub struct Buddies(Vec); #[derive(Component, Debug, Clone, Deref, DerefMut, Default)] pub struct Velocity(Vec3); #[derive(Component)] pub struct Toid; pub fn turkey_time(commands: &mut Commands, scene: &Handle) -> Entity { commands .spawn(SpatialBundle::default()) .insert((Velocity::default(), Buddies::default(), Toid)) .with_children(|t| { t.spawn(SceneBundle { scene: scene.to_owned(), ..Default::default() }) .insert(Transform::from_rotation(Quat::from_axis_angle( Vec3::Y, -std::f32::consts::FRAC_PI_2, ))); }) .id() } pub fn add_gizmos(mut gizmos: Gizmos, toids: Query<(&Transform, Entity), With>) { let gizmos = &mut gizmos; for (pos, _entity) in toids.iter() { let nudge = pos.up() * 0.15; let rpos = pos.translation + nudge; gizmos.ray(rpos, pos.forward(), Color::RED); } }