ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
BouncePhysics Class Reference

Simulates bouncing physics with gravity and velocity damping. More...

#include <BouncePhysics.h>

Collaboration diagram for BouncePhysics:

Public Member Functions

 BouncePhysics (float gravity, float velocityRatio=1.0f)
 Constructs a BouncePhysics object with the specified gravity and velocity ratio.
 
float Calculate (float velocity, unsigned long currentMillis)
 Calculates the new position and velocity based on the current velocity and time.
 
float Calculate (float velocity, float dT)
 Calculates the new position and velocity based on the current velocity and time delta.
 

Private Attributes

RunningAverageFilter< 10 > velocityFilter
 Filter to smooth out velocity fluctuations.
 
float currentVelocity
 Current velocity of the object.
 
float currentPosition
 Current position of the object.
 
float velocityRatio
 Ratio to control velocity damping.
 
float gravity
 Gravity constant affecting the motion.
 
unsigned long previousMillis
 Stores the last timestamp for time-based calculations.
 
float previousVelocity
 Tracks the velocity from the previous update.
 

Detailed Description

Simulates bouncing physics with gravity and velocity damping.

Definition at line 22 of file BouncePhysics.h.

Constructor & Destructor Documentation

◆ BouncePhysics()

BouncePhysics ( float  gravity,
float  velocityRatio = 1.0f 
)

Constructs a BouncePhysics object with the specified gravity and velocity ratio.

Parameters
gravityGravitational acceleration affecting the bounce.
velocityRatioDamping ratio for the velocity (default is 1.0).

Definition at line 3 of file BouncePhysics.cpp.

Member Function Documentation

◆ Calculate() [1/2]

float Calculate ( float  velocity,
float  dT 
)

Calculates the new position and velocity based on the current velocity and time delta.

Parameters
velocityInitial velocity to calculate the bounce.
dTTime delta in seconds.
Returns
Updated position after applying physics.

Definition at line 26 of file BouncePhysics.cpp.

References currentPosition, currentVelocity, RunningAverageFilter< memory >::Filter(), gravity, previousVelocity, velocityFilter, and velocityRatio.

◆ Calculate() [2/2]

float Calculate ( float  velocity,
unsigned long  currentMillis 
)

Calculates the new position and velocity based on the current velocity and time.

Parameters
velocityInitial velocity to calculate the bounce.
currentMillisCurrent time in milliseconds.
Returns
Updated position after applying physics.

Definition at line 13 of file BouncePhysics.cpp.

References currentPosition, currentVelocity, gravity, previousMillis, and velocityRatio.

Referenced by AudioReactiveGradient::Update(), and SpectrumAnalyzer::Update().

Member Data Documentation

◆ currentPosition

float currentPosition
private

Current position of the object.

Definition at line 26 of file BouncePhysics.h.

Referenced by Calculate(), and Calculate().

◆ currentVelocity

float currentVelocity
private

Current velocity of the object.

Definition at line 25 of file BouncePhysics.h.

Referenced by Calculate(), and Calculate().

◆ gravity

float gravity
private

Gravity constant affecting the motion.

Definition at line 28 of file BouncePhysics.h.

Referenced by Calculate(), and Calculate().

◆ previousMillis

unsigned long previousMillis
private

Stores the last timestamp for time-based calculations.

Definition at line 29 of file BouncePhysics.h.

Referenced by Calculate().

◆ previousVelocity

float previousVelocity
private

Tracks the velocity from the previous update.

Definition at line 30 of file BouncePhysics.h.

Referenced by Calculate().

◆ velocityFilter

RunningAverageFilter<10> velocityFilter
private

Filter to smooth out velocity fluctuations.

Definition at line 24 of file BouncePhysics.h.

Referenced by Calculate().

◆ velocityRatio

float velocityRatio
private

Ratio to control velocity damping.

Definition at line 27 of file BouncePhysics.h.

Referenced by Calculate(), and Calculate().


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