pub struct SpringChain {
pub positions: Vec<Vec3>,
pub velocities: Vec<Vec3>,
pub rest_lengths: Vec<f32>,
pub stiffness: f32,
pub damping: f32,
pub masses: Vec<f32>,
pub pin_head: bool,
pub gravity: Vec3,
pub iterations: usize,
}Expand description
A chain of N particles connected by spring-based distance constraints.
Useful for tails, tendrils, cloth edges, banner text, and rope physics. The first particle is optionally pinned to an anchor.
Fields§
§positions: Vec<Vec3>Particle positions.
velocities: Vec<Vec3>Particle velocities.
rest_lengths: Vec<f32>Per-segment rest lengths (length = positions.len() - 1).
stiffness: f32Constraint stiffness (0 = free-fall, 1 = rigid).
damping: f32Velocity damping per step.
masses: Vec<f32>Per-particle mass (1.0 default, first particle can be infinity).
pin_head: boolIf true, first particle is pinned to its initial position.
gravity: Vec3Gravity applied per step.
iterations: usizeNumber of constraint iterations per tick (higher = stiffer).
Implementations§
Source§impl SpringChain
impl SpringChain
Sourcepub fn new(anchor: Vec3, count: usize, segment_length: f32) -> Self
pub fn new(anchor: Vec3, count: usize, segment_length: f32) -> Self
Create a chain hanging vertically from anchor.
count — number of particles (including anchor).
segment_length — rest length per segment.
Sourcepub fn horizontal(anchor: Vec3, count: usize, segment_length: f32) -> Self
pub fn horizontal(anchor: Vec3, count: usize, segment_length: f32) -> Self
Create a chain for a banner or horizontal tendril.
Sourcepub fn set_anchor(&mut self, pos: Vec3)
pub fn set_anchor(&mut self, pos: Vec3)
Set the anchor (first particle) position.
Sourcepub fn tick(&mut self, dt: f32)
pub fn tick(&mut self, dt: f32)
Simulate one physics step.
Applies gravity, integrates velocities, then resolves constraints.
Sourcepub fn apply_impulse(&mut self, index: usize, impulse: Vec3)
pub fn apply_impulse(&mut self, index: usize, impulse: Vec3)
Apply an impulse to a specific particle.
Sourcepub fn apply_wind(&mut self, wind: Vec3, dt: f32)
pub fn apply_wind(&mut self, wind: Vec3, dt: f32)
Apply a wind force to all non-infinite-mass particles.
Sourcepub fn total_length(&self) -> f32
pub fn total_length(&self) -> f32
Total chain length.
Sourcepub fn extension_ratio(&self) -> f32
pub fn extension_ratio(&self) -> f32
Current extension ratio (actual_length / rest_length).
Trait Implementations§
Source§impl Clone for SpringChain
impl Clone for SpringChain
Source§fn clone(&self) -> SpringChain
fn clone(&self) -> SpringChain
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SpringChain
impl RefUnwindSafe for SpringChain
impl Send for SpringChain
impl Sync for SpringChain
impl Unpin for SpringChain
impl UnsafeUnpin for SpringChain
impl UnwindSafe for SpringChain
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
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>
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>
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)
&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)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.