![]() |
ProtoTracer
1.0
Real-time 3D rendering and animation engine
|
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. | |
Simulates the motion of a damped spring.
Definition at line 22 of file DampedSpring.h.
DampedSpring | ( | ) |
Default constructor initializing a damped spring with default values.
Definition at line 3 of file DampedSpring.cpp.
DampedSpring | ( | float | springConstant, |
float | damping | ||
) |
Constructs a DampedSpring with specified spring constant and damping.
springConstant | Spring constant determining stiffness. |
damping | Damping coefficient. |
Definition at line 14 of file DampedSpring.cpp.
Calculates the spring's position and velocity using a target position and delta time.
target | Target position for the spring. |
dT | Time step in seconds. |
Definition at line 51 of file DampedSpring.cpp.
References currentPosition, currentVelocity, damping, dampingForce, force, Mathematics::IsClose(), springConstant, and springForce.
Calculates the spring's position and velocity using a target position and timestamp.
target | Target position for the spring. |
currentMillis | Current time in milliseconds. |
Definition at line 34 of file DampedSpring.cpp.
References currentPosition, currentVelocity, damping, dampingForce, force, previousMillis, springConstant, and springForce.
Referenced by Menu::Update().
float GetCurrentPosition | ( | ) |
Gets the current position of the spring.
Definition at line 25 of file DampedSpring.cpp.
References currentPosition.
Sets the spring constant and damping coefficient.
springConstant | New spring constant. |
damping | New damping coefficient. |
Definition at line 29 of file DampedSpring.cpp.
References damping, and springConstant.
Referenced by Menu::Initialize(), and Menu::Initialize().
|
private |
Current position of the spring.
Definition at line 25 of file DampedSpring.h.
Referenced by Calculate(), Calculate(), and GetCurrentPosition().
|
private |
Current velocity of the spring.
Definition at line 24 of file DampedSpring.h.
Referenced by Calculate(), and Calculate().
|
private |
Damping coefficient.
Definition at line 30 of file DampedSpring.h.
Referenced by Calculate(), Calculate(), and SetConstants().
|
private |
Damping force resisting motion.
Definition at line 28 of file DampedSpring.h.
Referenced by Calculate(), and Calculate().
|
private |
Combined force acting on the spring.
Definition at line 29 of file DampedSpring.h.
Referenced by Calculate(), and Calculate().
Previous timestamp for time calculations.
Definition at line 31 of file DampedSpring.h.
Referenced by Calculate().
|
private |
Spring constant determining stiffness.
Definition at line 26 of file DampedSpring.h.
Referenced by Calculate(), Calculate(), and SetConstants().
|
private |
Force exerted by the spring.
Definition at line 27 of file DampedSpring.h.
Referenced by Calculate(), and Calculate().