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,
impl<F> DampedSpringController<F>where
F: Float + FromPrimitive,
Sourcepub fn with_coefficients(
delta_time: F,
desired_angular_frequency: F,
desired_damping_ratio: F,
) -> DampedSpringController<F>
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}
Sourcepub fn update(&self, position: &mut F, velocity: &mut F, target: F)
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> 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