Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
3DAnimatable.h
Go to the documentation of this file.
1//! @file 3DAnimatable.h
2//! @brief C3DKeyframable class for handling keyframes
3//!
4//////////////////////////////////////////////////////////////////////
5
6#ifndef C3DANIMATABLE_H
7#define C3DANIMATABLE_H
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13#include "CustomData.h"
14#include "3DKeyframe.h"
15
16BEGIN_MOOTOOLS_NAMESPACE
17
18class C3DKeyframe;
19class CTimeRange;
20
21//! @class C3DAnimatable
22//! @brief C3DAnimatable is the base class for any object which inherits an animation.
23//! @details A C3DScene is not directly animatable but inherits animation as it contains C3DSceneNode which are animated. Any classe which derive from C3DKeyframable are animatable.
24class DLL_3DFUNCTION C3DAnimatable
25{
26public:
27 //! @enum FindKey
28 //!
30 {
31 KEYFRAME_PREV = 0x01, //!< Retrieves closest keyframe after the given time
32 KEYFRAME_NEXT = 0x02, //!< Retrieves closest keyframe before the given time
33 KEYFRAME_SAME = 0x04 //!< Retrieves keyframe at the given time
34 };
35
37 virtual ~C3DAnimatable();
38
39 int GetKeyTime(int time, unsigned int pos, longuint classid = KEYFRAME_NULLID);
40
41 virtual CTimeRange GetTimeRange(longuint classid = KEYFRAME_NULLID) const = 0;
42 virtual const C3DKeyframe *GetConstKey(int time, unsigned int pos, longuint classid = KEYFRAME_NULLID, int *findKeyTime = NULL) const = 0;
43};
44
45//! @class C3DKeyframable
46//! @brief This is the base class for any object that can be animated using C3DKeyframe.
47//! @details The C3DSceneNode derived from this class and handles KEYFRAME_MATRIX, KEYFRAME_SCALE, KEYFRAME_ROT, KEYFRAME_TRANS keyframes.
48//! It is possible to add / remove keyframe of any kind and to evaluate the interpolation of 2 keyframes
49class C3DKeyframe;
50class DLL_3DFUNCTION C3DKeyframable : public C3DAnimatable
51{
52 friend C3DKeyframe;
53
54public:
55 typedef enum TimeStamp
56 {
57 INVALID_TIME = -1,
58 } TimeStamp;
59
60private:
61 typedef struct _KeyframeInfo
62 {
63 int time;
64 C3DKeyframe *key;
65
66 _KeyframeInfo()
67 {
68 time = 0;
69 key = NULL;
70 };
71
72 _KeyframeInfo(int reftime, C3DKeyframe *refkey)
73 {
74 this->time = reftime;
75 this->key = refkey;
76 };
77 } KeyframeInfo;
78
79 typedef struct _KeyCache
80 {
81 int time;
82 C3DKeyframe *key; // key at given time
83
84 _KeyCache()
85 {
86 time = INVALID_TIME;
87 key = NULL;
88 }
89 } KeyCache;
90
92 mutable CXArray<KeyCache> cache;
93
94 void InitCache();
95 void InvalidateCache(longuint classID = KEYFRAME_NULLID) const;
96 C3DKeyframe * CreateCacheKey(int time, longuint classID, const C3DKeyframe *fromKey) const;
97 bool FindCache(int time, longuint classID, C3DKeyframe *& key) const;
98
99 void KeyframesChanged(longuint classid = KEYFRAME_NULLID) const;
100 const C3DKeyframe *GetKey(int time, unsigned int findKeyFlag, longuint classid = KEYFRAME_NULLID, int *findKeyTime = NULL) const;
101
102public:
104 {
105 KEYFRAME_NONE = 0x00,
106 KEYFRAME_REPLACE_KEY = 0x01, //!< The created keyframe replaces the previous one
107 KEYFRAME_DONT_EVALUATE = 0x02, //!< The created is not evaluate during creation. If not specified, the created keyframe is the interpolation of the adjacent keyframes
108 };
109
110 C3DKeyframable(void);
111 virtual ~C3DKeyframable(void);
112
113 int AddKey(int time, C3DKeyframe *newkey); //!< Return -1 if fails or keyframe number
114 int AddKey(int time, const C3DKeyframe& newkey); //!< Return keyframe number
115 int DeleteKey(int time, longuint classid = KEYFRAME_NULLID); //!< If time = INVALID_TIME, then all key of classid are deleted or all keys are deleted if classid = KEYFRAME_NULLID
116 void DeleteAllKeys();
117
118 C3DKeyframe *CreateKey(int time, longuint classid, unsigned int flags = KEYFRAME_NONE); //!< Create key of the given classid. flags is one or more #KeyframeFlags
119 C3DKeyframe *GetKeyByIndex(unsigned int index, int *time = NULL, longuint classid = KEYFRAME_NULLID); //!< This invalidate the cache, and can lead to slower computation
120 const C3DKeyframe *GetConstKeyByIndex(unsigned int index, int *time = NULL, longuint classid = KEYFRAME_NULLID) const;
121
122 int GetKeyNbr(longuint classid = KEYFRAME_NULLID) const;
123 bool Evaluate(int time, C3DKeyframe& findkey) const; //!< This method evaluate the key at the given time. Same but slower that the following method that return a pointer
124 const C3DKeyframe *Evaluate(int time, longuint classid) const; //!< This method evaluate the key at the given time. This is the fastest method. The key content cannot be changed
125 int CopyKeys(const C3DKeyframable *srckeys, longuint classid = KEYFRAME_NULLID, CTimeRange range = CTimeRange(0, CTimeRange::MAX_TIME)); //!< Copy key of the given classid in the given time range
126
127 bool operator==(const C3DKeyframable& refkeys) const;
128 bool operator=(const C3DKeyframable& key);
129
130 virtual void Serialize(CXArchive& ar);
131
132 // Animatable overiden
133 virtual void OnKeyframesChanged(longuint classID) const; // Notify that something changed in the keyframes. classID == KEYFRAME_NULLID, if all kind of keyframe changed
134 virtual CTimeRange GetTimeRange(longuint classid = KEYFRAME_NULLID) const;
135 virtual const C3DKeyframe *GetConstKey(int time, unsigned int findKeyFlag, longuint classid = KEYFRAME_NULLID, int *findKeyTime = NULL) const; //!< Retrieve a keyframe at / before or after the specified time depending on findKeyFlag
136
137#ifdef _DEBUG
138 virtual bool Dump(unsigned int flags) const;
139 virtual bool DumpKeyList(unsigned int flags) const;
140#endif
141};
142
143END_MOOTOOLS_NAMESPACE
144
145#endif // C3DANIMATABLE_H
The file contains different kind of keyframes definition.
CCustomData class is a handly class for storing any kind of data.
C3DAnimatable is the base class for any object which inherits an animation.
Definition 3DAnimatable.h:25
FindKey
Definition 3DAnimatable.h:30
This is the base class for any object that can be animated using C3DKeyframe.
Definition 3DAnimatable.h:51
int CopyKeys(const C3DKeyframable *srckeys, longuint classid=KEYFRAME_NULLID, CTimeRange range=CTimeRange(0, CTimeRange::MAX_TIME))
Copy key of the given classid in the given time range.
int DeleteKey(int time, longuint classid=KEYFRAME_NULLID)
If time = INVALID_TIME, then all key of classid are deleted or all keys are deleted if classid = KEYF...
bool Evaluate(int time, C3DKeyframe &findkey) const
This method evaluate the key at the given time. Same but slower that the following method that return...
C3DKeyframe * CreateKey(int time, longuint classid, unsigned int flags=KEYFRAME_NONE)
Create key of the given classid. flags is one or more KeyframeFlags.
int AddKey(int time, const C3DKeyframe &newkey)
Return keyframe number.
const C3DKeyframe * Evaluate(int time, longuint classid) const
This method evaluate the key at the given time. This is the fastest method. The key content cannot be...
C3DKeyframe * GetKeyByIndex(unsigned int index, int *time=NULL, longuint classid=KEYFRAME_NULLID)
This invalidate the cache, and can lead to slower computation.
KeyframeFlags
Definition 3DAnimatable.h:104
int AddKey(int time, C3DKeyframe *newkey)
Return -1 if fails or keyframe number.
virtual const C3DKeyframe * GetConstKey(int time, unsigned int findKeyFlag, longuint classid=KEYFRAME_NULLID, int *findKeyTime=NULL) const
Retrieve a keyframe at / before or after the specified time depending on findKeyFlag.
This is the base class for any keyframe that is part of C3DKeyframable class.
Definition 3DKeyframe.h:49
Definition 3DKeyframe.h:22
Definition XArchive.h:17
CXArray is an array of simple data information which does not requires to call a constructor / destru...
Definition XTemplate.h:34