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-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef __KeyFrame_H__
|
---|
27 | #define __KeyFrame_H__
|
---|
28 |
|
---|
29 | #include "OgrePrerequisites.h"
|
---|
30 | #include "OgreVector3.h"
|
---|
31 | #include "OgreQuaternion.h"
|
---|
32 | #include "OgreAny.h"
|
---|
33 | #include "OgreHardwareVertexBuffer.h"
|
---|
34 | #include "OgreIteratorWrappers.h"
|
---|
35 |
|
---|
36 | namespace Ogre
|
---|
37 | {
|
---|
38 |
|
---|
39 | /** A key frame in an animation sequence defined by an AnimationTrack.
|
---|
40 | @remarks
|
---|
41 | This class can be used as a basis for all kinds of key frames.
|
---|
42 | The unifying principle is that multiple KeyFrames define an
|
---|
43 | animation sequence, with the exact state of the animation being an
|
---|
44 | interpolation between these key frames.
|
---|
45 | */
|
---|
46 | class _OgreExport KeyFrame
|
---|
47 | {
|
---|
48 | public:
|
---|
49 |
|
---|
50 | /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */
|
---|
51 | KeyFrame(const AnimationTrack* parent, Real time);
|
---|
52 |
|
---|
53 | virtual ~KeyFrame() {}
|
---|
54 |
|
---|
55 | /** Gets the time of this keyframe in the animation sequence. */
|
---|
56 | Real getTime(void) const { return mTime; }
|
---|
57 |
|
---|
58 | /** Clone a keyframe (internal use only) */
|
---|
59 | virtual KeyFrame* _clone(AnimationTrack* newParent) const;
|
---|
60 |
|
---|
61 |
|
---|
62 | protected:
|
---|
63 | Real mTime;
|
---|
64 | const AnimationTrack* mParentTrack;
|
---|
65 | };
|
---|
66 |
|
---|
67 |
|
---|
68 | /** Specialised KeyFrame which stores any numeric value.
|
---|
69 | */
|
---|
70 | class _OgreExport NumericKeyFrame : public KeyFrame
|
---|
71 | {
|
---|
72 | public:
|
---|
73 | /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */
|
---|
74 | NumericKeyFrame(const AnimationTrack* parent, Real time);
|
---|
75 | ~NumericKeyFrame() {}
|
---|
76 |
|
---|
77 | /** Get the value at this keyframe. */
|
---|
78 | virtual const AnyNumeric& getValue(void) const;
|
---|
79 | /** Set the value at this keyframe.
|
---|
80 | @remarks
|
---|
81 | All keyframe values must have a consistent type.
|
---|
82 | */
|
---|
83 | virtual void setValue(const AnyNumeric& val);
|
---|
84 |
|
---|
85 | /** Clone a keyframe (internal use only) */
|
---|
86 | KeyFrame* _clone(AnimationTrack* newParent) const;
|
---|
87 | protected:
|
---|
88 | AnyNumeric mValue;
|
---|
89 | };
|
---|
90 |
|
---|
91 |
|
---|
92 | /** Specialised KeyFrame which stores a full transform. */
|
---|
93 | class _OgreExport TransformKeyFrame : public KeyFrame
|
---|
94 | {
|
---|
95 | public:
|
---|
96 | /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */
|
---|
97 | TransformKeyFrame(const AnimationTrack* parent, Real time);
|
---|
98 | ~TransformKeyFrame() {}
|
---|
99 | /** Sets the translation associated with this keyframe.
|
---|
100 | @remarks
|
---|
101 | The translation factor affects how much the keyframe translates (moves) it's animable
|
---|
102 | object at it's time index.
|
---|
103 | @param trans The vector to translate by
|
---|
104 | */
|
---|
105 | virtual void setTranslate(const Vector3& trans);
|
---|
106 |
|
---|
107 | /** Gets the translation applied by this keyframe. */
|
---|
108 | const Vector3& getTranslate(void) const;
|
---|
109 |
|
---|
110 | /** Sets the scaling factor applied by this keyframe to the animable
|
---|
111 | object at it's time index.
|
---|
112 | @param scale The vector to scale by (beware of supplying zero values for any component of this
|
---|
113 | vector, it will scale the object to zero dimensions)
|
---|
114 | */
|
---|
115 | virtual void setScale(const Vector3& scale);
|
---|
116 |
|
---|
117 | /** Gets the scaling factor applied by this keyframe. */
|
---|
118 | virtual const Vector3& getScale(void) const;
|
---|
119 |
|
---|
120 | /** Sets the rotation applied by this keyframe.
|
---|
121 | @param rot The rotation applied; use Quaternion methods to convert from angle/axis or Matrix3 if
|
---|
122 | you don't like using Quaternions directly.
|
---|
123 | */
|
---|
124 | virtual void setRotation(const Quaternion& rot);
|
---|
125 |
|
---|
126 | /** Gets the rotation applied by this keyframe. */
|
---|
127 | virtual const Quaternion& getRotation(void) const;
|
---|
128 |
|
---|
129 | /** Clone a keyframe (internal use only) */
|
---|
130 | KeyFrame* _clone(AnimationTrack* newParent) const;
|
---|
131 | protected:
|
---|
132 | Vector3 mTranslate;
|
---|
133 | Vector3 mScale;
|
---|
134 | Quaternion mRotate;
|
---|
135 |
|
---|
136 |
|
---|
137 | };
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 | /** Specialised KeyFrame which stores absolute vertex positions for a complete
|
---|
142 | buffer, designed to be interpolated with other keys in the same track.
|
---|
143 | */
|
---|
144 | class _OgreExport VertexMorphKeyFrame : public KeyFrame
|
---|
145 | {
|
---|
146 | public:
|
---|
147 | /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */
|
---|
148 | VertexMorphKeyFrame(const AnimationTrack* parent, Real time);
|
---|
149 | ~VertexMorphKeyFrame() {}
|
---|
150 | /** Sets the vertex buffer containing the source positions for this keyframe.
|
---|
151 | @remarks
|
---|
152 | We assume that positions are the first 3 float elements in this buffer,
|
---|
153 | although we don't necessarily assume they're the only ones in there.
|
---|
154 | @param buf Vertex buffer link; will not be modified so can be shared
|
---|
155 | read-only data
|
---|
156 | */
|
---|
157 | void setVertexBuffer(const HardwareVertexBufferSharedPtr& buf);
|
---|
158 |
|
---|
159 | /** Gets the vertex buffer containing positions for this keyframe. */
|
---|
160 | const HardwareVertexBufferSharedPtr& getVertexBuffer(void) const;
|
---|
161 |
|
---|
162 | /** Clone a keyframe (internal use only) */
|
---|
163 | KeyFrame* _clone(AnimationTrack* newParent) const;
|
---|
164 |
|
---|
165 | protected:
|
---|
166 | HardwareVertexBufferSharedPtr mBuffer;
|
---|
167 |
|
---|
168 | };
|
---|
169 |
|
---|
170 | /** Specialised KeyFrame which references a Mesh::Pose at a certain influence
|
---|
171 | level, which stores offsets for a subset of the vertices
|
---|
172 | in a buffer to provide a blendable pose.
|
---|
173 | */
|
---|
174 | class _OgreExport VertexPoseKeyFrame : public KeyFrame
|
---|
175 | {
|
---|
176 | public:
|
---|
177 | /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */
|
---|
178 | VertexPoseKeyFrame(const AnimationTrack* parent, Real time);
|
---|
179 | ~VertexPoseKeyFrame() {}
|
---|
180 |
|
---|
181 | /** Reference to a pose at a given influence level
|
---|
182 | @remarks
|
---|
183 | Each keyframe can refer to many poses each at a given influence level.
|
---|
184 | **/
|
---|
185 | struct PoseRef
|
---|
186 | {
|
---|
187 | /** The linked pose index.
|
---|
188 | @remarks
|
---|
189 | The Mesh contains all poses for all vertex data in one list, both
|
---|
190 | for the shared vertex data and the dedicated vertex data on submeshes.
|
---|
191 | The 'target' on the parent track must match the 'target' on the
|
---|
192 | linked pose.
|
---|
193 | */
|
---|
194 | ushort poseIndex;
|
---|
195 | /** Influence level of the linked pose.
|
---|
196 | 1.0 for full influence (full offset), 0.0 for no influence.
|
---|
197 | */
|
---|
198 | Real influence;
|
---|
199 |
|
---|
200 | PoseRef(ushort p, Real i) : poseIndex(p), influence(i) {}
|
---|
201 | };
|
---|
202 | typedef std::vector<PoseRef> PoseRefList;
|
---|
203 |
|
---|
204 | /** Add a new pose reference.
|
---|
205 | @see PoseRef
|
---|
206 | */
|
---|
207 | void addPoseReference(ushort poseIndex, Real influence);
|
---|
208 | /** Update the influence of a pose reference.
|
---|
209 | @see PoseRef
|
---|
210 | */
|
---|
211 | void updatePoseReference(ushort poseIndex, Real influence);
|
---|
212 | /** Remove reference to a given pose.
|
---|
213 | @param poseIndex The pose index (not the index of the reference)
|
---|
214 | */
|
---|
215 | void removePoseReference(ushort poseIndex);
|
---|
216 | /** Remove all pose references. */
|
---|
217 | void removeAllPoseReferences(void);
|
---|
218 |
|
---|
219 |
|
---|
220 | /** Get a const reference to the list of pose references. */
|
---|
221 | const PoseRefList& getPoseReferences(void) const;
|
---|
222 |
|
---|
223 | typedef VectorIterator<PoseRefList> PoseRefIterator;
|
---|
224 | typedef ConstVectorIterator<PoseRefList> ConstPoseRefIterator;
|
---|
225 |
|
---|
226 | /** Get an iterator over the pose references. */
|
---|
227 | PoseRefIterator getPoseReferenceIterator(void);
|
---|
228 |
|
---|
229 | /** Get a const iterator over the pose references. */
|
---|
230 | ConstPoseRefIterator getPoseReferenceIterator(void) const;
|
---|
231 |
|
---|
232 | /** Clone a keyframe (internal use only) */
|
---|
233 | KeyFrame* _clone(AnimationTrack* newParent) const;
|
---|
234 |
|
---|
235 | protected:
|
---|
236 | PoseRefList mPoseRefs;
|
---|
237 |
|
---|
238 | };
|
---|
239 |
|
---|
240 | }
|
---|
241 |
|
---|
242 |
|
---|
243 | #endif
|
---|
244 |
|
---|