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

Simulates the motion of a damped spring. More...

#include <DampedSpring.h>

Public Member Functions

 DampedSpring ()
 Default constructor initializing a damped spring with default values.
 
 DampedSpring (float springConstant, float damping)
 Constructs a DampedSpring with specified spring constant and damping.
 
float GetCurrentPosition ()
 Gets the current position of the spring.
 
void SetConstants (float springConstant, float damping)
 Sets the spring constant and damping coefficient.
 
float Calculate (float target, unsigned long currentMillis)
 Calculates the spring's position and velocity using a target position and timestamp.
 
float Calculate (float target, float dT)
 Calculates the spring's position and velocity using a target position and delta time.
 

Private Attributes

float currentVelocity
 Current velocity of the spring.
 
float currentPosition
 Current position of the spring.
 
float springConstant
 Spring constant determining stiffness.
 
float springForce
 Force exerted by the spring.
 
float dampingForce
 Damping force resisting motion.
 
float force
 Combined force acting on the spring.
 
float damping
 Damping coefficient.
 
unsigned long previousMillis
 Previous timestamp for time calculations.
 

Detailed Description

Simulates the motion of a damped spring.

Definition at line 22 of file DampedSpring.h.

Constructor & Destructor Documentation

◆ DampedSpring() [1/2]

Default constructor initializing a damped spring with default values.

Definition at line 3 of file DampedSpring.cpp.

◆ DampedSpring() [2/2]

DampedSpring ( float  springConstant,
float  damping 
)

Constructs a DampedSpring with specified spring constant and damping.

Parameters
springConstantSpring constant determining stiffness.
dampingDamping coefficient.

Definition at line 14 of file DampedSpring.cpp.

Member Function Documentation

◆ Calculate() [1/2]

float Calculate ( float  target,
float  dT 
)

Calculates the spring's position and velocity using a target position and delta time.

Parameters
targetTarget position for the spring.
dTTime step in seconds.
Returns
Updated position as a float.

Definition at line 51 of file DampedSpring.cpp.

References currentPosition, currentVelocity, damping, dampingForce, force, Mathematics::IsClose(), springConstant, and springForce.

◆ Calculate() [2/2]

float Calculate ( float  target,
unsigned long  currentMillis 
)

Calculates the spring's position and velocity using a target position and timestamp.

Parameters
targetTarget position for the spring.
currentMillisCurrent time in milliseconds.
Returns
Updated position as a float.

Definition at line 34 of file DampedSpring.cpp.

References currentPosition, currentVelocity, damping, dampingForce, force, previousMillis, springConstant, and springForce.

Referenced by Menu::Update().

◆ GetCurrentPosition()

float GetCurrentPosition ( )

Gets the current position of the spring.

Returns
Current position as a float.

Definition at line 25 of file DampedSpring.cpp.

References currentPosition.

◆ SetConstants()

void SetConstants ( float  springConstant,
float  damping 
)

Sets the spring constant and damping coefficient.

Parameters
springConstantNew spring constant.
dampingNew damping coefficient.

Definition at line 29 of file DampedSpring.cpp.

References damping, and springConstant.

Referenced by Menu::Initialize(), and Menu::Initialize().

Member Data Documentation

◆ currentPosition

float currentPosition
private

Current position of the spring.

Definition at line 25 of file DampedSpring.h.

Referenced by Calculate(), Calculate(), and GetCurrentPosition().

◆ currentVelocity

float currentVelocity
private

Current velocity of the spring.

Definition at line 24 of file DampedSpring.h.

Referenced by Calculate(), and Calculate().

◆ damping

float damping
private

Damping coefficient.

Definition at line 30 of file DampedSpring.h.

Referenced by Calculate(), Calculate(), and SetConstants().

◆ dampingForce

float dampingForce
private

Damping force resisting motion.

Definition at line 28 of file DampedSpring.h.

Referenced by Calculate(), and Calculate().

◆ force

float force
private

Combined force acting on the spring.

Definition at line 29 of file DampedSpring.h.

Referenced by Calculate(), and Calculate().

◆ previousMillis

unsigned long previousMillis
private

Previous timestamp for time calculations.

Definition at line 31 of file DampedSpring.h.

Referenced by Calculate().

◆ springConstant

float springConstant
private

Spring constant determining stiffness.

Definition at line 26 of file DampedSpring.h.

Referenced by Calculate(), Calculate(), and SetConstants().

◆ springForce

float springForce
private

Force exerted by the spring.

Definition at line 27 of file DampedSpring.h.

Referenced by Calculate(), and Calculate().


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