Coverage Report

Created: 2025-08-25 06:44

/src/ogre/OgreMain/include/OgreKeyFrame.h
Line
Count
Source (jump to first uncovered line)
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-2014 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 "OgreVector.h"
34
#include "OgreQuaternion.h"
35
#include "OgreAny.h"
36
#include "OgreHardwareVertexBuffer.h"
37
#include "OgreHeaderPrefix.h"
38
39
namespace Ogre 
40
{
41
42
    /** \addtogroup Core
43
    *  @{
44
    */
45
    /** \addtogroup Animation
46
    *  @{
47
    */
48
    /** A key frame in an animation sequence defined by an AnimationTrack.
49
50
        This class can be used as a basis for all kinds of key frames. 
51
        The unifying principle is that multiple KeyFrames define an 
52
        animation sequence, with the exact state of the animation being an 
53
        interpolation between these key frames. 
54
    */
55
    class _OgreExport KeyFrame : public AnimationAlloc
56
    {
57
    public:
58
59
        /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */
60
        KeyFrame(const AnimationTrack* parent, Real time);
61
62
0
        virtual ~KeyFrame() {}
63
64
        /** Gets the time of this keyframe in the animation sequence. */
65
0
        Real getTime(void) const { return mTime; }
66
67
        /** Clone a keyframe (internal use only) */
68
        virtual KeyFrame* _clone(AnimationTrack* newParent) const OGRE_NODISCARD;
69
70
71
    protected:
72
        Real mTime;
73
        const AnimationTrack* mParentTrack;
74
    };
75
76
77
    /** Specialised KeyFrame which stores any numeric value.
78
    */
79
    class _OgreExport NumericKeyFrame : public KeyFrame
80
    {
81
    public:
82
        /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */
83
        NumericKeyFrame(const AnimationTrack* parent, Real time);
84
0
        ~NumericKeyFrame() {}
85
86
        /** Get the value at this keyframe. */
87
0
        const Any& getValue(void) const { return mValue; }
88
        /** Set the value at this keyframe.
89
90
            All keyframe values must have a consistent type. 
91
        */
92
0
        void setValue(const Any& val) { mValue = val; }
93
94
        /** Clone a keyframe (internal use only) */
95
        KeyFrame* _clone(AnimationTrack* newParent) const override;
96
    private:
97
        Any mValue;
98
    };
99
100
101
    /** Specialised KeyFrame which stores a full transform. */
102
    class _OgreExport TransformKeyFrame : public KeyFrame
103
    {
104
    public:
105
        /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */
106
        TransformKeyFrame(const AnimationTrack* parent, Real time);
107
0
        ~TransformKeyFrame() {}
108
        /** Sets the translation associated with this keyframe. 
109
110
        The translation factor affects how much the keyframe translates (moves) it's animable
111
        object at it's time index.
112
        @param trans The vector to translate by
113
        */
114
        virtual void setTranslate(const Vector3& trans);
115
116
        /** Gets the translation applied by this keyframe. */
117
        const Vector3& getTranslate(void) const;
118
119
        /** Sets the scaling factor applied by this keyframe to the animable
120
        object at it's time index.
121
        @param scale The vector to scale by (beware of supplying zero values for any component of this
122
        vector, it will scale the object to zero dimensions)
123
        */
124
        virtual void setScale(const Vector3& scale);
125
126
        /** Gets the scaling factor applied by this keyframe. */
127
        virtual const Vector3& getScale(void) const;
128
129
        /** Sets the rotation applied by this keyframe.
130
        @param rot The rotation applied; use Quaternion methods to convert from angle/axis or Matrix3 if
131
        you don't like using Quaternions directly.
132
        */
133
        virtual void setRotation(const Quaternion& rot);
134
135
        /** Gets the rotation applied by this keyframe. */
136
        virtual const Quaternion& getRotation(void) const;
137
138
        /** Clone a keyframe (internal use only) */
139
        KeyFrame* _clone(AnimationTrack* newParent) const override;
140
    private:
141
        Vector3 mTranslate;
142
        Vector3 mScale;
143
        Quaternion mRotate;
144
145
146
    };
147
148
149
150
    /** Specialised KeyFrame which stores absolute vertex positions for a complete
151
        buffer, designed to be interpolated with other keys in the same track. 
152
    */
153
    class _OgreExport VertexMorphKeyFrame : public KeyFrame
154
    {
155
    public:
156
        /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */
157
        VertexMorphKeyFrame(const AnimationTrack* parent, Real time);
158
0
        ~VertexMorphKeyFrame() {}
159
        /** Sets the vertex buffer containing the source positions for this keyframe. 
160
161
            We assume that positions are the first 3 float elements in this buffer,
162
            although we don't necessarily assume they're the only ones in there.
163
        @param buf Vertex buffer link; will not be modified so can be shared
164
            read-only data
165
        */
166
        void setVertexBuffer(const HardwareVertexBufferSharedPtr& buf);
167
168
        /** Gets the vertex buffer containing positions for this keyframe. */
169
        const HardwareVertexBufferSharedPtr& getVertexBuffer(void) const;
170
171
        KeyFrame* _clone(AnimationTrack* newParent) const override;
172
173
    private:
174
        HardwareVertexBufferSharedPtr mBuffer;
175
176
    };
177
178
    /** Specialised KeyFrame which references a Mesh::Pose at a certain influence
179
        level, which stores offsets for a subset of the vertices 
180
        in a buffer to provide a blendable pose.
181
    */
182
    class _OgreExport VertexPoseKeyFrame : public KeyFrame
183
    {
184
    public:
185
        /** Default constructor, you should not call this but use AnimationTrack::createKeyFrame instead. */
186
        VertexPoseKeyFrame(const AnimationTrack* parent, Real time);
187
0
        ~VertexPoseKeyFrame() {}
188
189
        /** Reference to a pose at a given influence level 
190
191
            Each keyframe can refer to many poses each at a given influence level.
192
        **/
193
        struct PoseRef
194
        {
195
            /** The linked pose index.
196
197
                The Mesh contains all poses for all vertex data in one list, both 
198
                for the shared vertex data and the dedicated vertex data on submeshes.
199
                The 'target' on the parent track must match the 'target' on the 
200
                linked pose.
201
            */
202
            ushort poseIndex;
203
            /** Influence level of the linked pose. 
204
                1.0 for full influence (full offset), 0.0 for no influence.
205
            */
206
            float influence;
207
208
0
            PoseRef(ushort p, float i) : poseIndex(p), influence(i) {}
209
        };
210
        typedef std::vector<PoseRef> PoseRefList;
211
212
        /** Add a new pose reference. 
213
        @see PoseRef
214
        */
215
        void addPoseReference(ushort poseIndex, float influence);
216
        /** Update the influence of a pose reference. 
217
        @see PoseRef
218
        */
219
        void updatePoseReference(ushort poseIndex, float influence);
220
        /** Remove reference to a given pose. 
221
        @param poseIndex The pose index (not the index of the reference)
222
        */
223
        void removePoseReference(ushort poseIndex);
224
        /** Remove all pose references. */
225
        void removeAllPoseReferences(void);
226
227
228
        /** Get a const reference to the list of pose references. */
229
        const PoseRefList& getPoseReferences(void) const;
230
231
        typedef VectorIterator<PoseRefList> PoseRefIterator;
232
        typedef ConstVectorIterator<PoseRefList> ConstPoseRefIterator;
233
234
        /** Get an iterator over the pose references.
235
        @deprecated use getPoseReferences() */
236
        OGRE_DEPRECATED PoseRefIterator getPoseReferenceIterator(void);
237
238
        /** Get a const iterator over the pose references.
239
        @deprecated use getPoseReferences() */
240
        OGRE_DEPRECATED ConstPoseRefIterator getPoseReferenceIterator(void) const;
241
242
        /** Clone a keyframe (internal use only) */
243
        KeyFrame* _clone(AnimationTrack* newParent) const override;
244
        
245
        void _applyBaseKeyFrame(const VertexPoseKeyFrame* base);
246
        
247
    private:
248
        PoseRefList mPoseRefs;
249
250
    };
251
    /** @} */
252
    /** @} */
253
254
}
255
256
#include "OgreHeaderSuffix.h"
257
258
#endif
259