pub struct ParticleBuffer {
pub positions_x: Vec<f32>,
pub positions_y: Vec<f32>,
pub positions_z: Vec<f32>,
pub velocities_x: Vec<f32>,
pub velocities_y: Vec<f32>,
pub velocities_z: Vec<f32>,
pub masses: Vec<f32>,
pub lifetimes: Vec<f32>,
pub ages: Vec<f32>,
pub count: usize,
}Expand description
Structure-of-Arrays particle buffer, optimised for GPU upload.
Fields§
§positions_x: Vec<f32>X positions of each particle slot.
positions_y: Vec<f32>Y positions of each particle slot.
positions_z: Vec<f32>Z positions of each particle slot.
velocities_x: Vec<f32>X velocities.
velocities_y: Vec<f32>Y velocities.
velocities_z: Vec<f32>Z velocities.
masses: Vec<f32>Per-particle mass.
lifetimes: Vec<f32>Remaining lifetime; negative means the slot is dead.
ages: Vec<f32>Elapsed age since spawn.
count: usizeNumber of slots allocated (alive + dead).
Implementations§
Source§impl ParticleBuffer
impl ParticleBuffer
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Allocate a buffer with capacity slots (all dead initially).
Sourcepub fn add_particle(
&mut self,
pos: [f32; 3],
vel: [f32; 3],
mass: f32,
lifetime: f32,
) -> Option<usize>
pub fn add_particle( &mut self, pos: [f32; 3], vel: [f32; 3], mass: f32, lifetime: f32, ) -> Option<usize>
Spawn a new particle in the first dead slot. Returns its index or
None if the buffer is full.
Sourcepub fn get_position(&self, i: usize) -> [f32; 3]
pub fn get_position(&self, i: usize) -> [f32; 3]
Get the position of slot i as \[x, y, z\].
Sourcepub fn get_velocity(&self, i: usize) -> [f32; 3]
pub fn get_velocity(&self, i: usize) -> [f32; 3]
Get the velocity of slot i as \[vx, vy, vz\].
Sourcepub fn set_position(&mut self, i: usize, p: [f32; 3])
pub fn set_position(&mut self, i: usize, p: [f32; 3])
Set the position of slot i.
Sourcepub fn set_velocity(&mut self, i: usize, v: [f32; 3])
pub fn set_velocity(&mut self, i: usize, v: [f32; 3])
Set the velocity of slot i.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Count how many slots are currently alive.
Auto Trait Implementations§
impl Freeze for ParticleBuffer
impl RefUnwindSafe for ParticleBuffer
impl Send for ParticleBuffer
impl Sync for ParticleBuffer
impl Unpin for ParticleBuffer
impl UnsafeUnpin for ParticleBuffer
impl UnwindSafe for ParticleBuffer
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more