ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
RampFilter.h
Go to the documentation of this file.
1/**
2 * @file RampFilter.h
3 * @brief Provides a class for smooth value transitions using a ramp filter.
4 *
5 * The `RampFilter` class ensures smooth transitions between values by incrementally
6 * adjusting towards the target value. It is particularly useful in animations and signal processing.
7 *
8 * @date 22/12/2024
9 * @version 1.0
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include "../Math/Mathematics.h"
16
17/**
18 * @class RampFilter
19 * @brief Smooths transitions between values using a linear ramp approach.
20 *
21 * This class incrementally adjusts an internal filter value towards a target,
22 * ensuring smooth transitions.
23 */
25private:
26 float increment; ///< The step size for each frame of the transition.
27 float filter; ///< The current filtered value.
28 float epsilon; ///< A small tolerance to determine when to stop adjusting.
29
30public:
31 /**
32 * @brief Default constructor for `RampFilter`.
33 *
34 * Initializes the filter with default parameters.
35 */
36 RampFilter();
37
38 /**
39 * @brief Constructs a `RampFilter` with a specified transition duration and epsilon.
40 *
41 * @param frames The number of frames for a complete transition.
42 * @param epsilon The tolerance for considering the transition complete.
43 */
44 RampFilter(int frames, float epsilon = 0.01f);
45
46 /**
47 * @brief Applies the ramp filter to the specified target value.
48 *
49 * Smoothly transitions the internal filter value towards the given target.
50 *
51 * @param value The target value to filter towards.
52 * @return The filtered value.
53 */
54 float Filter(float value);
55
56 /**
57 * @brief Sets the increment for each transition step.
58 *
59 * @param increment The step size for each frame of the transition.
60 */
61 void SetIncrement(float increment);
62
63 /**
64 * @brief Sets the number of frames for a complete transition.
65 *
66 * Automatically calculates the increment based on the number of frames.
67 *
68 * @param frames The number of frames for a complete transition.
69 */
70 void SetFrames(int frames);
71};
Smooths transitions between values using a linear ramp approach.
Definition RampFilter.h:24
void SetIncrement(float increment)
Sets the increment for each transition step.
float epsilon
A small tolerance to determine when to stop adjusting.
Definition RampFilter.h:28
float Filter(float value)
Applies the ramp filter to the specified target value.
float filter
The current filtered value.
Definition RampFilter.h:27
float increment
The step size for each frame of the transition.
Definition RampFilter.h:26
RampFilter()
Default constructor for RampFilter.
Definition RampFilter.cpp:3
void SetFrames(int frames)
Sets the number of frames for a complete transition.