SaturnRingLibrary 0.7
SGL wrapper
 
Loading...
Searching...
No Matches
SRL::Math::Interpolation Class Reference

Detailed Description

Class containing interpolation and easing functions optimized for fixed-point arithmetic.

This class provides a comprehensive set of interpolation and easing functions designed for game development. All functions are implemented using fixed-point arithmetic for consistent behavior across platforms.

Key features:

  • Compile-time evaluation with constexpr
  • No floating-point operations
  • Optimized for Saturn hardware
  • Memory-efficient implementations

#include <interpolation.hpp>

Static Public Member Functions

static constexpr Fxp BounceEaseIn (const Fxp &start, const Fxp &end, const Fxp &t)
 Bounce ease-in interpolation for reverse bouncing ball effect.
 
static constexpr Fxp BounceEaseOut (const Fxp &start, const Fxp &end, const Fxp &t)
 Bounce ease-out interpolation for bouncing ball effect.
 
static constexpr Fxp Clamp (const Fxp &value, const Fxp &min, const Fxp &max)
 Clamps a value between minimum and maximum bounds.
 
static constexpr Fxp CubicEaseIn (const Fxp &start, const Fxp &end, const Fxp &t)
 Cubic ease-in interpolation for stronger acceleration.
 
static constexpr Fxp CubicEaseOut (const Fxp &start, const Fxp &end, const Fxp &t)
 Cubic ease-out interpolation for stronger deceleration.
 
static constexpr Fxp EaseIn (const Fxp &start, const Fxp &end, const Fxp &t)
 Quadratic ease-in interpolation for accelerating motion.
 
static constexpr Fxp EaseOut (const Fxp &start, const Fxp &end, const Fxp &t)
 Quadratic ease-out interpolation for decelerating motion.
 
static constexpr Fxp ElasticEaseIn (const Fxp &start, const Fxp &end, const Fxp &t)
 Elastic ease-in interpolation for spring-like motion.
 
static constexpr Fxp Lerp (const Fxp &start, const Fxp &end, const Fxp &t)
 Linear interpolation between two fixed-point values.
 
static constexpr Fxp Smoothstep (const Fxp &start, const Fxp &end, const Fxp &t)
 Smoothstep interpolation for smooth acceleration and deceleration.
 

Member Function Documentation

◆ BounceEaseIn()

static constexpr Fxp SRL::Math::Interpolation::BounceEaseIn ( const Fxp & start,
const Fxp & end,
const Fxp & t )
inlinestaticconstexpr

Bounce ease-in interpolation for reverse bouncing ball effect.

Implements bouncing by reversing BounceEaseOut. Creates a series of bounces that converge to the start.

The motion consists of four phases in reverse:

  • Small initial bounces (10% of time)
  • Medium bounce (18% of time)
  • Large bounce (36% of time)
  • Final launch (36% of time)

Common uses:

  • Object launches
  • UI element takeoffs
  • Character jump startup
  • Power-up activation
Parameters
startStarting value of the interpolation
endEnding value of the interpolation
tInterpolation factor in range [0,1]
Returns
Eased value
Note
Reverses BounceEaseOut for symmetric animations

◆ BounceEaseOut()

static constexpr Fxp SRL::Math::Interpolation::BounceEaseOut ( const Fxp & start,
const Fxp & end,
const Fxp & t )
inlinestaticconstexpr

Bounce ease-out interpolation for bouncing ball effect.

Implements bouncing using piecewise quadratic functions. Simulates diminishing bounces of an elastic ball.

The motion consists of four phases:

  • Initial fall (36% of time)
  • First bounce (36% of time)
  • Second bounce (18% of time)
  • Final small bounces (10% of time)

Common uses:

  • Dropping objects
  • UI element landings
  • Character jump landing
  • Button clicks
Parameters
startStarting value of the interpolation
endEnding value of the interpolation
tInterpolation factor in range [0,1]
Returns
Eased value
Note
Each bounce is approximately 75% the height of previous

◆ Clamp()

static constexpr Fxp SRL::Math::Interpolation::Clamp ( const Fxp & value,
const Fxp & min,
const Fxp & max )
inlinestaticconstexpr

Clamps a value between minimum and maximum bounds.

Ensures a value stays within specified bounds using the formula: result = min(max(value, min), max)

Clamping behavior:

  • If value < min, returns min
  • If value > max, returns max
  • Otherwise, returns value unchanged

Common uses:

  • Constraining player movement
  • Limiting camera angles
  • Bounding UI element positions
  • Normalizing input values
Parameters
valueValue to be clamped
minMinimum allowed value
maxMaximum allowed value
Returns
Clamped value
Note
Assumes min <= max

◆ CubicEaseIn()

static constexpr Fxp SRL::Math::Interpolation::CubicEaseIn ( const Fxp & start,
const Fxp & end,
const Fxp & t )
inlinestaticconstexpr

Cubic ease-in interpolation for stronger acceleration.

