pub struct Flock {
pub boids: Vec<Boid>,
pub separation_weight: f32,
pub alignment_weight: f32,
pub cohesion_weight: f32,
pub neighbor_radius: f32,
pub separation_radius: f32,
pub bounds: Option<(Vec2, Vec2)>,
}Expand description
Reynolds flocking simulation (separation, alignment, cohesion).
Fields§
§boids: Vec<Boid>§separation_weight: f32§alignment_weight: f32§cohesion_weight: f32§neighbor_radius: f32Radius within which a boid considers others its neighbors.
separation_radius: f32Minimum distance before separation kicks in.
bounds: Option<(Vec2, Vec2)>Optional world bounds (min, max).
Implementations§
Source§impl Flock
impl Flock
pub fn new() -> Self
Sourcepub fn add_agent(&mut self, pos: Vec2, vel: Vec2)
pub fn add_agent(&mut self, pos: Vec2, vel: Vec2)
Add a boid with a given position and initial velocity.
pub fn add_boid(&mut self, boid: Boid)
Sourcepub fn separation_force(&self, idx: usize) -> Vec2
pub fn separation_force(&self, idx: usize) -> Vec2
Separation: steer to avoid crowding local flockmates.
Sourcepub fn alignment_force(&self, idx: usize) -> Vec2
pub fn alignment_force(&self, idx: usize) -> Vec2
Alignment: steer toward the average heading of local flockmates.
Sourcepub fn cohesion_force(&self, idx: usize) -> Vec2
pub fn cohesion_force(&self, idx: usize) -> Vec2
Cohesion: steer toward the average position of local flockmates.
Sourcepub fn seek_target(&mut self, target: Vec2, weight: f32, dt: f32)
pub fn seek_target(&mut self, target: Vec2, weight: f32, dt: f32)
Add a seek force toward a target for all boids.
Sourcepub fn average_speed(&self) -> f32
pub fn average_speed(&self) -> f32
Returns average speed of the flock.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Flock
impl RefUnwindSafe for Flock
impl Send for Flock
impl Sync for Flock
impl Unpin for Flock
impl UnsafeUnpin for Flock
impl UnwindSafe for Flock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.