pub struct Flock {
pub boids: Vec<Boid>,
pub config: FlockConfig,
pub obstacles: Vec<Obstacle>,
pub leader: Option<Vec3>,
pub predators: Vec<Vec3>,
}Expand description
The complete flock — owns and ticks all boids each frame.
Fields§
§boids: Vec<Boid>§config: FlockConfig§obstacles: Vec<Obstacle>§leader: Option<Vec3>§predators: Vec<Vec3>Implementations§
Source§impl Flock
impl Flock
pub fn new(config: FlockConfig) -> Self
Sourcepub fn spawn_circle(&mut self, n: usize, center: Vec3, radius: f32)
pub fn spawn_circle(&mut self, n: usize, center: Vec3, radius: f32)
Spawn N boids in a circle at the given center with random velocities.
Sourcepub fn spawn_scatter(&mut self, n: usize, center: Vec3, radius: f32, seed: u64)
pub fn spawn_scatter(&mut self, n: usize, center: Vec3, radius: f32, seed: u64)
Spawn N boids in a random scatter within radius.
Sourcepub fn tick(&mut self, dt: f32)
pub fn tick(&mut self, dt: f32)
Tick all boids by dt seconds. Computes neighbor lists and integrates.
Sourcepub fn add_obstacle(&mut self, center: Vec3, radius: f32)
pub fn add_obstacle(&mut self, center: Vec3, radius: f32)
Add a spherical obstacle to avoid.
Sourcepub fn set_leader(&mut self, pos: Option<Vec3>)
pub fn set_leader(&mut self, pos: Option<Vec3>)
Set the leader position (boids will follow).
Sourcepub fn set_predators(&mut self, predators: Vec<Vec3>)
pub fn set_predators(&mut self, predators: Vec<Vec3>)
Set predator positions (boids will flee).
pub fn is_empty(&self) -> bool
Sourcepub fn cohesion_metric(&self) -> f32
pub fn cohesion_metric(&self) -> f32
Cohesion metric: 1.0 = tight flock, 0.0 = completely scattered. Measured as 1 / (1 + average distance from centroid).
Sourcepub fn polarization(&self) -> f32
pub fn polarization(&self) -> f32
Polarization: how aligned the flock velocity is (1.0 = all same direction).
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> 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.