Coverage Report

Created: 2026-08-29 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/src/OgreKeyFrame.cpp
Line
Count
Source
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
#include "OgreStableHeaders.h"
29
30
#include "OgreKeyFrame.h"
31
#include "OgreAnimationTrack.h"
32
33
namespace Ogre
34
{
35
    //---------------------------------------------------------------------
36
    KeyFrame::KeyFrame(const AnimationTrack* parent, Real time) 
37
0
        : mTime(time), mParentTrack(parent)
38
0
    {
39
0
    }
40
    //---------------------------------------------------------------------
41
    KeyFrame* KeyFrame::_clone(AnimationTrack* newParent) const
42
0
    {
43
0
        return OGRE_NEW KeyFrame(newParent, mTime);
44
0
    }
45
    //---------------------------------------------------------------------
46
    NumericKeyFrame::NumericKeyFrame(const AnimationTrack* parent, Real time)
47
0
        :KeyFrame(parent, time)
48
0
    {
49
0
    }
50
    //---------------------------------------------------------------------
51
    KeyFrame* NumericKeyFrame::_clone(AnimationTrack* newParent) const
52
0
    {
53
0
        NumericKeyFrame* newKf = OGRE_NEW NumericKeyFrame(newParent, mTime);
54
0
        newKf->mValue = mValue;
55
0
        return newKf;
56
0
    }
57
    //---------------------------------------------------------------------
58
    TransformKeyFrame::TransformKeyFrame(const AnimationTrack* parent, Real time)
59
0
        :KeyFrame(parent, time), mTranslate(Vector3::ZERO), 
60
0
        mScale(Vector3::UNIT_SCALE), mRotate(Quaternion::IDENTITY) 
61
0
    {
62
0
    }
63
    //---------------------------------------------------------------------
64
    void TransformKeyFrame::setTranslate(const Vector3& trans)
65
0
    {
66
0
        mTranslate = trans;
67
0
        if (mParentTrack)
68
0
            mParentTrack->_keyFrameDataChanged();
69
0
    }
70
    //---------------------------------------------------------------------
71
    const Vector3& TransformKeyFrame::getTranslate(void) const
72
0
    {
73
0
        return mTranslate;
74
0
    }
75
    //---------------------------------------------------------------------
76
    void TransformKeyFrame::setScale(const Vector3& scale)
77
0
    {
78
0
        mScale = scale;
79
0
        if (mParentTrack)
80
0
            mParentTrack->_keyFrameDataChanged();
81
0
    }
82
    //---------------------------------------------------------------------
83
    const Vector3& TransformKeyFrame::getScale(void) const
84
0
    {
85
0
        return mScale;
86
0
    }
87
    //---------------------------------------------------------------------
88
    void TransformKeyFrame::setRotation(const Quaternion& rot)
89
0
    {
90
0
        mRotate = rot;
91
0
        if (mParentTrack)
92
0
            mParentTrack->_keyFrameDataChanged();
93
0
    }
94
    //---------------------------------------------------------------------
95
    const Quaternion& TransformKeyFrame::getRotation(void) const
96
0
    {
97
0
        return mRotate;
98
0
    }
99
    //---------------------------------------------------------------------
100
    KeyFrame* TransformKeyFrame::_clone(AnimationTrack* newParent) const
101
0
    {
102
0
        TransformKeyFrame* newKf = OGRE_NEW TransformKeyFrame(newParent, mTime);
103
0
        newKf->mTranslate = mTranslate;
104
0
        newKf->mScale = mScale;
105
0
        newKf->mRotate = mRotate;
106
0
        return newKf;
107
0
    }
108
    //---------------------------------------------------------------------
109
    VertexMorphKeyFrame::VertexMorphKeyFrame(const AnimationTrack* parent, Real time)
110
0
        : KeyFrame(parent, time)
111
0
    {
112
0
    }
113
    //---------------------------------------------------------------------
114
    void VertexMorphKeyFrame::setVertexBuffer(const HardwareVertexBufferSharedPtr& buf)
115
0
    {
116
0
        mBuffer = buf;
117
0
    }
118
    //---------------------------------------------------------------------
119
    const HardwareVertexBufferSharedPtr& 
120
    VertexMorphKeyFrame::getVertexBuffer(void) const
121
0
    {
122
0
        return mBuffer;
123
0
    }
124
    //---------------------------------------------------------------------
125
    KeyFrame* VertexMorphKeyFrame::_clone(AnimationTrack* newParent) const
126
0
    {
127
0
        VertexMorphKeyFrame* newKf = OGRE_NEW VertexMorphKeyFrame(newParent, mTime);
128
0
        newKf->mBuffer = mBuffer;
129
0
        return newKf;
130
0
    }   
131
    //---------------------------------------------------------------------
132
    VertexPoseKeyFrame::VertexPoseKeyFrame(const AnimationTrack* parent, Real time)
133
0
        :KeyFrame(parent, time)
134
0
    {
135
0
    }
136
    //---------------------------------------------------------------------
137
    void VertexPoseKeyFrame::addPoseReference(ushort poseIndex, float influence)
138
0
    {
139
0
        mPoseRefs.push_back(PoseRef(poseIndex, influence));
140
0
    }
141
    //---------------------------------------------------------------------
142
    void VertexPoseKeyFrame::updatePoseReference(ushort poseIndex, float influence)
143
0
    {
144
0
        for (auto & poseRef : mPoseRefs)
145
0
        {
146
0
            if (poseRef.poseIndex == poseIndex)
147
0
            {
148
0
                poseRef.influence = influence;
149
0
                return;
150
0
            }
151
0
        }
152
        // if we got here, we didn't find it
153
0
        addPoseReference(poseIndex, influence);
154
155
0
    }
156
    //---------------------------------------------------------------------
157
    void VertexPoseKeyFrame::removePoseReference(ushort poseIndex)
158
0
    {
159
0
        for (PoseRefList::iterator i = mPoseRefs.begin(); i != mPoseRefs.end(); ++i)
160
0
        {
161
0
            if (i->poseIndex == poseIndex)
162
0
            {
163
0
                mPoseRefs.erase(i);
164
0
                return;
165
0
            }
166
0
        }
167
0
    }
168
    //---------------------------------------------------------------------
169
    void VertexPoseKeyFrame::removeAllPoseReferences(void)
170
0
    {
171
0
        mPoseRefs.clear();
172
0
    }
173
    //---------------------------------------------------------------------
174
    const VertexPoseKeyFrame::PoseRefList& 
175
    VertexPoseKeyFrame::getPoseReferences(void) const
176
0
    {
177
0
        return mPoseRefs;
178
0
    }
179
    //---------------------------------------------------------------------
180
    VertexPoseKeyFrame::PoseRefIterator 
181
    VertexPoseKeyFrame::getPoseReferenceIterator(void)
182
0
    {
183
0
        return PoseRefIterator(mPoseRefs.begin(), mPoseRefs.end());
184
0
    }
185
    //---------------------------------------------------------------------
186
    VertexPoseKeyFrame::ConstPoseRefIterator 
187
    VertexPoseKeyFrame::getPoseReferenceIterator(void) const
188
0
    {
189
0
        return ConstPoseRefIterator(mPoseRefs.begin(), mPoseRefs.end());
190
0
    }
191
    //---------------------------------------------------------------------
192
    KeyFrame* VertexPoseKeyFrame::_clone(AnimationTrack* newParent) const
193
0
    {
194
0
        VertexPoseKeyFrame* newKf = OGRE_NEW VertexPoseKeyFrame(newParent, mTime);
195
        // By-value copy ok
196
0
        newKf->mPoseRefs = mPoseRefs;
197
0
        return newKf;
198
0
    }   
199
    //---------------------------------------------------------------------
200
    void VertexPoseKeyFrame::_applyBaseKeyFrame(const VertexPoseKeyFrame* base)
201
0
    {
202
        // We subtract the matching pose influences in the base keyframe from the
203
        // influences in this keyframe
204
0
        for (auto & myPoseRef : mPoseRefs)
205
0
        {
206
0
            PoseRefList::const_iterator basePoseIt = base->getPoseReferences().begin();
207
0
            Real baseInfluence = 0.0f;
208
0
            for (;basePoseIt != base->getPoseReferences().end(); ++basePoseIt)
209
0
            {
210
0
                const PoseRef& basePoseRef = *basePoseIt;
211
0
                if (basePoseRef.poseIndex == myPoseRef.poseIndex)
212
0
                {
213
0
                    baseInfluence = basePoseRef.influence;
214
0
                    break;
215
0
                }
216
0
            }
217
            
218
0
            myPoseRef.influence -= baseInfluence;
219
            
220
0
        }
221
        
222
0
    }
223
224
225
}
226