basic gizmo testing
This commit is contained in:
parent
d89666b3f0
commit
94ff4edcca
2 changed files with 30 additions and 4 deletions
|
@ -14,6 +14,7 @@ features = [
|
|||
"bevy_color",
|
||||
"bevy_render",
|
||||
"bevy_winit",
|
||||
"bevy_gizmos",
|
||||
"multi_threaded",
|
||||
"x11",
|
||||
"wayland",
|
||||
|
|
33
src/main.rs
33
src/main.rs
|
@ -1,3 +1,4 @@
|
|||
#![allow(clippy::type_complexity)]
|
||||
// #![allow(unused)]
|
||||
|
||||
mod acceleration;
|
||||
|
@ -21,6 +22,7 @@ fn main() {
|
|||
Update,
|
||||
(
|
||||
build_local_cache,
|
||||
(seperation_gizmos),
|
||||
(seperation, cohesion, alignment),
|
||||
accelerate,
|
||||
move_boids,
|
||||
|
@ -31,6 +33,9 @@ fn main() {
|
|||
.run();
|
||||
}
|
||||
|
||||
#[derive(Component, Default)]
|
||||
struct DrawGizmos;
|
||||
|
||||
#[derive(Component, Default)]
|
||||
struct Boid;
|
||||
|
||||
|
@ -82,7 +87,7 @@ fn cohesion(
|
|||
accel.0 = Vec2::ZERO;
|
||||
|
||||
let mut count = 0;
|
||||
for transform in other_boids.iter_many(&local.0[..]) {
|
||||
for transform in other_boids.iter_many(&local.0) {
|
||||
accel.0 += transform.translation.xy();
|
||||
|
||||
count += 1;
|
||||
|
@ -93,6 +98,22 @@ fn cohesion(
|
|||
})
|
||||
}
|
||||
|
||||
fn seperation_gizmos(
|
||||
boids: Query<(&Transform, &LocalCache), (With<Boid>, With<DrawGizmos>)>,
|
||||
other_boids: Query<&Transform, With<Boid>>,
|
||||
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,
|
||||
);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
fn seperation(
|
||||
mut boids: Query<(&Transform, &LocalCache, &mut SeperationAcceleration), With<Boid>>,
|
||||
other_boids: Query<&Transform, With<Boid>>,
|
||||
|
@ -110,7 +131,7 @@ fn alignment(
|
|||
.for_each(|(velocity, local, mut accel)| {
|
||||
accel.0 = Vec2::ZERO;
|
||||
let mut count = 0;
|
||||
for other_velocity in other_boids.iter_many(&local.0[..]) {
|
||||
for other_velocity in other_boids.iter_many(&local.0) {
|
||||
accel.0 += other_velocity.0;
|
||||
|
||||
count += 1;
|
||||
|
@ -179,7 +200,7 @@ fn setup(
|
|||
let lower_height = -half_height;
|
||||
let upper_height = half_height;
|
||||
|
||||
for _ in 0..1000 {
|
||||
for i in 0..1000 {
|
||||
use std::f32::consts::TAU;
|
||||
|
||||
let x = small_rng.gen_range(lower_width..=upper_width);
|
||||
|
@ -187,7 +208,7 @@ fn setup(
|
|||
|
||||
let angle = small_rng.gen_range(-TAU..=TAU);
|
||||
|
||||
commands.spawn(BoidBundle {
|
||||
let mut entity_commands = commands.spawn(BoidBundle {
|
||||
mesh: MaterialMesh2dBundle {
|
||||
mesh: boid_mesh.0.clone(),
|
||||
material: boid_color.clone(),
|
||||
|
@ -198,6 +219,10 @@ fn setup(
|
|||
velocity: Velocity(Vec2::from_angle(angle) * 200.),
|
||||
..default()
|
||||
});
|
||||
|
||||
if i == 0 {
|
||||
entity_commands.insert(DrawGizmos);
|
||||
}
|
||||
}
|
||||
|
||||
commands.spawn(Camera2dBundle::default());
|
||||
|
|
Loading…
Reference in a new issue