use argh::FromArgs; use bevy::prelude::*; const SPEED: f32 = 1.0; const SPEED_DIFF_RANGE: f32 = 0.08; // +/- 8% const RADIUS: f32 = 1_000.0; pub type Point = [f32; 3]; pub type Toint = rstar::primitives::GeomWithData; #[derive(Debug, FromArgs, Resource)] /// Toid Watching pub struct Config { /// how many Toids to spawn #[argh(option, short = 't', default = "100")] pub toids: usize, } #[derive(Resource, Deref, DerefMut, Default)] pub struct Index(pub rstar::RTree); #[derive(Resource, Deref, DerefMut, Default)] pub struct Positions(pub std::collections::HashMap); #[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 speed: f32, pub buddies: usize, } pub fn turkey_time( commands: &mut Commands, scene: &Handle, r: &mut impl rand::prelude::Rng, ) -> Entity { let speed_diff = r.gen_range(-SPEED_DIFF_RANGE..=SPEED_DIFF_RANGE); let speed = SPEED + (SPEED * speed_diff); let vel = unit_vec(r) * speed; let buddies = r.gen_range(6..=8); commands .spawn(SpatialBundle::default()) .insert((Velocity(vel), Buddies::default(), Toid { speed, buddies })) .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); } } pub fn update_pos( mut toids: Query<(&mut Transform, &Velocity, Entity)>, time: Res