Project

General

Profile

SO3Engine
SO3PoseAnimation.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
35
36#include <boost/lexical_cast.hpp>
37
38namespace SO3
39{
40
41SPoseAnimation::SPoseAnimation(SScene* scene, const std::string& animationName, SEntity* entity, const unsigned short& id, const unsigned short& poseHandle) : SAnim(scene, animationName, entity, id, SAnim::SO3_POSE_ANIM)
42{
43 mOgreEntity = entity->getOgreEntityPointer();
44 ogreAnimation = mOgreEntity->getMesh()->getAnimation(id);
45 ogrePoseHandle = poseHandle;
46 poseWeight = 0.0f;
47
48 Ogre::Animation::VertexTrackList ogreVertexTracks = ogreAnimation->_getVertexTrackList();
49 for (Ogre::Animation::VertexTrackList::iterator it = ogreVertexTracks.begin(); it != ogreVertexTracks.end(); it++)
50 {
51 Ogre::VertexAnimationTrack* ogreVertexTrack = it->second;
52 std::string animationTrackName = animationName+".poseTrack_"+boost::lexical_cast<std::string>(ogreVertexTrack->getHandle());
53 SAnimTrack* animationTrack = new SPoseAnimationTrack(animationTrackName, this, ogreVertexTrack->getHandle());
54 AddAnimationTrack(animationTrack);
55 }
56}
57
58SPoseAnimation::SPoseAnimation() : SAnim(0, "", 0, 0, SO3_UNKNOWN_ANIM)
59{
60 // Forbiden (private)
61}
62
66
68{
69 return mOgreEntity->getAnimationState(name);
70}
71
72void SPoseAnimation::SetWeight(const float& weight)
73{
74 unsigned int i = 0;
75 Ogre::Animation::VertexTrackList ogreVertexTracks = ogreAnimation->_getVertexTrackList();
76 for (Ogre::Animation::VertexTrackList::iterator it = ogreVertexTracks.begin(); it != ogreVertexTracks.end(); it++)
77 {
78 Ogre::VertexAnimationTrack* ogreVertexTrack = it->second;
79 Ogre::VertexPoseKeyFrame* ogreKeyFrame = ogreVertexTrack->getVertexPoseKeyFrame(0);
80 ogreKeyFrame->updatePoseReference(ogrePoseHandle + i, weight);
81 i++;
82 }
83
84 poseWeight = weight;
85 _GetOgreAnimationState()->getParent()->_notifyDirty();
86}
87
89{
90 return poseWeight;
91}
92
93}
void AddAnimationTrack(SAnimTrack *existingAnimationTrack)
Definition SO3Anim.cpp:187
Ogre::Animation * ogreAnimation
Definition SO3Anim.h:65
std::string name
Definition SO3DataScol.h:44
Ogre::Entity * getOgreEntityPointer()
virtual Ogre::AnimationState * _GetOgreAnimationState()
virtual float GetWeight()
virtual void SetWeight(const float &weight)