Struct ScalarSpring

Source
pub struct ScalarSpring {
    pub smooth: f32,
    pub undamp: f32,
    pub goal: f32,
    pub value: f32,
    pub vel: f32,
    pub time: u64,
    pub enabled: bool,
}
Expand description

Critically damped spring modulator. Moves towards its set goal with smooth seconds of delay, critically damping its arrival so it slows down and stops at the goal without overshooting or oscillation.

If overshooting is desired, positive values of undamp can be set to add artificial overshoot/oscillations around the goal.

Fields§

§smooth: f32

Spring delay (smoothing), in seconds

§undamp: f32

Amount of damping to remove (0..1)

§goal: f32

Current target for the spring

§value: f32

Current position of the spring (value)

§vel: f32

Current velocity

§time: u64

Accumulated microseconds

§enabled: bool

Enabling toggle

Implementations§

Source§

impl ScalarSpring

Source

pub fn new(smooth: f32, undamp: f32, initial: f32) -> Self

Make a critically damped spring

Source

pub fn spring_to(&mut self, goal: f32)

Update the target the spring is moving towards

Source

pub fn jump_to(&mut self, goal: f32)

Jump immediately to the given goal, zero velocity

Trait Implementations§

Source§

impl Modulator<f32> for ScalarSpring

Source§

fn value(&self) -> f32

Value of the modulator at the current time.
Source§

fn goal(&self) -> Option<f32>

Current goal of the modulator, or None if not applicable.
Source§

fn set_goal(&mut self, goal: f32)

Set a goal for the modulator to move towards, if possible.
Source§

fn elapsed_us(&self) -> u64

Total accumulated microseconds for the modulator.
Source§

fn enabled(&self) -> bool

Check if the modulator is disabled
Source§

fn set_enabled(&mut self, enabled: bool)

Toggle enabling/disabling the modulator
Source§

fn advance(&mut self, dt: u64)

Move the modulator ahead by dt microseconds.
Source§

fn as_any(&mut self) -> &mut dyn Any

Allow donwcasting.
Source§

fn range(&self) -> Option<[T; 2]>

Range of the modulator as min..=max, or None if the range is indeterminate.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V