pub struct SpringAnimation {
pub value: f32,
pub velocity: f32,
pub target: f32,
pub stiffness: f32,
pub damping: f32,
}Expand description
Spring-based animation for smooth, physics-based motion
This uses a damped spring physics model for natural-looking animations. Unlike timed animations, springs don’t have a fixed duration - they settle over time.
§Example
use armas_basic::animation::SpringAnimation;
let mut spring = SpringAnimation::new(0.0, 1.0)
.params(200.0, 20.0);
spring.update(0.016); // one frame at 60fps
let current = spring.value;Fields§
§value: f32Current value
velocity: f32Current velocity
target: f32Target value
stiffness: f32Spring stiffness (higher = faster oscillation, typical: 100-300)
damping: f32Spring damping (higher = less oscillation, typical: 10-30)
Implementations§
Source§impl SpringAnimation
impl SpringAnimation
Sourcepub fn update(&mut self, dt: f32)
pub fn update(&mut self, dt: f32)
Update the spring simulation using semi-implicit Euler integration
Sourcepub const fn set_target(&mut self, target: f32)
pub const fn set_target(&mut self, target: f32)
Set a new target value
Sourcepub fn is_settled(
&self,
position_threshold: f32,
velocity_threshold: f32,
) -> bool
pub fn is_settled( &self, position_threshold: f32, velocity_threshold: f32, ) -> bool
Check if the spring has approximately settled at the target
Trait Implementations§
Source§impl Clone for SpringAnimation
impl Clone for SpringAnimation
Source§fn clone(&self) -> SpringAnimation
fn clone(&self) -> SpringAnimation
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SpringAnimation
impl RefUnwindSafe for SpringAnimation
impl Send for SpringAnimation
impl Sync for SpringAnimation
impl Unpin for SpringAnimation
impl UnsafeUnpin for SpringAnimation
impl UnwindSafe for SpringAnimation
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