ugg
This commit is contained in:
parent
94ff4edcca
commit
6ca933a1b1
1 changed files with 33 additions and 12 deletions
45
src/main.rs
45
src/main.rs
|
@ -13,6 +13,8 @@ use bevy::{color::palettes::tailwind, prelude::*, sprite::MaterialMesh2dBundle};
|
|||
use boid_mesh::BoidMesh;
|
||||
use rand::{Rng, SeedableRng};
|
||||
|
||||
const VISION_RANGE: f32 = 100.;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.init_resource::<BoidMesh>()
|
||||
|
@ -23,7 +25,7 @@ fn main() {
|
|||
(
|
||||
build_local_cache,
|
||||
(seperation_gizmos),
|
||||
(seperation, cohesion, alignment),
|
||||
// (seperation, cohesion, alignment),
|
||||
accelerate,
|
||||
move_boids,
|
||||
boundary::boid_border_teleport,
|
||||
|
@ -55,9 +57,7 @@ struct BoidBundle {
|
|||
struct LocalCache(Vec<Entity>);
|
||||
|
||||
fn is_local(a: Vec3, b: Vec3) -> bool {
|
||||
const LOCAL_DISTANCE: f32 = 100.;
|
||||
|
||||
a.distance(b) < LOCAL_DISTANCE
|
||||
a.distance(b) < VISION_RANGE
|
||||
}
|
||||
|
||||
fn build_local_cache(
|
||||
|
@ -104,13 +104,28 @@ fn seperation_gizmos(
|
|||
mut gizmos: Gizmos,
|
||||
) {
|
||||
boids.iter().for_each(|(transform, local)| {
|
||||
other_boids.iter_many(&local.0).for_each(|other_transform| {
|
||||
gizmos.arrow_2d(
|
||||
transform.translation.xy(),
|
||||
other_transform.translation.xy(),
|
||||
tailwind::ROSE_500,
|
||||
);
|
||||
})
|
||||
other_boids
|
||||
.iter_many(&local.0)
|
||||
.take(1)
|
||||
.for_each(|other_transform| {
|
||||
let distance = transform.translation.distance(other_transform.translation);
|
||||
let diff_scale = (distance / VISION_RANGE);
|
||||
|
||||
let mut diff = transform.translation - other_transform.translation;
|
||||
diff *= diff_scale;
|
||||
|
||||
gizmos.arrow(
|
||||
transform.translation,
|
||||
transform.translation + diff,
|
||||
tailwind::RED_500,
|
||||
);
|
||||
|
||||
gizmos.line(
|
||||
transform.translation,
|
||||
other_transform.translation,
|
||||
tailwind::GREEN_500,
|
||||
);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -187,7 +202,13 @@ fn setup(
|
|||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
boid_mesh: Res<BoidMesh>,
|
||||
windows: Query<&Window>,
|
||||
mut time: ResMut<Time<Virtual>>,
|
||||
mut config_store: ResMut<GizmoConfigStore>,
|
||||
) {
|
||||
time.set_relative_speed(0.1);
|
||||
let (gizmo_config, _) = config_store.config_mut::<DefaultGizmoConfigGroup>();
|
||||
gizmo_config.line_width = 5.;
|
||||
|
||||
let window = windows.get_single().unwrap();
|
||||
let half_width = window.resolution.width() / 4.;
|
||||
let half_height = window.resolution.height() / 2.;
|
||||
|
@ -200,7 +221,7 @@ fn setup(
|
|||
let lower_height = -half_height;
|
||||
let upper_height = half_height;
|
||||
|
||||
for i in 0..1000 {
|
||||
for i in 0..500 {
|
||||
use std::f32::consts::TAU;
|
||||
|
||||
let x = small_rng.gen_range(lower_width..=upper_width);
|
||||
|
|
Loading…
Reference in a new issue