toid blossom
This commit is contained in:
parent
5175604649
commit
5e64325eb6
2 changed files with 22 additions and 23 deletions
36
src/lib.rs
36
src/lib.rs
|
@ -1,9 +1,14 @@
|
|||
use argh::FromArgs;
|
||||
use bevy::prelude::*;
|
||||
|
||||
const SPEED: f32 = 20.0;
|
||||
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<Point, Entity>;
|
||||
|
||||
#[derive(Debug, FromArgs, Resource)]
|
||||
/// Toid Watching
|
||||
pub struct Config {
|
||||
|
@ -12,24 +17,10 @@ pub struct Config {
|
|||
pub toids: usize,
|
||||
}
|
||||
|
||||
pub type Point = (f32, f32, f32);
|
||||
|
||||
pub type Toint = rstar::primitives::GeomWithData<Point, Entity>;
|
||||
|
||||
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)]
|
||||
#[derive(Resource, Deref, DerefMut, Default)]
|
||||
pub struct Index(pub rstar::RTree<Toint>);
|
||||
|
||||
#[derive(Resource, Deref, DerefMut)]
|
||||
#[derive(Resource, Deref, DerefMut, Default)]
|
||||
pub struct Positions(pub std::collections::HashMap<Entity, Vec3>);
|
||||
|
||||
#[derive(Component, Debug, Clone, Deref, DerefMut, Default)]
|
||||
|
@ -41,6 +32,7 @@ pub struct Velocity(Vec3);
|
|||
#[derive(Component)]
|
||||
pub struct Toid {
|
||||
pub speed: f32,
|
||||
pub buddies: usize,
|
||||
}
|
||||
|
||||
pub fn turkey_time(
|
||||
|
@ -51,9 +43,10 @@ pub fn turkey_time(
|
|||
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 }))
|
||||
.insert((Velocity(vel), Buddies::default(), Toid { speed, buddies }))
|
||||
.with_children(|t| {
|
||||
t.spawn(SceneBundle {
|
||||
scene: scene.to_owned(),
|
||||
|
@ -83,8 +76,9 @@ pub fn update_pos(
|
|||
) {
|
||||
let dt = time.delta_seconds();
|
||||
for (mut xform, vel, _entity) in toids.iter_mut() {
|
||||
let vel = vel.0;
|
||||
xform.translation += vel * dt;
|
||||
xform.translation += vel.0 * dt;
|
||||
let look_at = xform.translation + vel.0;
|
||||
xform.look_at(look_at, Vec3::Y);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +105,7 @@ pub fn update_buddies(mut toids: Query<(&Transform, Entity, &mut Buddies)>, inde
|
|||
// util
|
||||
//-************************************************************************
|
||||
|
||||
pub fn unit_vec(r: &mut impl rand::prelude::Rng) -> Vec3 {
|
||||
pub fn unit_vec(r: &mut impl rand::Rng) -> Vec3 {
|
||||
let mut x1: f32 = 0.0;
|
||||
let mut x2: f32 = 0.0;
|
||||
let mut ssum = std::f32::MAX;
|
||||
|
|
|
@ -8,16 +8,21 @@ fn main() {
|
|||
let config: audubon::Config = argh::from_env();
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.insert_resource(Index(rstar::RTree::new()))
|
||||
.insert_resource(config)
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
update_vel,
|
||||
add_gizmos,
|
||||
update_pos,
|
||||
update_buddies,
|
||||
rotate_camera,
|
||||
update_config,
|
||||
bevy::window::close_on_esc,
|
||||
),
|
||||
)
|
||||
.chain(),
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
@ -32,7 +37,7 @@ fn setup(
|
|||
let rand = &mut rand::thread_rng();
|
||||
|
||||
commands.spawn(Camera3dBundle {
|
||||
transform: Transform::from_xyz(0., 1.5, 6.).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
transform: Transform::from_xyz(0., 3.5, 10.).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
// plane
|
||||
|
|
Loading…
Reference in a new issue