pub struct Spring {
pub config: SpringConfig,
/* private fields */
}Expand description
A 1D damped harmonic oscillator spring.
Stack-allocated and no_std-compatible. Use SpringN<T>
for multi-dimensional animation.
§Example
use animato_spring::{Spring, SpringConfig};
use animato_core::Update;
let mut s = Spring::new(SpringConfig::stiff());
s.set_target(100.0);
for _ in 0..300 {
s.update(1.0 / 60.0);
}
assert!((s.position() - 100.0).abs() < 0.01);Fields§
§config: SpringConfigThe spring configuration (stiffness, damping, mass, epsilon).
Implementations§
Source§impl Spring
impl Spring
Sourcepub fn new(config: SpringConfig) -> Self
pub fn new(config: SpringConfig) -> Self
Create a new spring at position 0.0 with target 0.0.
Sourcepub fn set_target(&mut self, target: f32)
pub fn set_target(&mut self, target: f32)
Set the target position the spring moves toward.
Sourcepub fn is_settled(&self) -> bool
pub fn is_settled(&self) -> bool
true when the spring has come to rest within epsilon of the target.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Spring
impl RefUnwindSafe for Spring
impl Send for Spring
impl Sync for Spring
impl Unpin for Spring
impl UnsafeUnpin for Spring
impl UnwindSafe for Spring
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