VR-Engage  2.2
Loading...
Searching...
No Matches
bezierInterpolator.h
Go to the documentation of this file.
1/*********************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*********************************************************************************/
5
6#pragma once
7
8//! \file bezierInterpolator.h
9//! \brief Provides a template class for Bezier curve-based interpolation
10
11#include <vrvUtil/DtEaser.h>
12
13namespace makVre
14{
15//! \brief Bezier curve-based interpolation template class
16//!
17//! This template class provides interpolation between start and end values
18//! using Bezier curves for easing over a specified time period.
19//! Specializations are provided for float, double, DtVector, and DtQuat types.
20//!
21//! \tparam T The type of value to interpolate
22template <typename T>
24{
25public:
26 //! \brief Constructor
27 //!
28 //! Initializes the interpolator with an easing function, start and end values,
29 //! and the time period.
30 //!
31 //! \param easer The easing function to use for interpolation
32 //! \param start The starting value
33 //! \param stop The ending value
34 //! \param period The time period over which to interpolate (in seconds)
35 DtBezierInterpolator(makVrv::DtEaser easer, T start, T stop, double period);
36
37 //! \brief Destructor
39
40 //! \brief Updates the interpolation based on elapsed time
41 //!
42 //! This function advances the interpolation by the given time step,
43 //! recalculating the current value based on the elapsed time and easing function.
44 //! Specialized implementations are provided for float, double, DtVector, and DtQuat.
45 //!
46 //! \param dt The time step in seconds
47 void tick(double dt);
48
49 //! \brief Gets the current interpolated value
50 //!
51 //! \return The current value of the interpolation
52 T value() const;
53
54 //! \brief Checks if the interpolation has completed
55 //!
56 //! \return true if the current time has reached or exceeded the period
57 bool isDone() const;
58
59 //! \brief Resets the interpolation to the beginning
60 //!
61 //! Sets the current value back to the start value and resets the time to zero
62 void reset();
63
64 //! \brief Resets the interpolation with new start, end, and period values
65 //!
66 //! \param start The new starting value
67 //! \param stop The new ending value
68 //! \param period The new time period (in seconds)
69 void reset(T start, T stop, double period);
70
71 //! \brief Resets the interpolation with a new easer and parameters
72 //!
73 //! \param easer The new easing function
74 //! \param start The new starting value
75 //! \param stop The new ending value
76 //! \param period The new time period (in seconds)
77 void reset(makVrv::DtEaser easer, T start, T stop, double period);
78
79 //! \brief Gets the start value
80 //!
81 //! \return The start value of the interpolation
82 T start() const;
83
84 //! \brief Gets the end value
85 //!
86 //! \return The end value of the interpolation
87 T stop() const;
88
89 //! \brief Gets the time remaining in the interpolation
90 //!
91 //! \return The remaining time in seconds
92 double timeRemaining() const;
93
94protected:
95 //! \brief The easing function to use
96 makVrv::DtEaser myEaser;
97
98 //! \brief The starting value
100
101 //! \brief The ending value
103
104 //! \brief The current interpolated value
106
107 //! \brief The total time period for the interpolation (in seconds)
108 double myPeriod;
109
110 //! \brief The current elapsed time (in seconds)
112};
113
114// Implementation
115
116//! \brief Constructor implementation
117template <typename T>
118makVre::DtBezierInterpolator<T>::DtBezierInterpolator(makVrv::DtEaser easer, T start, T stop, double period)
119 : myEaser(easer)
120 , myStart(start)
121 , myEnd(stop)
123 , myCurrentTime(0)
124 , myPeriod(period)
125{
126}
127
128//! \brief Destructor implementation
129template <typename T>
133
134//! \brief Gets the current value of the interpolation
135template <typename T>
140
141//! \brief Gets the start value of the interpolation
142template <typename T>
144{
145 return myStart;
146}
147
148//! \brief Gets the end value of the interpolation
149template <typename T>
151{
152 return myEnd;
153}
154
155//! \brief Gets the time remaining in the interpolation
156template <typename T>
161
162//! \brief Checks if the interpolation has completed
163template <typename T>
165{
166 return myCurrentTime >= myPeriod;
167}
168
169//! \brief Resets the interpolation to the beginning
170template <typename T>
176
177//! \brief Resets the interpolation with new parameters
178template <typename T>
180{
181 myStart = start;
182 myEnd = stop;
183 myPeriod = period;
185 myCurrentTime = 0.0;
186}
187
188//! \brief Resets the interpolation with a new easer and parameters
189template <typename T>
190void makVre::DtBezierInterpolator<T>::reset(makVrv::DtEaser easer, T start, T stop, double period)
191{
192 myEaser = easer;
193 myStart = start;
194 myEnd = stop;
195 myPeriod = period;
197 myCurrentTime = 0.0;
198}
199
200//! \brief Namespace containing predefined easing functions
201//!
202//! This namespace provides a collection of standard easing functions
203//! for use with the DtBezierInterpolator class. Each function returns
204//! a properly configured DtEaser object for a specific easing type.
205namespace Eases
206{
207//! \brief Creates an ease-in sine function
208//! \return A DtEaser configured for sine ease-in
209static makVrv::DtEaser EaseInSine()
210{
211 return makVrv::DtEaser(0.12f, 0.f, 0.39f, 0.f);
212};
213
214//! \brief Creates an ease-out sine function
215//! \return A DtEaser configured for sine ease-out
216static makVrv::DtEaser EaseOutSine()
217{
218 return makVrv::DtEaser(0.61f, 1.f, 0.88f, 1.f);
219};
220
221//! \brief Creates an ease-in-out sine function
222//! \return A DtEaser configured for sine ease-in-out
223static makVrv::DtEaser EaseInOutSine()
224{
225 return makVrv::DtEaser(0.37f, 0.f, 0.63f, 1.f);
226};
227
228//! \brief Creates an ease-in quadratic function
229//! \return A DtEaser configured for quadratic ease-in
230static makVrv::DtEaser EaseInQuad()
231{
232 return makVrv::DtEaser(0.11f, 0.f, 0.5f, 0.f);
233};
234
235//! \brief Creates an ease-out quadratic function
236//! \return A DtEaser configured for quadratic ease-out
237static makVrv::DtEaser EaseOutQuad()
238{
239 return makVrv::DtEaser(0.5f, 1.f, 0.89f, 1.f);
240};
241
242//! \brief Creates an ease-in-out quadratic function
243//! \return A DtEaser configured for quadratic ease-in-out
244static makVrv::DtEaser EaseInOutQuad()
245{
246 return makVrv::DtEaser(0.45f, 0.f, 0.55f, 1.f);
247};
248
249//! \brief Creates an ease-in cubic function
250//! \return A DtEaser configured for cubic ease-in
251static makVrv::DtEaser EaseInCubic()
252{
253 return makVrv::DtEaser(0.32f, 0.f, 0.67f, 0.f);
254};
255
256//! \brief Creates an ease-out cubic function
257//! \return A DtEaser configured for cubic ease-out
258static makVrv::DtEaser EaseOutCubic()
259{
260 return makVrv::DtEaser(0.33f, 1.f, 0.68f, 1.f);
261};
262
263//! \brief Creates an ease-in-out cubic function
264//! \return A DtEaser configured for cubic ease-in-out
265static makVrv::DtEaser EaseInOutCubic()
266{
267 return makVrv::DtEaser(0.65f, 0.f, 0.35f, 1.f);
268};
269
270//! \brief Creates an ease-in quartic function
271//! \return A DtEaser configured for quartic ease-in
272static makVrv::DtEaser EaseInQuart()
273{
274 return makVrv::DtEaser(0.5f, 0.f, 0.75f, 0.f);
275};
276
277//! \brief Creates an ease-out quartic function
278//! \return A DtEaser configured for quartic ease-out
279static makVrv::DtEaser EaseOutQuart()
280{
281 return makVrv::DtEaser(0.25f, 1.f, 0.5f, 1.f);
282};
283
284//! \brief Creates an ease-in-out quartic function
285//! \return A DtEaser configured for quartic ease-in-out
286static makVrv::DtEaser EaseInOutQuart()
287{
288 return makVrv::DtEaser(0.76f, 0.f, 0.24f, 1.f);
289};
290
291//! \brief Creates an ease-in quintic function
292//! \return A DtEaser configured for quintic ease-in
293static makVrv::DtEaser EaseInQuint()
294{
295 return makVrv::DtEaser(0.64f, 0.f, 0.78f, 0.f);
296};
297
298//! \brief Creates an ease-out quintic function
299//! \return A DtEaser configured for quintic ease-out
300static makVrv::DtEaser EaseOutQuint()
301{
302 return makVrv::DtEaser(0.22f, 1.f, 0.36f, 1.f);
303};
304
305//! \brief Creates an ease-in-out quintic function
306//! \return A DtEaser configured for quintic ease-in-out
307static makVrv::DtEaser EaseInOutQuint()
308{
309 return makVrv::DtEaser(0.83f, 0.f, 0.17f, 1.f);
310};
311
312//! \brief Creates an ease-in exponential function
313//! \return A DtEaser configured for exponential ease-in
314static makVrv::DtEaser EaseInExpo()
315{
316 return makVrv::DtEaser(0.7f, 0.f, 0.84f, 0.f);
317};
318
319//! \brief Creates an ease-out exponential function
320//! \return A DtEaser configured for exponential ease-out
321static makVrv::DtEaser EaseOutExpo()
322{
323 return makVrv::DtEaser(0.16f, 1.f, 0.3f, 1.f);
324};
325
326//! \brief Creates an ease-in-out exponential function
327//! \return A DtEaser configured for exponential ease-in-out
328static makVrv::DtEaser EaseInOutExpo()
329{
330 return makVrv::DtEaser(0.87f, 0.f, 0.13f, 1.f);
331};
332
333//! \brief Creates an ease-in circular function
334//! \return A DtEaser configured for circular ease-in
335static makVrv::DtEaser EaseInCirc()
336{
337 return makVrv::DtEaser(0.55f, 0.f, 1.f, 0.45f);
338};
339
340//! \brief Creates an ease-out circular function
341//! \return A DtEaser configured for circular ease-out
342static makVrv::DtEaser EaseOutCirc()
343{
344 return makVrv::DtEaser(0.f, 0.55f, 0.45f, 1.f);
345};
346
347//! \brief Creates an ease-in-out circular function
348//! \return A DtEaser configured for circular ease-in-out
349static makVrv::DtEaser EaseInOutCirc()
350{
351 return makVrv::DtEaser(0.85f, 0.f, 0.15f, 1.f);
352};
353
354//! \brief Creates an ease-in back function (overshoots backwards)
355//! \return A DtEaser configured for back ease-in
356static makVrv::DtEaser EaseInBack()
357{
358 return makVrv::DtEaser(0.36f, 0.f, 0.66f, -0.56f);
359};
360
361//! \brief Creates an ease-out back function (overshoots forwards)
362//! \return A DtEaser configured for back ease-out
363static makVrv::DtEaser EaseOutBack()
364{
365 return makVrv::DtEaser(0.34f, 1.56f, 0.64f, 1.f);
366};
367
368//! \brief Creates an ease-in-out back function (overshoots both ways)
369//! \return A DtEaser configured for back ease-in-out
370static makVrv::DtEaser EaseInOutBack()
371{
372 return makVrv::DtEaser(0.68f, -0.6f, 0.32f, 1.6f);
373};
374} // namespace Eases
375} // namespace makVre
double timeRemaining() const
Gets the time remaining in the interpolation.
Definition bezierInterpolator.h:157
~DtBezierInterpolator()
Destructor.
Definition bezierInterpolator.h:130
T myStart
The starting value.
Definition bezierInterpolator.h:99
T myEnd
The ending value.
Definition bezierInterpolator.h:102
void tick(double dt)
Updates the interpolation based on elapsed time.
double myCurrentTime
The current elapsed time (in seconds)
Definition bezierInterpolator.h:111
DtVector start() const
Definition bezierInterpolator.h:143
bool isDone() const
Checks if the interpolation has completed.
Definition bezierInterpolator.h:164
double myPeriod
The total time period for the interpolation (in seconds)
Definition bezierInterpolator.h:108
DtBezierInterpolator(makVrv::DtEaser easer, T start, T stop, double period)
Constructor.
Definition bezierInterpolator.h:118
T value() const
Gets the current interpolated value.
Definition bezierInterpolator.h:136
void reset(makVrv::DtEaser easer, T start, T stop, double period)
Resets the interpolation with a new easer and parameters.
Definition bezierInterpolator.h:190
void reset()
Resets the interpolation to the beginning.
Definition bezierInterpolator.h:171
void reset(T start, T stop, double period)
Resets the interpolation with new start, end, and period values.
Definition bezierInterpolator.h:179
DtVector stop() const
Definition bezierInterpolator.h:150
makVrv::DtEaser myEaser
The easing function to use.
Definition bezierInterpolator.h:96
T myCurrentValue
The current interpolated value.
Definition bezierInterpolator.h:105
Namespace containing predefined easing functions.
Definition bezierInterpolator.h:206
static makVrv::DtEaser EaseInQuart()
Creates an ease-in quartic function.
Definition bezierInterpolator.h:272
static makVrv::DtEaser EaseInOutBack()
Creates an ease-in-out back function (overshoots both ways)
Definition bezierInterpolator.h:370
static makVrv::DtEaser EaseInSine()
Creates an ease-in sine function.
Definition bezierInterpolator.h:209
static makVrv::DtEaser EaseInBack()
Creates an ease-in back function (overshoots backwards)
Definition bezierInterpolator.h:356
static makVrv::DtEaser EaseOutExpo()
Creates an ease-out exponential function.
Definition bezierInterpolator.h:321
static makVrv::DtEaser EaseInOutExpo()
Creates an ease-in-out exponential function.
Definition bezierInterpolator.h:328
static makVrv::DtEaser EaseOutCubic()
Creates an ease-out cubic function.
Definition bezierInterpolator.h:258
static makVrv::DtEaser EaseInOutCubic()
Creates an ease-in-out cubic function.
Definition bezierInterpolator.h:265
static makVrv::DtEaser EaseInOutQuart()
Creates an ease-in-out quartic function.
Definition bezierInterpolator.h:286
static makVrv::DtEaser EaseInOutQuad()
Creates an ease-in-out quadratic function.
Definition bezierInterpolator.h:244
static makVrv::DtEaser EaseOutBack()
Creates an ease-out back function (overshoots forwards)
Definition bezierInterpolator.h:363
static makVrv::DtEaser EaseOutQuint()
Creates an ease-out quintic function.
Definition bezierInterpolator.h:300
static makVrv::DtEaser EaseInCubic()
Creates an ease-in cubic function.
Definition bezierInterpolator.h:251
static makVrv::DtEaser EaseInCirc()
Creates an ease-in circular function.
Definition bezierInterpolator.h:335
static makVrv::DtEaser EaseInQuad()
Creates an ease-in quadratic function.
Definition bezierInterpolator.h:230
static makVrv::DtEaser EaseInOutSine()
Creates an ease-in-out sine function.
Definition bezierInterpolator.h:223
static makVrv::DtEaser EaseOutQuad()
Creates an ease-out quadratic function.
Definition bezierInterpolator.h:237
static makVrv::DtEaser EaseInOutQuint()
Creates an ease-in-out quintic function.
Definition bezierInterpolator.h:307
static makVrv::DtEaser EaseInExpo()
Creates an ease-in exponential function.
Definition bezierInterpolator.h:314
static makVrv::DtEaser EaseInOutCirc()
Creates an ease-in-out circular function.
Definition bezierInterpolator.h:349
static makVrv::DtEaser EaseInQuint()
Creates an ease-in quintic function.
Definition bezierInterpolator.h:293
static makVrv::DtEaser EaseOutSine()
Creates an ease-out sine function.
Definition bezierInterpolator.h:216
static makVrv::DtEaser EaseOutCirc()
Creates an ease-out circular function.
Definition bezierInterpolator.h:342
static makVrv::DtEaser EaseOutQuart()
Creates an ease-out quartic function.
Definition bezierInterpolator.h:279
Include export definitions for this library.
Definition glsVreMessageUtil.h:49