10 INTERPOLATION_HERMITE,
13 INTERPOLATION_LINEAR_CROSSFRAME,
38 virtual int AddKey(
int time,
bool* isKeyExist = NULL);
44 virtual void SetTime(
int nIndex,
int nTime);
45 virtual int GetTime(
int nIndex);
47 virtual void SetValue(
int nIndex,
const Quaternion& val);
48 virtual bool GetValue(
int nIndex,
Quaternion& val);
49 virtual bool GetValueByTime(
int nTime,
Quaternion& val);
51 virtual void SetValue(
int nIndex,
const Vector2& val);
52 virtual bool GetValue(
int nIndex,
Vector2& val);
53 virtual bool GetValueByTime(
int nTime,
Vector2& val);
55 virtual void SetValue(
int nIndex,
const Vector3& val);
56 virtual bool GetValue(
int nIndex,
Vector3& val);
57 virtual bool GetValueByTime(
int nTime,
Vector3& val);
59 virtual void SetValue(
int nIndex,
const double& val);
60 virtual bool GetValue(
int nIndex,
double& val);
61 virtual bool GetValueByTime(
int nTime,
double& val);
63 virtual void SetValue(
int nIndex,
const float& val);
64 virtual bool GetValue(
int nIndex,
float& val);
65 virtual bool GetValueByTime(
int nTime,
float& val);
67 virtual void SetValue(
int nIndex,
const int& val);
68 virtual bool GetValue(
int nIndex,
int& val);
69 virtual bool GetValueByTime(
int nTime,
int& val);
71 virtual void SetValue(
int nIndex,
const std::string& val);
72 virtual bool GetValue(
int nIndex, std::string& val);
73 virtual bool GetValueByTime(
int nTime, std::string& val);
79 inline T interpolate(
const float r,
const T &v1,
const T &v2)
81 return (v1*(1.0f - r) + v2*r);
85 inline T interpolateHermite(
const float r,
const T &v1,
const T &v2,
const T &in,
const T &out)
91 float h1 = 2.0f*r*r*r - 3.0f*r*r + 1.0f;
92 float h2 = -2.0f*r*r*r + 3.0f*r*r;
93 float h3 = r*r*r - 2.0f*r*r + r;
94 float h4 = r*r*r - r*r;
97 return static_cast<T
>(v1*h1 + v2*h2 + in*h3 + out*h4);
104 return Quaternion::Slerp(r, v1, v2,
true);
110 inline static const float conv(
const DWORD t)
119 inline static const T& conv(
const T& t)
126 template <
class T,
class Conv = Identity<T> >
139 int nNumKeys = (int) m_data.size();
145 int nEnd = nNumKeys-2;
153 int nMid = (nStart + nEnd) / 2;
154 int startP = (m_times[nMid]);
155 int endP = (m_times[nMid + 1]);
157 if (startP <= time && time < endP)
162 else if (time < startP)
166 else if (time >= endP)
172 int t1 = m_times[pos];
173 int t2 = m_times[pos + 1];
180 val = m_data[pos + 1];
188 float r = (time - t1) / (
float)(t2 - t1);
190 if (m_interpolationType == INTERPOLATION_LINEAR)
191 val = interpolate<T>(r, m_data[pos], m_data[pos + 1]);
192 else if (m_interpolationType == INTERPOLATION_LINEAR_CROSSFRAME)
197 val = interpolate<T>(r, m_data[pos], m_data[pos + 1]);
203 val = interpolate<T>(r, m_data[pos], m_data[pos + 1]);
208 else if (nNumKeys > 0)
218 virtual bool GetValue(
int nIndex, T& val)
222 val = m_data[nIndex];
225 else if (m_data.size() > 0)
227 val = m_data[m_data.size()-1];
233 virtual void SetValue(
int nIndex,
const T& val)
237 m_data[nIndex] = val;
242 SetValue(nIndex, val);
248 return (
int)m_data.size();
255 m_data.resize(nKeyCount);
256 m_times.resize(nKeyCount);
262 if (nIndex < (
int)m_times.size())
263 m_times[nIndex] = nTime;
266 virtual int GetTime(
int nIndex)
268 return (nIndex < (
int)m_times.size()) ? m_times[nIndex] : 0;
273 int dataCount = (int)m_data.size();
278 else if (dataCount > 0)
283 int nEnd = dataCount - 1;
291 int nMid = (nStart + nEnd) / 2;
292 int startP = (m_times[nMid]);
293 int endP = (m_times[nMid + 1]);
295 if (startP <= time && time < endP)
300 else if (time < startP)
304 else if (time >= endP)
310 for (
int i = pos - 1; i >= 0; --i)
312 if (m_times[i] >= time)
322 virtual int AddKey(
int time,
bool* isKeyExist = NULL)
329 int next_time = GetTime(index);
330 if (next_time == time)
338 if (next_time < time)
342 m_times.insert(m_times.begin()+index, time);
343 m_data.insert(m_data.begin()+index, T());
359 int m_interpolationType;
360 std::vector<int> m_times;
361 std::vector<T> m_data;
virtual int AddKey(int time, bool *isKeyExist=NULL)
add a given key with default value at specified time if there is already a key at the index...
Definition: IAnimated.cpp:26
virtual void SetNumKeys(int nKeyCount)
get set the total number of animated keys.
Definition: IAnimated.h:251
virtual int GetNextKeyIndex(int time)
return the index of the first key whose time is larger than or equal to time.
Definition: IAnimated.h:271
different physics engine has different winding order.
Definition: EventBinding.h:32
Implementation of a Quaternion, i.e.
Definition: ParaQuaternion.h:10
virtual void SetTime(int nIndex, int nTime)
only applied to Animated attribute
Definition: IAnimated.cpp:31
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
virtual int AddKey(int time, bool *isKeyExist=NULL)
add a given key with default value at specified time if there is already a key at the index...
Definition: IAnimated.h:322
Definition: IAnimated.h:117
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
Definition: IAnimated.h:108
base class for AnimatedVariable.
Definition: IAnimated.h:18
key, value pairs
Definition: IAnimated.h:127
virtual bool GetValueByTime(int time, T &val)
this function will return the interpolated animation vector frame number internally use binary search...
Definition: IAnimated.h:137
virtual int GetNumKeys()
get total number of animated keys.
Definition: IAnimated.cpp:11
virtual void SetTime(int nIndex, int nTime)
only applied to Animated attribute
Definition: IAnimated.h:260
virtual void SetNumKeys(int nKeyCount)
get set the total number of animated keys.
Definition: IAnimated.cpp:16
virtual int GetNumKeys()
get total number of animated keys.
Definition: IAnimated.h:246
virtual int GetNextKeyIndex(int nTime)
return the index of the first key whose time is larger than or equal to time.
Definition: IAnimated.cpp:21