Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
3DKeyframe.h
Go to the documentation of this file.
1//! @file 3DKeyframe.h
2//! @brief The file contains different kind of keyframes definition
3
4//////////////////////////////////////////////////////////////////////
5
6#ifndef C3DKEYKEYFRAME_CLASS_H
7#define C3DKEYKEYFRAME_CLASS_H
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13#include "4x4Matrix.h"
14#include "3DVector.h"
15#include "CustomData.h"
16#include "3DKeyCurve.h"
17#include "RGBColor.h"
18
19BEGIN_MOOTOOLS_NAMESPACE
20
21class DLL_3DFUNCTION CTimeRange
22{
23public:
24 typedef enum
25 {
26 MAX_TIME = INT_MAX,
27 } SpecificTime;
28
29 int start, end;
30
31 CTimeRange();
32 CTimeRange(int start, int end);
33
34 BOOL IsInInterval(int time) const;
35 unsigned int GetLength() const;
36 int AdjustTime(int time) const;
37
38 CTimeRange& operator|=(const CTimeRange& range);
39 CTimeRange& operator&=(const CTimeRange& range);
40};
41
42class C3DKeyframable;
43
44//! @class C3DKeyframe
45//! @brief This is the base class for any keyframe that is part of C3DKeyframable class.
46//! @details There is different kind of keyframe defined by KeyframeType.
47//! C3DKeyframe::GetClassID can be used to cast a C3DKeyframe to the appropriate class.
48class DLL_3DFUNCTION C3DKeyframe
49{
50protected:
51 longuint classid; // The type of the keyframe and the content of the data
52
53 CCustomData data;
54 C3DKeyCurve *curve;
55 C3DKeyframable* keyframes;
56
57 C3DKeyframe& operator=(const C3DKeyframe& key) { MOOTOOLS_PRIVATE_ASSERT(0); return *this; }; // Use CopyFrom
58 void KeyFrameChanged(); // Called when the keyframe changed
59
60public:
61 //! @enum KeyframeType
62 typedef enum KeyframeType
63 {
64 KEYFRAME_TYPE_NULLID = 0, //!< Keyframe not defined. Can be also used to retrieve any kind of keyframe
65 KEYFRAME_TYPE_MATRIX = MAKE_CUSTOM_ID('M', 'A', 'T', 'R'), //!< C3DMatrixKey keyframe
66 KEYFRAME_TYPE_TRANS = MAKE_CUSTOM_ID('T', 'R', 'A', 'N'), //!< C3DTranslateKey keyframe
67 KEYFRAME_TYPE_SCALE = MAKE_CUSTOM_ID('S', 'C', 'A', 'L'), //!< C3DScaleKey keyframe
68 KEYFRAME_TYPE_ROT = MAKE_CUSTOM_ID('R', 'O', 'T', 'A'), //!< C3DRotateKey keyframe
69 KEYFRAME_TYPE_VECTOR = MAKE_CUSTOM_ID('V', 'E', 'C', 'T'), //!< C3DVectorKey keyframe
70 KEYFRAME_TYPE_FLOAT = MAKE_CUSTOM_ID('F', 'L', 'O', 'A'), //!< C3DFloatKey keyframe
71 KEYFRAME_TYPE_DOUBLE = MAKE_CUSTOM_ID('D', 'O', 'U', 'B'), //!< C3DDoubleKey keyframe
72 KEYFRAME_TYPE_INT = MAKE_CUSTOM_ID(' ', 'I', 'N', 'T'), //!< C3DIntKey keyframe
73 KEYFRAME_TYPE_UINT = MAKE_CUSTOM_ID('U', 'I', 'N', 'T'), //!< C3DUIntKey keyframe
74 KEYFRAME_TYPE_COLOR = MAKE_CUSTOM_ID('C', 'O', 'L', 'O'), //!< C3DColorKey keyframe
75 } KeyframeType;
76
78 virtual ~C3DKeyframe(void);
79
80 void SetKeyframes(C3DKeyframable* keyframes);
81 C3DKeyframable* GetKeyframes() const { return keyframes; }
82
83 CCustomData& GetCustomData() { return data; }
84
85 longuint GetClassID() const;
86 unsigned int GetTypeID() const;
87 unsigned int GetContentID() const;
88
89 static C3DKeyframe *CreateKey(longuint classid, unsigned int curveClassid = C3DKeyCurve::KEYCURVE_NULLID);
90 C3DKeyframe *Copy() const;
91
92 void SetKeyCurve(C3DKeyCurve *curve);
93 void SetKeyCurve(const C3DKeyCurve& curve);
94 const C3DKeyCurve *GetKeyCurve() const;
95 C3DKeyCurve *CreateCurve(unsigned int classid);
96
97 virtual void Serialize(CXArchive& ar);
98
99 virtual bool Evaluate(const C3DKeyframe& key1, const C3DKeyframe& key2, int time, const CTimeRange& range);
100 virtual bool operator==(const C3DKeyframe& key) const;
101 virtual C3DKeyframe& CopyFrom(const C3DKeyframe& key);
102
103public:
104#ifdef _DEBUG
105 virtual bool Dump(int time, unsigned int flags) const;
106#endif
107};
108
109#define KEYFRAMEID(classid, contentid) ((mootools::longuint)(((mootools::longuint)classid << 32) | (unsigned int)contentid))
110#define KEYFRAMETYPE(classid) ((unsigned int)((mootools::longuint)classid >> 32))
111#define KEYFRAMECONTENT(classid) ((unsigned int)(classid))
112
113#define KEYFRAME_NULLID KEYFRAMEID(mootools::C3DKeyframe::KEYFRAME_TYPE_NULLID, mootools::C3DKeyframe::KEYFRAME_TYPE_NULLID)
114#define KEYFRAME_MATRIX KEYFRAMEID(mootools::C3DKeyframe::KEYFRAME_TYPE_MATRIX, mootools::C3DKeyframe::KEYFRAME_TYPE_NULLID)
115#define KEYFRAME_SCALE KEYFRAMEID(mootools::C3DKeyframe::KEYFRAME_TYPE_SCALE, mootools::C3DKeyframe::KEYFRAME_TYPE_NULLID)
116#define KEYFRAME_ROT KEYFRAMEID(mootools::C3DKeyframe::KEYFRAME_TYPE_ROT, mootools::C3DKeyframe::KEYFRAME_TYPE_NULLID)
117#define KEYFRAME_TRANS KEYFRAMEID(mootools::C3DKeyframe::KEYFRAME_TYPE_TRANS, MAKE_CUSTOM_ID('T', 'R', 'A', 'N'))
118#define KEYFRAME_PIVOT KEYFRAMEID(mootools::C3DKeyframe::KEYFRAME_TYPE_VECTOR, MAKE_CUSTOM_ID('P', 'I', 'V', 'O'))
119
120//! @class C3DMatrixKey
121//! @brief This is the keyframe base class for transformation keyfrrame which allows to modify the node matrix transformation.
122//! @details C3DTranslateKey, C3DScaleKey, C3DRotateKey... derived from C3DMatrixKey. Use C3DMatrixKey::ToMatrix() to get the corresponding transformation C4x4Matrix.
123//!
124class DLL_3DFUNCTION C3DMatrixKey : public C3DKeyframe
125{
126protected:
127 C4x4Matrix matrix;
128
129public:
130 C3DMatrixKey(longuint classid);
131 C3DMatrixKey(const C4x4Matrix& matrix);
132
133 void SwapCoordinates(unsigned int swapMode, bool adjustMode);
134
135 virtual const C4x4Matrix& ToMatrix() const;
136 void SetMatrix(const C4x4Matrix& matrix);
137
138 virtual void Serialize(CXArchive& ar);
139
140 virtual bool Evaluate(const C3DKeyframe& key1, const C3DKeyframe& key2, int time, const CTimeRange& range);
141 virtual bool operator==(const C3DKeyframe& key) const;
142 virtual C3DKeyframe& CopyFrom(const C3DKeyframe& key);
143
144#ifdef _DEBUG
145 virtual bool Dump(int time, unsigned int flags) const;
146#endif
147};
148
149//! @class C3DMatrixKey
150//! @brief This class defines a rotation keyframe
151class DLL_3DFUNCTION C3DRotateKey : public C3DMatrixKey
152{
153protected:
154 double angle;
155 C3DVector rotation;
156
157public:
158 C3DRotateKey(longuint classid);
159 C3DRotateKey(real angle, const C3DVector& rotation);
160
161 void SwapCoordinates(unsigned int swapMode);
162
163 void SetRotation(double angle, const C3DVector& rotation);
164 C3DVector GetRotation(double& angle) const;
165 void SetQuaternion(const CQuaternion& quat);
166 CQuaternion GetQuaternion() const;
167
168 virtual void Serialize(CXArchive& ar);
169
170 virtual bool Evaluate(const C3DKeyframe& key1, const C3DKeyframe& key2, int time, const CTimeRange& range);
171 virtual C3DKeyframe& CopyFrom(const C3DKeyframe& key);
172
173 using C3DMatrixKey::ToMatrix;
174 using C3DMatrixKey::operator ==;
175
176#ifdef _DEBUG
177 bool Dump(int time, unsigned int flags) const;
178#endif
179};
180
181//! @class C3DMatrixKey
182//! @brief This class defines a translation keyframe
183class DLL_3DFUNCTION C3DVectorKey : public C3DMatrixKey
184{
185protected:
186 C3DVector vector;
187
188public:
189 C3DVectorKey(longuint classid);
190
191 void SwapCoordinates(unsigned int swapMode);
192
193 void SetVector(const C3DVector& vector);
194 real *GetVectorPtr();
195 C3DVector GetVector() const;
196
197 virtual void Serialize(CXArchive& ar);
198
199 virtual bool Evaluate(const C3DKeyframe& key1, const C3DKeyframe& key2, int time, const CTimeRange& range);
200 virtual C3DKeyframe& CopyFrom(const C3DKeyframe& key);
201 virtual void UpdateMatrix();
202
203#ifdef _DEBUG
204 bool Dump(int time, unsigned int flags) const;
205#endif
206};
207
208//! @class C3DMatrixKey
209//! @brief This class defines a scale keyframe
210class DLL_3DFUNCTION C3DScaleKey : public C3DVectorKey
211{
212public:
213 C3DScaleKey(longuint classid);
214
215 void UpdateMatrix();
216
217 using C3DVectorKey::operator ==; // Prevent C4263 & C4264 (unreal)
218 using C3DVectorKey::operator =;
219};
220
221class DLL_3DFUNCTION C3DTranslateKey : public C3DVectorKey
222{
223public:
224 C3DTranslateKey(longuint classid);
225
226 void UpdateMatrix();
227
228 using C3DVectorKey::operator ==; // Prevent C4263 & C4264 (unreal)
229 using C3DVectorKey::operator =;
230};
231
232/////////////////////////////////////////
233// Materials keys
234
235//! @class C3DTypeKey
236//! @brief This template class defines a keyframe of the specified TYPE
237template<class TYPE> class C3DTypeKey : public C3DKeyframe
238{
239public:
240 TYPE value;
241
242public:
243 C3DTypeKey(longuint classid);
244 C3DTypeKey(unsigned int contentid, TYPE value);
245
246 void SetValue(TYPE value);
247 TYPE GetValue() const;
248
249 unsigned int GetTypeID() const
250 {
251 XASSERT(0);
253 }
254
255 virtual void Serialize(CXArchive& ar);
256
257 virtual bool Evaluate(const C3DKeyframe& key1, const C3DKeyframe& key2, int time, const CTimeRange& range);
258 virtual bool operator==(const C3DKeyframe& key) const;
259 virtual C3DKeyframe& CopyFrom(const C3DKeyframe& key);
260
261#ifdef _DEBUG
262 virtual bool Dump(int time, unsigned int flags) const;
263#endif
264};
265
266////////////////////////////////////////////////////////////
267// C3DTypeKey
268////////////////////////////////////////////////////////////
269
270template <class TYPE> C3DTypeKey<TYPE>::C3DTypeKey(longuint classid)
271{
272 XASSERT(KEYFRAMETYPE(classid) == GetTypeID());
273 this->classid = classid;
274 value = 0;
275}
276
277template <class TYPE> C3DTypeKey<TYPE>::C3DTypeKey(unsigned int contentid, TYPE refvalue)
278{
279 classid = KEYFRAMEID(GetTypeID(), contentid);
280 this->value = refvalue;
281}
282
283template <class TYPE> void C3DTypeKey<TYPE>::SetValue(TYPE refvalue)
284{
285 this->value = refvalue;
286}
287
288template <class TYPE> TYPE C3DTypeKey<TYPE>::GetValue() const
289{
290 return value;
291}
292
293template <class TYPE> bool C3DTypeKey<TYPE>::operator==(const C3DKeyframe& key) const
294{
295 if (!C3DKeyframe::operator==(key))
296 return false;
297
298 return value == ((C3DTypeKey<TYPE>&)key).value;
299}
300
301template <class TYPE> void C3DTypeKey<TYPE>::Serialize(CXArchive& ar)
302{
303 C3DKeyframe::Serialize(ar);
304
305 if (ar.IsStoring())
306 ar << value;
307 else
308 ar >> value;
309}
310
311template <class TYPE> C3DKeyframe& C3DTypeKey<TYPE>::CopyFrom(const C3DKeyframe& key)
312{
313 C3DKeyframe::CopyFrom(key);
314 if (classid != key.GetClassID())
315 return (*this);
316
317 this->value = ((C3DTypeKey<TYPE>&)key).value;
318
319 return (*this);
320}
321
322template <class TYPE> bool C3DTypeKey<TYPE>::Evaluate(const C3DKeyframe& refkey1, const C3DKeyframe& refkey2, int time, const CTimeRange& range)
323{
326
327 double coef = (time-range.start)/(double)range.GetLength();
328 value = (TYPE)(key1.value*(1.0-coef)+key2.value*coef);
329
330 return true;
331}
332
333#ifdef _DEBUG
334template <class TYPE> bool C3DTypeKey<TYPE>::Dump(int time, unsigned int flags) const
335{
336 if (!C3DKeyframe::Dump(time, flags))
337 return false;
338
340 XTRACE(_T("Type Key %d %d:\n"), GetTypeID(), GetContentID());
341 trace << value;
342
343 return true;
344}
345#endif
346
347//! @class C3DFloatKey
348//! @extends C3DTypeKey
349//! @brief This keyframe stores a float value information which can be get / set using SetValue() / GetValue() methods
350//! @class C3DDoubleKey
351//! @extends C3DTypeKey
352//! @brief This keyframe stores a double value information which can be get / set using SetValue() / GetValue() methods
353//! @class C3DIntKey
354//! @extends C3DTypeKey
355//! @brief This keyframe stores a int value information which can be get / set using SetValue() / GetValue() methods
356//! @class C3DUIntKey
357//! @extends C3DTypeKey
358//! @brief This keyframe stores a unsigned int value information which can be get / set using SetValue() / GetValue() methods
359//! @class C3DColorKey
360//! @extends C3DTypeKey
361//! @brief This keyframe stores a CRGBColor color information which can be get / set using SetValue() / GetValue() methods
367
368/////////////////////////////////////////////////////////////////////
369// Specialization
370//////////////////////////////////////////////////////////////////////
371
372#ifdef _DEBUG
373template<> inline unsigned int C3DFloatKey::GetTypeID() const
374{
375 return KEYFRAME_TYPE_FLOAT;
376}
377
378template<> inline unsigned int C3DDoubleKey::GetTypeID() const
379{
381}
382
383template<> inline unsigned int C3DIntKey::GetTypeID() const
384{
385 return KEYFRAME_TYPE_INT;
386}
387
388template<> inline unsigned int C3DUIntKey::GetTypeID() const
389{
390 return KEYFRAME_TYPE_UINT;
391}
392
393template<> inline unsigned int C3DColorKey::GetTypeID() const
394{
395 return KEYFRAME_TYPE_COLOR;
396}
397
398//template unsigned int C3DFloatKey::GetTypeID() const;
399//template unsigned int C3DDoubleKey::GetTypeID() const;
400//template unsigned int C3DIntKey::GetTypeID() const;
401//template unsigned int C3DUIntKey::GetTypeID() const;
402//template unsigned int C3DColorKey::GetTypeID() const;
403#endif
404
405END_MOOTOOLS_NAMESPACE
406
407#endif // C3DKEYKEYFRAME_CLASS_H
The file defines C3DKeyCurve, C3DTCBCurve which handles interpolation curve between two keyframes.
CCustomData class is a handly class for storing any kind of data.
CRGBColor is a class that handles RGBA colors.
This keyframe stores a CRGBColor color information which can be get / set using SetValue() / GetValue...
This keyframe stores a double value information which can be get / set using SetValue() / GetValue() ...
This keyframe stores a float value information which can be get / set using SetValue() / GetValue() m...
This keyframe stores a int value information which can be get / set using SetValue() / GetValue() met...
C3DKeyCurve is the base class that determines the transition curve between a given keyframe and the n...
Definition 3DKeyCurve.h:22
This is the base class for any object that can be animated using C3DKeyframe.
Definition 3DAnimatable.h:51
This is the base class for any keyframe that is part of C3DKeyframable class.
Definition 3DKeyframe.h:49
KeyframeType
Definition 3DKeyframe.h:63
@ KEYFRAME_TYPE_NULLID
Keyframe not defined. Can be also used to retrieve any kind of keyframe.
Definition 3DKeyframe.h:64
@ KEYFRAME_TYPE_DOUBLE
C3DDoubleKey keyframe.
Definition 3DKeyframe.h:71
@ KEYFRAME_TYPE_INT
C3DIntKey keyframe.
Definition 3DKeyframe.h:72
@ KEYFRAME_TYPE_UINT
C3DUIntKey keyframe.
Definition 3DKeyframe.h:73
@ KEYFRAME_TYPE_FLOAT
C3DFloatKey keyframe.
Definition 3DKeyframe.h:70
@ KEYFRAME_TYPE_COLOR
C3DColorKey keyframe.
Definition 3DKeyframe.h:74
This is the keyframe base class for transformation keyfrrame which allows to modify the node matrix t...
Definition 3DKeyframe.h:125
Definition 3DKeyframe.h:152
Definition 3DKeyframe.h:211
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Definition 3DKeyframe.h:222
This template class defines a keyframe of the specified TYPE.
Definition 3DKeyframe.h:238
This keyframe stores a unsigned int value information which can be get / set using SetValue() / GetVa...
Definition 3DKeyframe.h:184
CCustomData is a handly class for storing any kind of data.
Definition CustomData.h:106
The class defines a quaternion transformation.
Definition Quaternion.h:20
Definition 3DKeyframe.h:22
Definition XArchive.h:17