psychic-ui 0.0.0
Loading...
Searching...
No Matches
psychic_ui::Spring Struct Reference

#include <Timing.hpp>

Public Member Functions

float dampingRatio () const
Approach approach (float x0, float v0, float t, float tolerance) const
constexpr bool operator== (const Spring &) const =default

Public Attributes

float stiffness {170.0f}
float damping {26.0f}
float mass {1.0f}

Static Public Attributes

static constexpr std::chrono::nanoseconds maxTime = std::chrono::seconds(10)
static const Spring Gentle {.stiffness = 170.0f, .damping = 26.0f, .mass = 1.0f}
static const Spring Snappy {.stiffness = 500.0f, .damping = 30.0f, .mass = 1.0f}
static const Spring Bouncy {.stiffness = 400.0f, .damping = 14.0f, .mass = 1.0f}

Detailed Description

A damped spring pulling a value to its target: no duration, it settles when it gets there. Interrupted, it keeps its speed, so a value that reverses half-way turns smoothly. Below a damping of 2√(stiffness × mass) it overshoots and oscillates; at or above it, it doesn't.

Spring{.stiffness = 500, .damping = 30}

Member Function Documentation

◆ approach()

Approach psychic_ui::Spring::approach ( float x0,
float v0,
float t,
float tolerance ) const
nodiscard

Where it is t seconds after it had an offset of x0 and a velocity of v0 (the closed form, so the frame rate doesn't change the motion): settled once the offset is within tolerance and the velocity within tolerance × max(ω, 1), or after maxTime

◆ dampingRatio()

float psychic_ui::Spring::dampingRatio ( ) const
nodiscard

Its damping ratio: below 1 it overshoots

Member Data Documentation

◆ maxTime

std::chrono::nanoseconds psychic_ui::Spring::maxTime = std::chrono::seconds(10)
staticconstexpr

A spring that went on this long is settled


The documentation for this struct was generated from the following files: