VR-Engage  2.2
Loading...
Searching...
No Matches
linearInterpolator.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 linearInterpolator.h
9//! \brief Provides a template class for linear interpolation between values
10
11
12namespace makVre
13{
14//! \brief Linear interpolation template class
15//!
16//! This template class provides linear interpolation between a start and end value
17//! over a specified time period. Specializations are provided for float, double,
18//! and DtVector types.
19//!
20//! \tparam T The type of value to interpolate
21template <typename T>
23{
24public:
25 //! \brief Constructor
26 //!
27 //! Initializes the interpolator with start and end values and the time period
28 //!
29 //! \param start The starting value
30 //! \param stop The ending value
31 //! \param period The time period over which to interpolate (in seconds)
32 DtLinearInterpolator(T start, T stop, double period)
33 : myStart(start)
34 , myEnd(stop)
36 , myCurrentTime(0)
37 , myPeriod(period)
38 {
39 }
40
41 //! \brief Destructor
43
44 //! \brief Updates the interpolation based on elapsed time
45 //!
46 //! This function advances the interpolation by the given time step,
47 //! recalculating the current value based on the elapsed time.
48 //! Specialized implementations are provided for float, double, and DtVector.
49 //!
50 //! \param dt The time step in seconds
51 void tick(double dt);
52
53 //! \brief Gets the current interpolated value
54 //!
55 //! \return The current value of the interpolation
56 T value() const { return myCurrentValue; }
57
58 //! \brief Checks if the interpolation has completed
59 //!
60 //! \return true if the current time has reached or exceeded the period
61 bool isDone() const;
62
63 //! \brief Resets the interpolation to the beginning
64 //!
65 //! Sets the current value back to the start value and resets the time to zero
66 void reset();
67
68 //! \brief Resets the interpolation with new parameters
69 //!
70 //! \param start The new starting value
71 //! \param stop The new ending value
72 //! \param period The new time period (in seconds)
73 void reset(T start, T stop, double period);
74
75 //! \brief Gets the start value
76 //!
77 //! \return The start value of the interpolation
78 T start() const { return myStart; }
79
80 //! \brief Gets the end value
81 //!
82 //! \return The end value of the interpolation
83 T stop() const { return myEnd; }
84
85 //! \brief Gets the time remaining in the interpolation
86 //!
87 //! \return The remaining time in seconds
88 double timeRemaining() const { return myPeriod - myCurrentTime; }
89
90protected:
91 //! \brief The starting value
93
94 //! \brief The ending value
96
97 //! \brief The current interpolated value
99
100 //! \brief The total time period for the interpolation (in seconds)
101 double myPeriod;
102
103 //! \brief The current elapsed time (in seconds)
105};
106
107//! \brief Checks if the interpolation has completed
108//!
109//! \return true if the current time has reached or exceeded the period
110template <typename T>
112{
113 return myCurrentTime >= myPeriod;
114}
115
116//! \brief Resets the interpolation to the beginning
117//!
118//! Sets the current value back to the start value and resets the time to zero
119template <typename T>
125
126//! \brief Resets the interpolation with new parameters
127//!
128//! \param start The new starting value
129//! \param stop The new ending value
130//! \param period The new time period (in seconds)
131template <typename T>
133{
134 myStart = start;
135 myEnd = stop;
136 myPeriod = period;
138 myCurrentTime = 0.0;
139}
140
141} // namespace makVre
void reset(T start, T stop, double period)
Resets the interpolation with new parameters.
Definition linearInterpolator.h:132
T myStart
The starting value.
Definition linearInterpolator.h:92
double myPeriod
The total time period for the interpolation (in seconds)
Definition linearInterpolator.h:101
double timeRemaining() const
Gets the time remaining in the interpolation.
Definition linearInterpolator.h:88
T stop() const
Gets the end value.
Definition linearInterpolator.h:83
DtLinearInterpolator(T start, T stop, double period)
Constructor.
Definition linearInterpolator.h:32
void reset()
Resets the interpolation to the beginning.
Definition linearInterpolator.h:120
double myCurrentTime
The current elapsed time (in seconds)
Definition linearInterpolator.h:104
T start() const
Gets the start value.
Definition linearInterpolator.h:78
T myEnd
The ending value.
Definition linearInterpolator.h:95
void tick(double dt)
Updates the interpolation based on elapsed time.
T value() const
Gets the current interpolated value.
Definition linearInterpolator.h:56
T myCurrentValue
The current interpolated value.
Definition linearInterpolator.h:98
~DtLinearInterpolator()
Destructor.
Definition linearInterpolator.h:42
bool isDone() const
Checks if the interpolation has completed.
Definition linearInterpolator.h:111
Include export definitions for this library.
Definition glsVreMessageUtil.h:49