Project

General

Profile

SO3Engine
SO3NodeAnimationTrack.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
28
29namespace SO3
30{
31
32SNodeAnimationTrack::SNodeAnimationTrack(const std::string& animationTrackName, SNodeAnimation* animation, const unsigned short& nodeTrackAnimationId) : SAnimTrack(animationTrackName, animation, SAnimTrack::SO3_NODE_TRACK)
33{
34 ogreAnimationTrack = GetParentAnimation()->GetOgreAnimationPointer()->createNodeTrack(nodeTrackAnimationId, animation->GetParentNode()->GetOgreSceneNodePointer());
35}
36
41
42SNodeAnimationTrack::SNodeAnimationTrack() : SAnimTrack("", 0, SAnimTrack::SO3_NODE_TRACK)
43{
44 //Forbiden (private)
45}
46
47void SNodeAnimationTrack::CreateKey(const float& timepos, const Ogre::Vector3& pos, const Ogre::Quaternion& quat, const Ogre::Vector3& scale)
48{
49 Ogre::NodeAnimationTrack* mTrack = static_cast <Ogre::NodeAnimationTrack*>(GetOgreAnimationTrackPointer());
50 Ogre::TransformKeyFrame* key = mTrack->createNodeKeyFrame(timepos);
51
52 if (key)
53 {
54 key->setTranslate(pos);
55 key->setRotation(quat);
56 key->setScale(scale);
57 }
58}
59
60void SNodeAnimationTrack::SetKeyTransform(const unsigned int& keyIndex, const Ogre::Vector3& pos, const Ogre::Quaternion& quat, const Ogre::Vector3& scale)
61{
62 Ogre::NodeAnimationTrack* mTrack = static_cast <Ogre::NodeAnimationTrack*> (GetOgreAnimationTrackPointer());
63 Ogre::TransformKeyFrame* key = 0;
64 if(((int)GetNumKeyFrames() - 1) >= (int)keyIndex)
65 key = mTrack->getNodeKeyFrame(keyIndex);
66
67 if (key)
68 {
69 key->setTranslate(pos);
70 key->setScale(scale);
71 key->setRotation(quat);
72 }
73}
74
75void SNodeAnimationTrack::GetKeyTransform(const unsigned int& keyIndex, Ogre::Vector3& pos, Ogre::Quaternion& quat, Ogre::Vector3& scale)
76{
77 pos = Ogre::Vector3::ZERO;
78 quat = Ogre::Quaternion::IDENTITY;
79 scale = Ogre::Vector3::ZERO;
80
81 Ogre::NodeAnimationTrack* mTrack = static_cast <Ogre::NodeAnimationTrack*> (GetOgreAnimationTrackPointer());
82 Ogre::TransformKeyFrame* key = 0;
83 if(((int)GetNumKeyFrames() - 1) >= (int)keyIndex)
84 key = mTrack->getNodeKeyFrame(keyIndex);
85
86 if (key)
87 {
88 pos = key->getTranslate();
89 quat = key->getRotation();
90 scale = key->getScale();
91 }
92}
93
98
99}
Ogre::Animation * GetOgreAnimationPointer()
Definition SO3Anim.cpp:115
SNode * GetParentNode()
Definition SO3Anim.cpp:120
Ogre::AnimationTrack * ogreAnimationTrack
virtual unsigned short GetNumKeyFrames()
SAnim * GetParentAnimation()
Ogre::AnimationTrack * GetOgreAnimationTrackPointer()
virtual void SetKeyTransform(const unsigned int &keyIndex, const Ogre::Vector3 &pos, const Ogre::Quaternion &quat, const Ogre::Vector3 &scale)
virtual void GetKeyTransform(const unsigned int &keyIndex, Ogre::Vector3 &pos, Ogre::Quaternion &quat, Ogre::Vector3 &scale)
virtual void CreateKey(const float &timepos, const Ogre::Vector3 &pos, const Ogre::Quaternion &quat, const Ogre::Vector3 &scale)
Ogre::SceneNode * GetOgreSceneNodePointer()