Implements cubic easing using the formula: t³

The easing produces this motion:

  • Very slow start
  • Rapid acceleration
  • Maximum velocity at end

Common uses:

  • Dramatic entrances
  • Power-up effects
  • Explosion start
  • Heavy object movement
Parameters
startStarting value of the interpolation
endEnding value of the interpolation
tInterpolation factor in range [0,1]
Returns
Eased value
Note
More pronounced than quadratic EaseIn

◆ CubicEaseOut()

static constexpr Fxp SRL::Math::Interpolation::CubicEaseOut ( const Fxp & start,
const Fxp & end,
const Fxp & t )
inlinestaticconstexpr

Cubic ease-out interpolation for stronger deceleration.

Implements cubic easing using the formula: (t - 1)³ + 1

The easing produces this motion:

  • Maximum velocity at start
  • Rapid deceleration
  • Very slow end

Common uses:

  • Dramatic exits
  • Impact effects
  • Explosion end
  • Heavy object stopping
Parameters
startStarting value of the interpolation
endEnding value of the interpolation
tInterpolation factor in range [0,1]
Returns
Eased value
Note
More pronounced than quadratic EaseOut

◆ EaseIn()

static constexpr Fxp SRL::Math::Interpolation::EaseIn ( const Fxp & start,
const Fxp & end,
const Fxp & t )
inlinestaticconstexpr

Quadratic ease-in interpolation for accelerating motion.

Implements quadratic easing using the formula: t²

The easing produces this motion:

  • Starts slow (zero velocity)
  • Continuously accelerates
  • Reaches full velocity at end

Common uses:

  • Character movement startup
  • UI element entrance
  • Zoom-in effects
  • Power-up animations
Parameters
startStarting value of the interpolation
endEnding value of the interpolation
tInterpolation factor in range [0,1]
Returns
Eased value
Note
For symmetric animation, pair with EaseOut

◆ EaseOut()

static constexpr Fxp SRL::Math::Interpolation::EaseOut ( const Fxp & start,
const Fxp & end,
const Fxp & t )
inlinestaticconstexpr

Quadratic ease-out interpolation for decelerating motion.

Implements quadratic easing using the formula: -t * (t - 2)

The easing produces this motion:

  • Starts at full velocity
  • Continuously decelerates
  • Stops smoothly (zero velocity)

Common uses:

  • Character movement stop
  • UI element exit
  • Zoom-out effects
  • Landing animations
Parameters
startStarting value of the interpolation
endEnding value of the interpolation
tInterpolation factor in range [0,1]
Returns
Eased value
Note
For symmetric animation, pair with EaseIn

◆ ElasticEaseIn()

static constexpr Fxp SRL::Math::Interpolation::ElasticEaseIn ( const Fxp & start,
const Fxp & end,
const Fxp & t )
inlinestaticconstexpr

Elastic ease-in interpolation for spring-like motion.

Implements elastic easing with configurable period and amplitude. Uses quadratic approximation of sine for efficiency.

The easing produces this motion:

  • Multiple overshoots
  • Decreasing amplitude
  • Final snap to position

Common uses:

  • Menu bounces
  • Character stretching
  • Projectile charge-up
  • Spring animations
Parameters
startStarting value of the interpolation
endEnding value of the interpolation
tInterpolation factor in range [0,1]
Returns
Eased value
Note
Uses approximated sine to avoid trigonometric tables

◆ Lerp()

static constexpr Fxp SRL::Math::Interpolation::Lerp ( const Fxp & start,
const Fxp & end,
const Fxp & t )
inlinestaticconstexpr

Linear interpolation between two fixed-point values.

Performs linear interpolation (lerp) between start and end values using the formula: result = start + (end - start) * t

The interpolation follows this pattern:

  • When t = 0, returns start
  • When t = 1, returns end
  • When t = 0.5, returns the midpoint

Common uses:

  • Camera movement
  • UI element transitions
  • Color blending
  • Position interpolation
Parameters
startStarting value of the interpolation
endEnding value of the interpolation
tInterpolation factor in range [0,1]
Returns
Interpolated value
Note
For best performance, ensure t is pre-clamped to [0,1]

◆ Smoothstep()

static constexpr Fxp SRL::Math::Interpolation::Smoothstep ( const Fxp & start,
const Fxp & end,
const Fxp & t )
inlinestaticconstexpr

Smoothstep interpolation for smooth acceleration and deceleration.

Implements Ken Perlin's smoothstep function using the formula: 3t² - 2t³

The smoothstep produces this behavior:

  • Smooth acceleration from start
  • Constant velocity at midpoint
  • Smooth deceleration to end

Common uses:

  • Camera transitions
  • Smooth UI animations
  • Particle system parameters
  • Fade effects
Parameters
startStarting value of the interpolation
endEnding value of the interpolation
tInterpolation factor, automatically clamped to [0,1]
Returns
Smoothly interpolated value
Note
Automatically clamps input t to [0,1] for safety