friz
An animation control system for JUCE
Loading...
Searching...
No Matches
friz::Spring Class Reference

Accelerates toward the end value – if this acceleration takes it past the end value, it enters a mode where it acts like a simplified oscillating spring; the behavior of the oscillation can be loosened or tightened using the dampen parameter. More...

#include <spring.h>

Inheritance diagram for friz::Spring:

Public Member Functions

 Spring (float startVal, float endVal, float tolerance, float accel, float dampen)
 
- Public Member Functions inherited from friz::ToleranceValue
 ToleranceValue (float startVal, float endVal, float tolerance)
 
float getNextValue (int, int msSinceLastUpdate) override
 Calculate the next value in the sequence based on the delta time since last updated. Internally, we use an update rate of 1 kHz to recalculate values so that we can remain consistent as the actual animation frame rate changes.
 
bool isFinished () override
 Test to see if this value has reached its end state.
 
- Public Member Functions inherited from friz::AnimatedValue
 AnimatedValue (float startVal_, float endVal_)
 Base class init for the animated value classes.
 
virtual float getNextValue (int msElapsed, int msSinceLastUpdate)=0
 
float getEndValue () const
 get the ending state of this value object. When we cancel an in-progress animation, we may need to snap to the end value, and this gives a way to get there immediately.
 
virtual bool isFinished ()=0
 
virtual bool updateTarget (float)
 Attempt to change the end value of an animation that's currently in process.
 
void cancel (bool moveToEndPosition)
 Cancel an in-progress animation.
 

Private Member Functions

float generateNextValue () override
 Execute a single step of this curve's function.
 

Private Attributes

float startAcceleration
 The initial acceleration for this value.
 
float acceleration
 When we're in a damping state, the acceleration will change.
 
float damping
 damping factor to apply when we need to oscillate toward end val.
 
float velocity
 current velocity, updated with acceleration every frame.
 

Additional Inherited Members

- Protected Attributes inherited from friz::ToleranceValue
float tolerance
 
- Protected Attributes inherited from friz::AnimatedValue
float startVal
 
float endVal
 
float currentVal
 
bool canceled { false }
 
bool finished { false }
 

Detailed Description

Accelerates toward the end value – if this acceleration takes it past the end value, it enters a mode where it acts like a simplified oscillating spring; the behavior of the oscillation can be loosened or tightened using the dampen parameter.

Constructor & Destructor Documentation

◆ Spring()

friz::Spring::Spring ( float  startVal,
float  endVal,
float  tolerance,
float  accel,
float  dampen 
)

A curve that accelerates toward the end value, then oscillates toward it on overshoot.

Parameters
startValinitial value
endValend value.
toleranceHow close do we need to be to stop animating?
accelVelocity change on each update.
dampenHow much to dampen the oscillation, 0 < dampen < 1. smaller values dampen the oscillation faster.

Member Function Documentation

◆ generateNextValue()

float friz::Spring::generateNextValue ( )
overrideprivatevirtual

Execute a single step of this curve's function.

Returns
next value.

Implements friz::ToleranceValue.


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