1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2013 Torus Knot Software Ltd |
---|
8 | |
---|
9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
10 | of this software and associated documentation files (the "Software"), to deal |
---|
11 | in the Software without restriction, including without limitation the rights |
---|
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
13 | copies of the Software, and to permit persons to whom the Software is |
---|
14 | furnished to do so, subject to the following conditions: |
---|
15 | |
---|
16 | The above copyright notice and this permission notice shall be included in |
---|
17 | all copies or substantial portions of the Software. |
---|
18 | |
---|
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
25 | THE SOFTWARE. |
---|
26 | ----------------------------------------------------------------------------- |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef __KeyFrame_H__ |
---|
30 | #define __KeyFrame_H__ |
---|
31 | |
---|
32 | #include "OgrePrerequisites.h" |
---|
33 | #include "OgreVector3.h" |
---|
34 | #include "OgreQuaternion.h" |
---|
35 | #include "OgreAny.h" |
---|
36 | #include "OgreHardwareVertexBuffer.h" |
---|
37 | #include "OgreIteratorWrappers.h" |
---|
38 | #include "OgreHeaderPrefix.h" |
---|
39 | |
---|
40 | namespace Ogre |
---|
41 | { |
---|
42 | |
---|
43 | /** \addtogroup Core |
---|
44 | * @{ |
---|
45 | */ |
---|
46 | /** \addtogroup Animation |
---|
47 | * @{ |
---|
48 | */ |
---|
49 | /** A key frame in an animation sequence defined by an AnimationTrack. |
---|
50 | @remarks |
---|
51 | This class can be used as a basis for all kinds of key frames. |
---|
52 | The unifying principle is that multiple KeyFrames define an |
---|
53 | animation sequence, with the exact state of the animation being an |
---|
54 | interpolation between these key frames. |
---|
55 | */ |
---|
56 | class _OgreExport KeyFrame : public AnimationAlloc |
---|
57 | { |
---|
58 | public: |
---|
59 | |
---|
60 | /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */ |
---|
61 | KeyFrame(const AnimationTrack* parent, Real time); |
---|
62 | |
---|
63 | virtual ~KeyFrame() {} |
---|
64 | |
---|
65 | /** Gets the time of this keyframe in the animation sequence. */ |
---|
66 | Real getTime(void) const { return mTime; } |
---|
67 | |
---|
68 | /** Clone a keyframe (internal use only) */ |
---|
69 | virtual KeyFrame* _clone(AnimationTrack* newParent) const; |
---|
70 | |
---|
71 | |
---|
72 | protected: |
---|
73 | Real mTime; |
---|
74 | const AnimationTrack* mParentTrack; |
---|
75 | }; |
---|
76 | |
---|
77 | |
---|
78 | /** Specialised KeyFrame which stores any numeric value. |
---|
79 | */ |
---|
80 | class _OgreExport NumericKeyFrame : public KeyFrame |
---|
81 | { |
---|
82 | public: |
---|
83 | /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */ |
---|
84 | NumericKeyFrame(const AnimationTrack* parent, Real time); |
---|
85 | ~NumericKeyFrame() {} |
---|
86 | |
---|
87 | /** Get the value at this keyframe. */ |
---|
88 | virtual const AnyNumeric& getValue(void) const; |
---|
89 | /** Set the value at this keyframe. |
---|
90 | @remarks |
---|
91 | All keyframe values must have a consistent type. |
---|
92 | */ |
---|
93 | virtual void setValue(const AnyNumeric& val); |
---|
94 | |
---|
95 | /** Clone a keyframe (internal use only) */ |
---|
96 | KeyFrame* _clone(AnimationTrack* newParent) const; |
---|
97 | protected: |
---|
98 | AnyNumeric mValue; |
---|
99 | }; |
---|
100 | |
---|
101 | |
---|
102 | /** Specialised KeyFrame which stores a full transform. */ |
---|
103 | class _OgreExport TransformKeyFrame : public KeyFrame |
---|
104 | { |
---|
105 | public: |
---|
106 | /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */ |
---|
107 | TransformKeyFrame(const AnimationTrack* parent, Real time); |
---|
108 | ~TransformKeyFrame() {} |
---|
109 | /** Sets the translation associated with this keyframe. |
---|
110 | @remarks |
---|
111 | The translation factor affects how much the keyframe translates (moves) it's animable |
---|
112 | object at it's time index. |
---|
113 | @param trans The vector to translate by |
---|
114 | */ |
---|
115 | virtual void setTranslate(const Vector3& trans); |
---|
116 | |
---|
117 | /** Gets the translation applied by this keyframe. */ |
---|
118 | const Vector3& getTranslate(void) const; |
---|
119 | |
---|
120 | /** Sets the scaling factor applied by this keyframe to the animable |
---|
121 | object at it's time index. |
---|
122 | @param scale The vector to scale by (beware of supplying zero values for any component of this |
---|
123 | vector, it will scale the object to zero dimensions) |
---|
124 | */ |
---|
125 | virtual void setScale(const Vector3& scale); |
---|
126 | |
---|
127 | /** Gets the scaling factor applied by this keyframe. */ |
---|
128 | virtual const Vector3& getScale(void) const; |
---|
129 | |
---|
130 | /** Sets the rotation applied by this keyframe. |
---|
131 | @param rot The rotation applied; use Quaternion methods to convert from angle/axis or Matrix3 if |
---|
132 | you don't like using Quaternions directly. |
---|
133 | */ |
---|
134 | virtual void setRotation(const Quaternion& rot); |
---|
135 | |
---|
136 | /** Gets the rotation applied by this keyframe. */ |
---|
137 | virtual const Quaternion& getRotation(void) const; |
---|
138 | |
---|
139 | /** Clone a keyframe (internal use only) */ |
---|
140 | KeyFrame* _clone(AnimationTrack* newParent) const; |
---|
141 | protected: |
---|
142 | Vector3 mTranslate; |
---|
143 | Vector3 mScale; |
---|
144 | Quaternion mRotate; |
---|
145 | |
---|
146 | |
---|
147 | }; |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | /** Specialised KeyFrame which stores absolute vertex positions for a complete |
---|
152 | buffer, designed to be interpolated with other keys in the same track. |
---|
153 | */ |
---|
154 | class _OgreExport VertexMorphKeyFrame : public KeyFrame |
---|
155 | { |
---|
156 | public: |
---|
157 | /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */ |
---|
158 | VertexMorphKeyFrame(const AnimationTrack* parent, Real time); |
---|
159 | ~VertexMorphKeyFrame() {} |
---|
160 | /** Sets the vertex buffer containing the source positions for this keyframe. |
---|
161 | @remarks |
---|
162 | We assume that positions are the first 3 float elements in this buffer, |
---|
163 | although we don't necessarily assume they're the only ones in there. |
---|
164 | @param buf Vertex buffer link; will not be modified so can be shared |
---|
165 | read-only data |
---|
166 | */ |
---|
167 | void setVertexBuffer(const HardwareVertexBufferSharedPtr& buf); |
---|
168 | |
---|
169 | /** Gets the vertex buffer containing positions for this keyframe. */ |
---|
170 | const HardwareVertexBufferSharedPtr& getVertexBuffer(void) const; |
---|
171 | |
---|
172 | /** Clone a keyframe (internal use only) */ |
---|
173 | KeyFrame* _clone(AnimationTrack* newParent) const; |
---|
174 | |
---|
175 | protected: |
---|
176 | HardwareVertexBufferSharedPtr mBuffer; |
---|
177 | |
---|
178 | }; |
---|
179 | |
---|
180 | /** Specialised KeyFrame which references a Mesh::Pose at a certain influence |
---|
181 | level, which stores offsets for a subset of the vertices |
---|
182 | in a buffer to provide a blendable pose. |
---|
183 | */ |
---|
184 | class _OgreExport VertexPoseKeyFrame : public KeyFrame |
---|
185 | { |
---|
186 | public: |
---|
187 | /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */ |
---|
188 | VertexPoseKeyFrame(const AnimationTrack* parent, Real time); |
---|
189 | ~VertexPoseKeyFrame() {} |
---|
190 | |
---|
191 | /** Reference to a pose at a given influence level |
---|
192 | @remarks |
---|
193 | Each keyframe can refer to many poses each at a given influence level. |
---|
194 | **/ |
---|
195 | struct PoseRef |
---|
196 | { |
---|
197 | /** The linked pose index. |
---|
198 | @remarks |
---|
199 | The Mesh contains all poses for all vertex data in one list, both |
---|
200 | for the shared vertex data and the dedicated vertex data on submeshes. |
---|
201 | The 'target' on the parent track must match the 'target' on the |
---|
202 | linked pose. |
---|
203 | */ |
---|
204 | ushort poseIndex; |
---|
205 | /** Influence level of the linked pose. |
---|
206 | 1.0 for full influence (full offset), 0.0 for no influence. |
---|
207 | */ |
---|
208 | Real influence; |
---|
209 | |
---|
210 | PoseRef(ushort p, Real i) : poseIndex(p), influence(i) {} |
---|
211 | }; |
---|
212 | typedef vector<PoseRef>::type PoseRefList; |
---|
213 | |
---|
214 | /** Add a new pose reference. |
---|
215 | @see PoseRef |
---|
216 | */ |
---|
217 | void addPoseReference(ushort poseIndex, Real influence); |
---|
218 | /** Update the influence of a pose reference. |
---|
219 | @see PoseRef |
---|
220 | */ |
---|
221 | void updatePoseReference(ushort poseIndex, Real influence); |
---|
222 | /** Remove reference to a given pose. |
---|
223 | @param poseIndex The pose index (not the index of the reference) |
---|
224 | */ |
---|
225 | void removePoseReference(ushort poseIndex); |
---|
226 | /** Remove all pose references. */ |
---|
227 | void removeAllPoseReferences(void); |
---|
228 | |
---|
229 | |
---|
230 | /** Get a const reference to the list of pose references. */ |
---|
231 | const PoseRefList& getPoseReferences(void) const; |
---|
232 | |
---|
233 | typedef VectorIterator<PoseRefList> PoseRefIterator; |
---|
234 | typedef ConstVectorIterator<PoseRefList> ConstPoseRefIterator; |
---|
235 | |
---|
236 | /** Get an iterator over the pose references. */ |
---|
237 | PoseRefIterator getPoseReferenceIterator(void); |
---|
238 | |
---|
239 | /** Get a const iterator over the pose references. */ |
---|
240 | ConstPoseRefIterator getPoseReferenceIterator(void) const; |
---|
241 | |
---|
242 | /** Clone a keyframe (internal use only) */ |
---|
243 | KeyFrame* _clone(AnimationTrack* newParent) const; |
---|
244 | |
---|
245 | void _applyBaseKeyFrame(const VertexPoseKeyFrame* base); |
---|
246 | |
---|
247 | protected: |
---|
248 | PoseRefList mPoseRefs; |
---|
249 | |
---|
250 | }; |
---|
251 | /** @} */ |
---|
252 | /** @} */ |
---|
253 | |
---|
254 | } |
---|
255 | |
---|
256 | #include "OgreHeaderSuffix.h" |
---|
257 | |
---|
258 | #endif |
---|
259 | |
---|