Struct DampedSpringController

Source
pub struct DampedSpringController<F> { /* private fields */ }
Expand description

Caches coefficients so that multiple springs with the same parameters may be used without re-running trigonometry calls.

Implementations§

Source§

impl<F> DampedSpringController<F>
where F: Float + FromPrimitive,

Source

pub fn with_coefficients( delta_time: F, desired_angular_frequency: F, desired_damping_ratio: F, ) -> DampedSpringController<F>

Performs (somewhat nontrivial) calculations to prepare the motion of a damped spring. Once initialized, you may update any spring with identical properties with update using the same object.

Examples found in repository?
examples/springy.rs (line 7)
5fn sixtyfour() {
6    // 64-bit float springs
7    let spring = DampedSpringController::<f64>::with_coefficients(1.0, 10.0, 10.0);
8    let mut v: f64 = 0.0;
9    let mut p: f64 = 0.0;
10
11    for _i in 0..10 {
12        spring.update(&mut p, &mut v, 100.0);
13        print!("{}\n", p);
14    }
15}
16
17fn thirtytwo() {
18    // 64-bit float springs
19    let spring = DampedSpringController::<f32>::with_coefficients(1.0, 10.0, 10.0);
20    let mut v: f32 = 0.0;
21    let mut p: f32 = 0.0;
22
23    for _i in 0..10 {
24        spring.update(&mut p, &mut v, 100.0);
25        print!("{}\n", p);
26    }
27}
Source

pub fn update(&self, position: &mut F, velocity: &mut F, target: F)

Updates the position and velocity of a spring using this controller’s physical properties.

Examples found in repository?
examples/springy.rs (line 12)
5fn sixtyfour() {
6    // 64-bit float springs
7    let spring = DampedSpringController::<f64>::with_coefficients(1.0, 10.0, 10.0);
8    let mut v: f64 = 0.0;
9    let mut p: f64 = 0.0;
10
11    for _i in 0..10 {
12        spring.update(&mut p, &mut v, 100.0);
13        print!("{}\n", p);
14    }
15}
16
17fn thirtytwo() {
18    // 64-bit float springs
19    let spring = DampedSpringController::<f32>::with_coefficients(1.0, 10.0, 10.0);
20    let mut v: f32 = 0.0;
21    let mut p: f32 = 0.0;
22
23    for _i in 0..10 {
24        spring.update(&mut p, &mut v, 100.0);
25        print!("{}\n", p);
26    }
27}

Auto Trait Implementations§

§

impl<F> Freeze for DampedSpringController<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for DampedSpringController<F>
where F: RefUnwindSafe,

§

impl<F> Send for DampedSpringController<F>
where F: Send,

§

impl<F> Sync for DampedSpringController<F>
where F: Sync,

§

impl<F> Unpin for DampedSpringController<F>
where F: Unpin,

§

impl<F> UnwindSafe for DampedSpringController<F>
where F: UnwindSafe,

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.