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-2006 Torus Knot Software Ltd |
---|
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 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OgreStableHeaders.h" |
---|
30 | |
---|
31 | #include "OgreKeyFrame.h" |
---|
32 | #include "OgreAnimationTrack.h" |
---|
33 | #include "OgreHardwareBufferManager.h" |
---|
34 | |
---|
35 | namespace Ogre |
---|
36 | { |
---|
37 | //--------------------------------------------------------------------- |
---|
38 | KeyFrame::KeyFrame(const AnimationTrack* parent, Real time) |
---|
39 | : mTime(time), mParentTrack(parent) |
---|
40 | { |
---|
41 | } |
---|
42 | //--------------------------------------------------------------------- |
---|
43 | KeyFrame* KeyFrame::_clone(AnimationTrack* newParent) const |
---|
44 | { |
---|
45 | return new KeyFrame(newParent, mTime); |
---|
46 | } |
---|
47 | //--------------------------------------------------------------------- |
---|
48 | NumericKeyFrame::NumericKeyFrame(const AnimationTrack* parent, Real time) |
---|
49 | :KeyFrame(parent, time) |
---|
50 | { |
---|
51 | } |
---|
52 | //--------------------------------------------------------------------- |
---|
53 | const AnyNumeric& NumericKeyFrame::getValue(void) const |
---|
54 | { |
---|
55 | return mValue; |
---|
56 | } |
---|
57 | //--------------------------------------------------------------------- |
---|
58 | void NumericKeyFrame::setValue(const AnyNumeric& val) |
---|
59 | { |
---|
60 | mValue = val; |
---|
61 | } |
---|
62 | //--------------------------------------------------------------------- |
---|
63 | KeyFrame* NumericKeyFrame::_clone(AnimationTrack* newParent) const |
---|
64 | { |
---|
65 | NumericKeyFrame* newKf = new NumericKeyFrame(newParent, mTime); |
---|
66 | newKf->mValue = mValue; |
---|
67 | return newKf; |
---|
68 | } |
---|
69 | //--------------------------------------------------------------------- |
---|
70 | TransformKeyFrame::TransformKeyFrame(const AnimationTrack* parent, Real time) |
---|
71 | :KeyFrame(parent, time), mTranslate(Vector3::ZERO), |
---|
72 | mScale(Vector3::UNIT_SCALE), mRotate(Quaternion::IDENTITY) |
---|
73 | { |
---|
74 | } |
---|
75 | //--------------------------------------------------------------------- |
---|
76 | void TransformKeyFrame::setTranslate(const Vector3& trans) |
---|
77 | { |
---|
78 | mTranslate = trans; |
---|
79 | if (mParentTrack) |
---|
80 | mParentTrack->_keyFrameDataChanged(); |
---|
81 | } |
---|
82 | //--------------------------------------------------------------------- |
---|
83 | const Vector3& TransformKeyFrame::getTranslate(void) const |
---|
84 | { |
---|
85 | return mTranslate; |
---|
86 | } |
---|
87 | //--------------------------------------------------------------------- |
---|
88 | void TransformKeyFrame::setScale(const Vector3& scale) |
---|
89 | { |
---|
90 | mScale = scale; |
---|
91 | if (mParentTrack) |
---|
92 | mParentTrack->_keyFrameDataChanged(); |
---|
93 | } |
---|
94 | //--------------------------------------------------------------------- |
---|
95 | const Vector3& TransformKeyFrame::getScale(void) const |
---|
96 | { |
---|
97 | return mScale; |
---|
98 | } |
---|
99 | //--------------------------------------------------------------------- |
---|
100 | void TransformKeyFrame::setRotation(const Quaternion& rot) |
---|
101 | { |
---|
102 | mRotate = rot; |
---|
103 | if (mParentTrack) |
---|
104 | mParentTrack->_keyFrameDataChanged(); |
---|
105 | } |
---|
106 | //--------------------------------------------------------------------- |
---|
107 | const Quaternion& TransformKeyFrame::getRotation(void) const |
---|
108 | { |
---|
109 | return mRotate; |
---|
110 | } |
---|
111 | //--------------------------------------------------------------------- |
---|
112 | KeyFrame* TransformKeyFrame::_clone(AnimationTrack* newParent) const |
---|
113 | { |
---|
114 | TransformKeyFrame* newKf = new TransformKeyFrame(newParent, mTime); |
---|
115 | newKf->mTranslate = mTranslate; |
---|
116 | newKf->mScale = mScale; |
---|
117 | newKf->mRotate = mRotate; |
---|
118 | return newKf; |
---|
119 | } |
---|
120 | //--------------------------------------------------------------------- |
---|
121 | VertexMorphKeyFrame::VertexMorphKeyFrame(const AnimationTrack* parent, Real time) |
---|
122 | : KeyFrame(parent, time) |
---|
123 | { |
---|
124 | } |
---|
125 | //--------------------------------------------------------------------- |
---|
126 | void VertexMorphKeyFrame::setVertexBuffer(const HardwareVertexBufferSharedPtr& buf) |
---|
127 | { |
---|
128 | mBuffer = buf; |
---|
129 | } |
---|
130 | //--------------------------------------------------------------------- |
---|
131 | const HardwareVertexBufferSharedPtr& |
---|
132 | VertexMorphKeyFrame::getVertexBuffer(void) const |
---|
133 | { |
---|
134 | return mBuffer; |
---|
135 | } |
---|
136 | //--------------------------------------------------------------------- |
---|
137 | KeyFrame* VertexMorphKeyFrame::_clone(AnimationTrack* newParent) const |
---|
138 | { |
---|
139 | VertexMorphKeyFrame* newKf = new VertexMorphKeyFrame(newParent, mTime); |
---|
140 | newKf->mBuffer = mBuffer; |
---|
141 | return newKf; |
---|
142 | } |
---|
143 | //--------------------------------------------------------------------- |
---|
144 | VertexPoseKeyFrame::VertexPoseKeyFrame(const AnimationTrack* parent, Real time) |
---|
145 | :KeyFrame(parent, time) |
---|
146 | { |
---|
147 | } |
---|
148 | //--------------------------------------------------------------------- |
---|
149 | void VertexPoseKeyFrame::addPoseReference(ushort poseIndex, Real influence) |
---|
150 | { |
---|
151 | mPoseRefs.push_back(PoseRef(poseIndex, influence)); |
---|
152 | } |
---|
153 | //--------------------------------------------------------------------- |
---|
154 | void VertexPoseKeyFrame::updatePoseReference(ushort poseIndex, Real influence) |
---|
155 | { |
---|
156 | for (PoseRefList::iterator i = mPoseRefs.begin(); i != mPoseRefs.end(); ++i) |
---|
157 | { |
---|
158 | if (i->poseIndex == poseIndex) |
---|
159 | { |
---|
160 | i->influence = influence; |
---|
161 | return; |
---|
162 | } |
---|
163 | } |
---|
164 | // if we got here, we didn't find it |
---|
165 | addPoseReference(poseIndex, influence); |
---|
166 | |
---|
167 | } |
---|
168 | //--------------------------------------------------------------------- |
---|
169 | void VertexPoseKeyFrame::removePoseReference(ushort poseIndex) |
---|
170 | { |
---|
171 | for (PoseRefList::iterator i = mPoseRefs.begin(); i != mPoseRefs.end(); ++i) |
---|
172 | { |
---|
173 | if (i->poseIndex == poseIndex) |
---|
174 | { |
---|
175 | mPoseRefs.erase(i); |
---|
176 | return; |
---|
177 | } |
---|
178 | } |
---|
179 | } |
---|
180 | //--------------------------------------------------------------------- |
---|
181 | void VertexPoseKeyFrame::removeAllPoseReferences(void) |
---|
182 | { |
---|
183 | mPoseRefs.clear(); |
---|
184 | } |
---|
185 | //--------------------------------------------------------------------- |
---|
186 | const VertexPoseKeyFrame::PoseRefList& |
---|
187 | VertexPoseKeyFrame::getPoseReferences(void) const |
---|
188 | { |
---|
189 | return mPoseRefs; |
---|
190 | } |
---|
191 | //--------------------------------------------------------------------- |
---|
192 | VertexPoseKeyFrame::PoseRefIterator |
---|
193 | VertexPoseKeyFrame::getPoseReferenceIterator(void) |
---|
194 | { |
---|
195 | return PoseRefIterator(mPoseRefs.begin(), mPoseRefs.end()); |
---|
196 | } |
---|
197 | //--------------------------------------------------------------------- |
---|
198 | VertexPoseKeyFrame::ConstPoseRefIterator |
---|
199 | VertexPoseKeyFrame::getPoseReferenceIterator(void) const |
---|
200 | { |
---|
201 | return ConstPoseRefIterator(mPoseRefs.begin(), mPoseRefs.end()); |
---|
202 | } |
---|
203 | //--------------------------------------------------------------------- |
---|
204 | KeyFrame* VertexPoseKeyFrame::_clone(AnimationTrack* newParent) const |
---|
205 | { |
---|
206 | VertexPoseKeyFrame* newKf = new VertexPoseKeyFrame(newParent, mTime); |
---|
207 | // By-value copy ok |
---|
208 | newKf->mPoseRefs = mPoseRefs; |
---|
209 | return newKf; |
---|
210 | } |
---|
211 | //--------------------------------------------------------------------- |
---|
212 | |
---|
213 | |
---|
214 | } |
---|
215 | |
---|