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 more