pub struct Spring {
pub stiffness: f32,
pub damping: f32,
}Expand description
A damped harmonic oscillator with unit mass, solved in closed form.
Numeric integration drifts with the frame rate and can blow up after a long frame. The analytic solution gives the same position at a given time however many frames were drawn on the way there.
Fields§
§stiffness: f32Restoring force per unit of displacement.
damping: f32Braking force per unit of velocity.
Implementations§
Source§impl Spring
impl Spring
Sourcepub const fn new(stiffness: f32, damping: f32) -> Self
pub const fn new(stiffness: f32, damping: f32) -> Self
A spring with this stiffness and damping.
Sourcepub fn from_response(response: f32, damping_ratio: f32) -> Self
pub fn from_response(response: f32, damping_ratio: f32) -> Self
A spring described the way designers think about it: response is the
period of the undamped oscillation in seconds, and damping_ratio is
1.0 for no overshoot, less for some bounce.
Trait Implementations§
impl Copy for Spring
impl StructuralPartialEq for Spring
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