Rename Acceleration to Force
Closes #2 Acceleration is mass * force. This doesn't materially change anything, but it will make it easier to give the boids a mass component. The change will not require updates to most of the systems, only the physics integrator and the boids bundle.
This commit is contained in:
@@ -52,7 +52,7 @@ struct PlayerBoid;
|
|||||||
pub(crate) struct Velocity(Vec3);
|
pub(crate) struct Velocity(Vec3);
|
||||||
|
|
||||||
#[derive(Component, Deref, DerefMut)]
|
#[derive(Component, Deref, DerefMut)]
|
||||||
pub(crate) struct Acceleration(Vec3);
|
pub(crate) struct Force(Vec3);
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub(crate) struct TrackedByKdTree;
|
pub(crate) struct TrackedByKdTree;
|
||||||
@@ -61,7 +61,7 @@ pub(crate) struct TrackedByKdTree;
|
|||||||
struct BoidBundle {
|
struct BoidBundle {
|
||||||
boid: Boid,
|
boid: Boid,
|
||||||
velocity: Velocity,
|
velocity: Velocity,
|
||||||
accel: Acceleration,
|
accel: Force,
|
||||||
spatial: TrackedByKdTree,
|
spatial: TrackedByKdTree,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ impl BoidBundle {
|
|||||||
Self {
|
Self {
|
||||||
boid: Boid,
|
boid: Boid,
|
||||||
velocity: Velocity(vel),
|
velocity: Velocity(vel),
|
||||||
accel: Acceleration(Vec3::ZERO),
|
accel: Force(Vec3::ZERO),
|
||||||
spatial: TrackedByKdTree,
|
spatial: TrackedByKdTree,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ fn spawn_boids(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn space_brakes(mut mobs: Query<&mut Acceleration, With<Boid>>) {
|
fn space_brakes(mut mobs: Query<&mut Force, With<Boid>>) {
|
||||||
for mut accel in &mut mobs {
|
for mut accel in &mut mobs {
|
||||||
let braking_dir = -accel.0 * SPACEBRAKES_COEFFICIENT;
|
let braking_dir = -accel.0 * SPACEBRAKES_COEFFICIENT;
|
||||||
accel.0 += braking_dir;
|
accel.0 += braking_dir;
|
||||||
@@ -147,7 +147,7 @@ fn turn_if_edge(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn apply_velocity(
|
fn apply_velocity(
|
||||||
mut query: Query<(&mut Transform, &Velocity, &mut Acceleration)>,
|
mut query: Query<(&mut Transform, &Velocity, &mut Force)>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
for (mut transform, velocity, mut acceleration) in &mut query {
|
for (mut transform, velocity, mut acceleration) in &mut query {
|
||||||
@@ -187,7 +187,7 @@ fn check_keyboard(
|
|||||||
|
|
||||||
fn cohesion(
|
fn cohesion(
|
||||||
spatial_tree: Res<KDTree2<TrackedByKdTree>>,
|
spatial_tree: Res<KDTree2<TrackedByKdTree>>,
|
||||||
mut boids: Query<(&Transform, &mut Acceleration), With<Boid>>,
|
mut boids: Query<(&Transform, &mut Force), With<Boid>>,
|
||||||
) {
|
) {
|
||||||
// for each boid
|
// for each boid
|
||||||
// find neighbors
|
// find neighbors
|
||||||
@@ -205,7 +205,7 @@ fn cohesion(
|
|||||||
|
|
||||||
fn separation(
|
fn separation(
|
||||||
spatial_tree: Res<KDTree2<TrackedByKdTree>>,
|
spatial_tree: Res<KDTree2<TrackedByKdTree>>,
|
||||||
mut boids: Query<(&Transform, &mut Acceleration), With<Boid>>,
|
mut boids: Query<(&Transform, &mut Force), With<Boid>>,
|
||||||
) {
|
) {
|
||||||
// for each boid
|
// for each boid
|
||||||
// find neighbors
|
// find neighbors
|
||||||
@@ -226,14 +226,14 @@ fn separation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make this an exponential so force gets stronger faster as the points approach.
|
// TODO: Make this an exponential so force gets stronger faster as the points approach.
|
||||||
fn separation_force(us: Vec2, neighbor: Vec2) -> Acceleration {
|
fn separation_force(us: Vec2, neighbor: Vec2) -> Force {
|
||||||
let distance = neighbor - us;
|
let distance = neighbor - us;
|
||||||
Acceleration(-(distance * SEPARATION_FACTOR).extend(0.0))
|
Force(-(distance * SEPARATION_FACTOR).extend(0.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alignment(
|
fn alignment(
|
||||||
spatial_tree: Res<KDTree2<TrackedByKdTree>>,
|
spatial_tree: Res<KDTree2<TrackedByKdTree>>,
|
||||||
mut boids: Query<(&Transform, &Velocity, &mut Acceleration), With<Boid>>,
|
mut boids: Query<(&Transform, &Velocity, &mut Force), With<Boid>>,
|
||||||
boid_velocities: Query<&Velocity, With<Boid>>,
|
boid_velocities: Query<&Velocity, With<Boid>>,
|
||||||
) {
|
) {
|
||||||
// for each boid
|
// for each boid
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use bevy::{prelude::*, sprite::MaterialMesh2dBundle, window::PrimaryWindow};
|
|||||||
use bevy_spatial::{kdtree::KDTree2, SpatialAccess};
|
use bevy_spatial::{kdtree::KDTree2, SpatialAccess};
|
||||||
|
|
||||||
use crate::birdoids_plugin::{
|
use crate::birdoids_plugin::{
|
||||||
center_of_boids, velocity_of_boids, Acceleration, Boid, TrackedByKdTree, Velocity,
|
center_of_boids, velocity_of_boids, Force, Boid, TrackedByKdTree, Velocity,
|
||||||
};
|
};
|
||||||
|
|
||||||
const SCANRADIUS: f32 = 50.0;
|
const SCANRADIUS: f32 = 50.0;
|
||||||
@@ -117,7 +117,7 @@ fn print_gizmo_config(query: Query<(&SelectionMode, &ScannerMode), With<Cursor>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn do_scan(
|
fn do_scan(
|
||||||
boids_query: Query<(&Transform, &Velocity, &Acceleration), With<Boid>>,
|
boids_query: Query<(&Transform, &Velocity, &Force), With<Boid>>,
|
||||||
scanner_query: Query<(&Transform, &SelectionMode, &ScannerMode), With<Cursor>>,
|
scanner_query: Query<(&Transform, &SelectionMode, &ScannerMode), With<Cursor>>,
|
||||||
spatial_tree: Res<KDTree2<TrackedByKdTree>>,
|
spatial_tree: Res<KDTree2<TrackedByKdTree>>,
|
||||||
/* Push info to summary somewhere */
|
/* Push info to summary somewhere */
|
||||||
|
|||||||
Reference in New Issue
Block a user