ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
BouncePhysics.h
Go to the documentation of this file.
1/**
2 * @file BouncePhysics.h
3 * @brief Defines the BouncePhysics class for simulating basic bouncing physics with velocity and gravity.
4 *
5 * The BouncePhysics class provides functionality to simulate a simple bouncing motion
6 * influenced by gravity and velocity damping. It also includes filtering for smoother velocity calculations.
7 *
8 * @date 22/12/2024
9 * @version 1.0
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include "../../Utils/Math/Mathematics.h"
16#include "../../Utils/Filter/RunningAverageFilter.h"
17
18/**
19 * @class BouncePhysics
20 * @brief Simulates bouncing physics with gravity and velocity damping.
21 */
23private:
24 RunningAverageFilter<10> velocityFilter; ///< Filter to smooth out velocity fluctuations.
25 float currentVelocity; ///< Current velocity of the object.
26 float currentPosition; ///< Current position of the object.
27 float velocityRatio; ///< Ratio to control velocity damping.
28 float gravity; ///< Gravity constant affecting the motion.
29 unsigned long previousMillis; ///< Stores the last timestamp for time-based calculations.
30 float previousVelocity; ///< Tracks the velocity from the previous update.
31
32public:
33 /**
34 * @brief Constructs a BouncePhysics object with the specified gravity and velocity ratio.
35 * @param gravity Gravitational acceleration affecting the bounce.
36 * @param velocityRatio Damping ratio for the velocity (default is 1.0).
37 */
38 BouncePhysics(float gravity, float velocityRatio = 1.0f);
39
40 /**
41 * @brief Calculates the new position and velocity based on the current velocity and time.
42 * @param velocity Initial velocity to calculate the bounce.
43 * @param currentMillis Current time in milliseconds.
44 * @return Updated position after applying physics.
45 */
46 float Calculate(float velocity, unsigned long currentMillis);
47
48 /**
49 * @brief Calculates the new position and velocity based on the current velocity and time delta.
50 * @param velocity Initial velocity to calculate the bounce.
51 * @param dT Time delta in seconds.
52 * @return Updated position after applying physics.
53 */
54 float Calculate(float velocity, float dT);
55};
Simulates bouncing physics with gravity and velocity damping.
float velocityRatio
Ratio to control velocity damping.
float currentVelocity
Current velocity of the object.
float Calculate(float velocity, unsigned long currentMillis)
Calculates the new position and velocity based on the current velocity and time.
RunningAverageFilter< 10 > velocityFilter
Filter to smooth out velocity fluctuations.
float gravity
Gravity constant affecting the motion.
float currentPosition
Current position of the object.
unsigned long previousMillis
Stores the last timestamp for time-based calculations.
float previousVelocity
Tracks the velocity from the previous update.
Smooths data values using a weighted running average.