Project

General

Profile

SO3Engine
SO3AnimTrack.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
34
35namespace SO3
36{
37
38SAnimTrack::SAnimTrack(const std::string& animationTrackName, SAnim* animation, const AnimTrackType& animationTrackType) : SData(animationTrackName)
39{
40 type = animationTrackType;
41 parentAnimation = animation;
42
43 // To be initialised by a SAnimTrack derived class.
45}
46
47SAnimTrack::SAnimTrack() : SData(""), parentAnimation(0)
48{
49 //Forbiden (private)
50}
51
53{
54 parentAnimation = 0;
56}
57
59{
60 return ogreAnimationTrack;
61}
62
67
69{
70 return parentAnimation;
71}
72
74{
75 unsigned short size = 0;
77 size = ogreAnimationTrack->getNumKeyFrames();
78 return size;
79}
80
82{
84 ogreAnimationTrack->optimise();
85}
86
87void SAnimTrack::Update(const float& pos)
88{
89}
90
91void SAnimTrack::CreateKey(const float& timepos, const Ogre::Vector3& pos, const Ogre::Quaternion& quat, const Ogre::Vector3& scale)
92{
93}
94
95void SAnimTrack::SetKeyTransform(const unsigned int& keyIndex, const Ogre::Vector3& pos, const Ogre::Quaternion& quat, const Ogre::Vector3& scale)
96{
97}
98
99void SAnimTrack::GetKeyTransform(const unsigned int& keyIndex, Ogre::Vector3& pos, Ogre::Quaternion& quat, Ogre::Vector3& scale)
100{
101 pos = Ogre::Vector3::ZERO;
102 quat = Ogre::Quaternion::IDENTITY;
103 scale = Ogre::Vector3::ZERO;
104}
105
106float SAnimTrack::GetKeyPositionTime(const unsigned int& keyIndex)
107{
108 float postime = 0.0f;
109 Ogre::KeyFrame* key = 0;
110 if(((int)GetNumKeyFrames() - 1) >= (int)keyIndex)
111 key = GetOgreAnimationTrackPointer()->getKeyFrame(keyIndex);
112
113 if (key)
114 postime = key->getTime();
115
116 return postime;
117}
118
119void SAnimTrack::RemoveKey(const unsigned int& keyIndex)
120{
121 if(((int)GetNumKeyFrames() - 1) >= (int)keyIndex)
122 GetOgreAnimationTrackPointer()->removeKeyFrame(keyIndex);
123}
124
128
129Ogre::AnimationTrack* SAnimTrack::_Clone(Ogre::Animation* tanim, const unsigned short& tid)
130{
131 Ogre::AnimationTrack* newAnimTrack = 0;
132 try
133 {
134 switch(type)
135 {
137 {
138 Ogre::NodeAnimationTrack* nodeTrack = static_cast<Ogre::NodeAnimationTrack*>(ogreAnimationTrack);
139 newAnimTrack = tanim->createNodeTrack(tid, nodeTrack->getAssociatedNode());
140 for (int i = 0; i < nodeTrack->getNumKeyFrames(); i++)
141 {
142 Ogre::TransformKeyFrame* key = nodeTrack->getNodeKeyFrame(i);
143 Ogre::TransformKeyFrame* nkey = static_cast<Ogre::NodeAnimationTrack*>(newAnimTrack)->createNodeKeyFrame(key->getTime());
144 nkey->setRotation(key->getRotation());
145 nkey->setScale(key->getScale());
146 nkey->setTranslate(key->getTranslate());
147 }
148 break;
149 }
150/*
151 case SAnimTrack::SO3_POSE_TRACK:
152 {
153 Ogre::VertexAnimationTrack* vertexTrack = static_cast<Ogre::VertexAnimationTrack*>(ogreAnimationTrack);
154 newAnimTrack = tanim->createVertexTrack(tid, vertexTrack->getAssociatedVertexData(), vertexTrack->getAnimationType());
155 for (int i = 0; i < vertexTrack->getNumKeyFrames(); i++)
156 {
157 Ogre::VertexPoseKeyFrame* key = vertexTrack->getVertexPoseKeyFrame(i);
158 Ogre::VertexPoseKeyFrame* nkey = static_cast<Ogre::VertexAnimationTrack*>(newAnimTrack)->createVertexPoseKeyFrame(key->getTime());
159 Ogre::VertexPoseKeyFrame::PoseRefIterator piterator = key->getPoseReferenceIterator();
160 while (piterator.hasMoreElements())
161 {
162 Ogre::VertexPoseKeyFrame::PoseRef pref = piterator.getNext();
163 key->addPoseReference(pref.poseIndex, pref.influence);
164 }
165 }
166 break;
167 }*/
168
170 {
171 Ogre::VertexAnimationTrack* vertexTrack = static_cast<Ogre::VertexAnimationTrack*>(ogreAnimationTrack);
172 newAnimTrack = tanim->createVertexTrack(tid, vertexTrack->getAssociatedVertexData(), vertexTrack->getAnimationType());
173 for (int i = 0; i < vertexTrack->getNumKeyFrames(); i++)
174 {
175 Ogre::VertexMorphKeyFrame* key = vertexTrack->getVertexMorphKeyFrame(i);
176 Ogre::VertexMorphKeyFrame* nkey = static_cast<Ogre::VertexAnimationTrack*>(newAnimTrack)->createVertexMorphKeyFrame(key->getTime());
177 nkey->setVertexBuffer(key->getVertexBuffer());
178 }
179 break;
180 }
181
182 default:
183 newAnimTrack = 0;
184 }
185 }
186 catch (Ogre::Exception)
187 {
188 }
189
190 return newAnimTrack;
191}
192
193}
Ogre::AnimationTrack * _Clone(Ogre::Animation *tanim, const unsigned short &tid)
Ogre::AnimationTrack * ogreAnimationTrack
virtual void RemoveAllKeyFrames()
virtual unsigned short GetNumKeyFrames()
virtual void GetKeyTransform(const unsigned int &keyIndex, Ogre::Vector3 &pos, Ogre::Quaternion &quat, Ogre::Vector3 &scale)
virtual void RemoveKey(const unsigned int &keyIndex)
virtual void Update(const float &pos)
AnimTrackType GetType()
virtual void SetKeyTransform(const unsigned int &keyIndex, const Ogre::Vector3 &pos, const Ogre::Quaternion &quat, const Ogre::Vector3 &scale)
virtual float GetKeyPositionTime(const unsigned int &keyIndex)
SAnim * GetParentAnimation()
Ogre::AnimationTrack * GetOgreAnimationTrackPointer()
virtual void CreateKey(const float &timepos, const Ogre::Vector3 &pos, const Ogre::Quaternion &quat, const Ogre::Vector3 &scale)
virtual ~SAnimTrack()