ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
KeyFrameTrack.h
Go to the documentation of this file.
1/**
2 * @file KeyFrameTrack.h
3 * @brief Declares the KeyFrameTrack template class for managing keyframe-based animations.
4 *
5 * This file defines the KeyFrameTrack class, which provides functionality for managing
6 * keyframe-based animations, including parameter updates, interpolation, and playback controls.
7 *
8 * @author Coela Can't
9 * @date 22/12/2024
10 */
11
12#pragma once
13
14#include "KeyFrame.h" // Include for keyframe data structure.
15#include "../Utils/Math/Mathematics.h" // Include for mathematical utilities.
16
17/**
18 * @class KeyFrameInterpolation
19 * @brief Base class providing interpolation methods for keyframe animations.
20 *
21 * This class defines the available interpolation methods, which can be used for
22 * smooth transitions between keyframes in animations.
23 */
25public:
26 /**
27 * @enum InterpolationMethod
28 * @brief Enumeration of interpolation methods.
29 *
30 * Provides various methods for transitioning between keyframe values.
31 */
33 Linear, ///< Linear interpolation.
34 Cosine, ///< Smooth cosine interpolation.
35 Step ///< Step interpolation (discrete transitions).
36 };
37};
38
39/**
40 * @class KeyFrameTrack
41 * @brief A template class for managing animations with multiple parameters and keyframes.
42 *
43 * The KeyFrameTrack class handles animations by managing a set of parameters and their
44 * corresponding keyframes. It supports playback controls, interpolation, and time-based updates.
45 *
46 * @tparam maxParameters The maximum number of parameters this track can handle.
47 * @tparam maxKeyFrames The maximum number of keyframes this track can contain.
48 */
49template<size_t maxParameters, size_t maxKeyFrames>
51private:
52 InterpolationMethod interpMethod; ///< The interpolation method for the track.
53 float* parameters[maxParameters]; ///< Array of pointers to parameters being animated.
54 KeyFrame keyFrames[maxKeyFrames]; ///< Array of keyframes defining the animation.
55 float min = 0.0f; ///< Minimum value for the parameters.
56 float max = 0.0f; ///< Maximum value for the parameters.
57 float startFrameTime = Mathematics::FLTMAX; ///< Start time of the animation (initialized out of bounds).
58 float stopFrameTime = Mathematics::FLTMIN; ///< End time of the animation (initialized out of bounds).
59 uint8_t currentFrames = 0; ///< Current number of keyframes.
60 uint8_t currentParameters = 0; ///< Current number of parameters.
61 bool isActive = true; ///< Indicates whether the track is active.
62 float parameterValue = 0.0f; ///< Current interpolated parameter value.
63 float currentTime = 0.0f; ///< Current time of the animation.
64 float timeOffset = 0.0f; ///< Offset for the animation time.
65
66 /**
67 * @brief Shifts the keyframe array starting at a specific position.
68 *
69 * Used for reorganizing keyframes when inserting or removing elements.
70 *
71 * @param position The index from which to shift the keyframe array.
72 */
73 void ShiftKeyFrameArray(int position);
74
75public:
76 /**
77 * @brief Constructs a KeyFrameTrack object with the specified settings.
78 *
79 * @param min The minimum value for the parameters.
80 * @param max The maximum value for the parameters.
81 * @param interpMethod The interpolation method for the track.
82 */
84
85 /**
86 * @brief Retrieves the current animation time.
87 *
88 * @return The current time of the animation.
89 */
91
92 /**
93 * @brief Sets the current animation time.
94 *
95 * @param setTime The new current time to set.
96 */
97 void SetCurrentTime(float setTime);
98
99 /**
100 * @brief Pauses the animation.
101 */
102 void Pause();
103
104 /**
105 * @brief Resumes the animation.
106 */
107 void Play();
108
109 /**
110 * @brief Adds a parameter to the track.
111 *
112 * @param parameter A pointer to the parameter to be animated.
113 */
114 void AddParameter(float* parameter);
115
116 /**
117 * @brief Adds a keyframe to the track.
118 *
119 * @param time The time of the keyframe.
120 * @param value The value of the keyframe.
121 */
122 void AddKeyFrame(float time, float value);
123
124 /**
125 * @brief Retrieves the current interpolated parameter value.
126 *
127 * @return The current value of the parameter.
128 */
130
131 /**
132 * @brief Resets the animation track to its initial state.
133 */
134 void Reset();
135
136 /**
137 * @brief Updates the animation track and computes the new parameter value.
138 *
139 * @return The updated parameter value.
140 */
141 float Update();
142};
143
144#include "KeyFrameTrack.tpp" // Include the template implementation.
Declares the KeyFrame class for representing individual animation keyframes.
Base class providing interpolation methods for keyframe animations.
InterpolationMethod
Enumeration of interpolation methods.
@ Linear
Linear interpolation.
@ Step
Step interpolation (discrete transitions).
@ Cosine
Smooth cosine interpolation.
A template class for managing animations with multiple parameters and keyframes.
void AddParameter(float *parameter)
Adds a parameter to the track.
float GetCurrentTime()
Retrieves the current animation time.
void Play()
Resumes the animation.
float max
Maximum value for the parameters.
void Reset()
Resets the animation track to its initial state.
void AddKeyFrame(float time, float value)
Adds a keyframe to the track.
float GetParameterValue()
Retrieves the current interpolated parameter value.
float stopFrameTime
End time of the animation (initialized out of bounds).
uint8_t currentParameters
Current number of parameters.
void Pause()
Pauses the animation.
void ShiftKeyFrameArray(int position)
Shifts the keyframe array starting at a specific position.
KeyFrame keyFrames[maxKeyFrames]
Array of keyframes defining the animation.
uint8_t currentFrames
Current number of keyframes.
float Update()
Updates the animation track and computes the new parameter value.
bool isActive
Indicates whether the track is active.
float currentTime
Current time of the animation.
InterpolationMethod interpMethod
The interpolation method for the track.
float * parameters[maxParameters]
Array of pointers to parameters being animated.
KeyFrameTrack(float min, float max, InterpolationMethod interpMethod)
Constructs a KeyFrameTrack object with the specified settings.
float startFrameTime
Start time of the animation (initialized out of bounds).
float min
Minimum value for the parameters.
void SetCurrentTime(float setTime)
Sets the current animation time.
float parameterValue
Current interpolated parameter value.
float timeOffset
Offset for the animation time.
Represents a single keyframe in an animation.
Definition KeyFrame.h:21
static const float FLTMIN
Minimum float value (shortcut to a very small or near-zero number).
Definition Mathematics.h:62
static const float FLTMAX
Maximum float value (shortcut to a large number).
Definition Mathematics.h:57