ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
EasyEaseAnimator.h
Go to the documentation of this file.
1/**
2 * @file EasyEaseAnimator.h
3 * @brief Declares the EasyEaseAnimator template class for advanced animation easing.
4 *
5 * This file defines the EasyEaseAnimator class, which implements the IEasyEaseAnimator
6 * interface and provides functionalities for smooth and customizable animations using
7 * various interpolation methods, damped springs, and ramp filters.
8 *
9 * @author Coela Can't
10 * @date 22/12/2024
11 */
12
13#pragma once
14
15#include "IEasyEaseAnimator.h" // Include for base interface class.
16
17/**
18 * @class EasyEaseAnimator
19 * @brief A template class for implementing advanced animation easing.
20 *
21 * The EasyEaseAnimator class provides a framework for animating parameters with smooth
22 * transitions using a combination of interpolation methods, damped springs, and ramp filters.
23 *
24 * @tparam maxParameters The maximum number of parameters this animator can handle.
25 */
26template<size_t maxParameters>
28private:
29 InterpolationMethod interpMethod; ///< The global interpolation method for the animator.
30 DampedSpring dampedSpring[maxParameters]; ///< Array of damped springs for smooth animations.
31 RampFilter rampFilter[maxParameters]; ///< Array of ramp filters for controlling transitions.
32 float* parameters[maxParameters]; ///< Array of pointers to animated parameters.
33 float parameterFrame[maxParameters]; ///< Current frame values for each parameter.
34 float previousSet[maxParameters]; ///< Previous set values for each parameter.
35 float basis[maxParameters]; ///< Basis values for each parameter.
36 float goal[maxParameters]; ///< Target values for each parameter.
37 uint8_t interpolationMethods[maxParameters]; ///< Interpolation methods for each parameter.
38 uint16_t dictionary[maxParameters]; ///< Dictionary mapping for parameter lookup.
39 uint16_t currentParameters = 0; ///< Number of currently active parameters.
40 bool isActive = true; ///< Indicates whether the animator is active.
41
42public:
43 /**
44 * @brief Constructs an EasyEaseAnimator object with the specified interpolation method.
45 *
46 * @param interpMethod The default interpolation method.
47 * @param springConstant The default spring constant for damped springs.
48 * @param dampingConstant The default damping constant for damped springs.
49 */
50 EasyEaseAnimator(InterpolationMethod interpMethod, float springConstant = 1.0f, float dampingConstant = 0.5f);
51
52 /**
53 * @brief Sets spring and damping constants for a specific parameter.
54 *
55 * @param dictionaryValue The parameter's dictionary identifier.
56 * @param springConstant The spring constant to set.
57 * @param damping The damping constant to set.
58 */
59 void SetConstants(uint16_t dictionaryValue, float springConstant, float damping) override;
60
61 /**
62 * @brief Gets the current value of a parameter.
63 *
64 * @param dictionaryValue The parameter's dictionary identifier.
65 * @return The current value of the parameter.
66 */
67 float GetValue(uint16_t dictionaryValue) override;
68
69 /**
70 * @brief Gets the target value of a parameter.
71 *
72 * @param dictionaryValue The parameter's dictionary identifier.
73 * @return The target value of the parameter.
74 */
75 float GetTarget(uint16_t dictionaryValue) override;
76
77 /**
78 * @brief Adds a parameter to the animator.
79 *
80 * @param parameter A pointer to the parameter to animate.
81 * @param dictionaryValue The parameter's dictionary identifier.
82 * @param frames The number of frames for the transition.
83 * @param basis The initial basis value.
84 * @param goal The target goal value.
85 */
86 void AddParameter(float* parameter, uint16_t dictionaryValue, uint16_t frames, float basis, float goal) override;
87
88 /**
89 * @brief Adds a single frame value for a parameter.
90 *
91 * @param dictionaryValue The parameter's dictionary identifier.
92 * @param value The frame value to add.
93 */
94 void AddParameterFrame(uint16_t dictionaryValue, float value) override;
95
96 /**
97 * @brief Sets the interpolation method for a specific parameter.
98 *
99 * @param dictionaryValue The parameter's dictionary identifier.
100 * @param interpMethod The interpolation method to set.
101 */
102 void SetInterpolationMethod(uint16_t dictionaryValue, InterpolationMethod interpMethod) override;
103
104 /**
105 * @brief Resets the animator to its initial state.
106 */
107 void Reset() override;
108
109 /**
110 * @brief Applies the current animation values to the parameters.
111 */
112 void SetParameters() override;
113
114 /**
115 * @brief Updates the animator, advancing all animations.
116 */
117 void Update() override;
118};
119
120#include "EasyEaseAnimator.tpp" // Include the template implementation.
Declares the IEasyEaseAnimator interface for defining animation behaviors.
Simulates the motion of a damped spring.
A template class for implementing advanced animation easing.
DampedSpring dampedSpring[maxParameters]
Array of damped springs for smooth animations.
uint16_t dictionary[maxParameters]
Dictionary mapping for parameter lookup.
uint16_t currentParameters
Number of currently active parameters.
EasyEaseAnimator(InterpolationMethod interpMethod, float springConstant=1.0f, float dampingConstant=0.5f)
Constructs an EasyEaseAnimator object with the specified interpolation method.
float GetValue(uint16_t dictionaryValue) override
Gets the current value of a parameter.
float GetTarget(uint16_t dictionaryValue) override
Gets the target value of a parameter.
void SetParameters() override
Applies the current animation values to the parameters.
void AddParameterFrame(uint16_t dictionaryValue, float value) override
Adds a single frame value for a parameter.
float parameterFrame[maxParameters]
Current frame values for each parameter.
bool isActive
Indicates whether the animator is active.
void SetConstants(uint16_t dictionaryValue, float springConstant, float damping) override
Sets spring and damping constants for a specific parameter.
InterpolationMethod interpMethod
The global interpolation method for the animator.
float goal[maxParameters]
Target values for each parameter.
float * parameters[maxParameters]
Array of pointers to animated parameters.
void Update() override
Updates the animator, advancing all animations.
float basis[maxParameters]
Basis values for each parameter.
void SetInterpolationMethod(uint16_t dictionaryValue, InterpolationMethod interpMethod) override
Sets the interpolation method for a specific parameter.
uint8_t interpolationMethods[maxParameters]
Interpolation methods for each parameter.
RampFilter rampFilter[maxParameters]
Array of ramp filters for controlling transitions.
void Reset() override
Resets the animator to its initial state.
float previousSet[maxParameters]
Previous set values for each parameter.
void AddParameter(float *parameter, uint16_t dictionaryValue, uint16_t frames, float basis, float goal) override
Adds a parameter to the animator.
Interface for defining animation behaviors with easing and interpolation.
InterpolationMethod
Enumeration of interpolation methods for animations.
Smooths transitions between values using a linear ramp approach.
Definition RampFilter.h:24