ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
DampedSpring.h
Go to the documentation of this file.
1/**
2 * @file DampedSpring.h
3 * @brief Defines the DampedSpring class for simulating damped spring motion.
4 *
5 * The DampedSpring class provides a simple physical simulation of a damped spring,
6 * modeling its position and velocity over time based on a target position, spring
7 * constant, and damping factor.
8 *
9 * @date 22/12/2024
10 * @version 1.0
11 * @author Coela Can't
12 */
13
14#pragma once
15
16#include "../../Utils/Math/Mathematics.h"
17
18/**
19 * @class DampedSpring
20 * @brief Simulates the motion of a damped spring.
21 */
23private:
24 float currentVelocity; ///< Current velocity of the spring.
25 float currentPosition; ///< Current position of the spring.
26 float springConstant; ///< Spring constant determining stiffness.
27 float springForce; ///< Force exerted by the spring.
28 float dampingForce; ///< Damping force resisting motion.
29 float force; ///< Combined force acting on the spring.
30 float damping; ///< Damping coefficient.
31 unsigned long previousMillis; ///< Previous timestamp for time calculations.
32
33public:
34 /**
35 * @brief Default constructor initializing a damped spring with default values.
36 */
38
39 /**
40 * @brief Constructs a DampedSpring with specified spring constant and damping.
41 * @param springConstant Spring constant determining stiffness.
42 * @param damping Damping coefficient.
43 */
45
46 /**
47 * @brief Gets the current position of the spring.
48 * @return Current position as a float.
49 */
50 float GetCurrentPosition();
51
52 /**
53 * @brief Sets the spring constant and damping coefficient.
54 * @param springConstant New spring constant.
55 * @param damping New damping coefficient.
56 */
57 void SetConstants(float springConstant, float damping);
58
59 /**
60 * @brief Calculates the spring's position and velocity using a target position and timestamp.
61 * @param target Target position for the spring.
62 * @param currentMillis Current time in milliseconds.
63 * @return Updated position as a float.
64 */
65 float Calculate(float target, unsigned long currentMillis);
66
67 /**
68 * @brief Calculates the spring's position and velocity using a target position and delta time.
69 * @param target Target position for the spring.
70 * @param dT Time step in seconds.
71 * @return Updated position as a float.
72 */
73 float Calculate(float target, float dT);
74};
Simulates the motion of a damped spring.
float currentVelocity
Current velocity of the spring.
float springForce
Force exerted by the spring.
float Calculate(float target, unsigned long currentMillis)
Calculates the spring's position and velocity using a target position and timestamp.
float currentPosition
Current position of the spring.
unsigned long previousMillis
Previous timestamp for time calculations.
float springConstant
Spring constant determining stiffness.
float GetCurrentPosition()
Gets the current position of the spring.
float damping
Damping coefficient.
DampedSpring()
Default constructor initializing a damped spring with default values.
void SetConstants(float springConstant, float damping)
Sets the spring constant and damping coefficient.
float dampingForce
Damping force resisting motion.
float force
Combined force acting on the spring.