00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #include "OgreStableHeaders.h" 00026 #include "OgreAnimation.h" 00027 #include "OgreKeyFrame.h" 00028 #include "OgreAnimationTrack.h" 00029 #include "OgreException.h" 00030 #include "OgreSkeleton.h" 00031 #include "OgreBone.h" 00032 00033 namespace Ogre { 00034 00035 Animation::InterpolationMode Animation::msDefaultInterpolationMode = Animation::IM_LINEAR; 00036 //--------------------------------------------------------------------- 00037 Animation::Animation(const String& name, Real length) : mName(name), mLength(length) 00038 { 00039 mInterpolationMode = Animation::msDefaultInterpolationMode; 00040 } 00041 //--------------------------------------------------------------------- 00042 Animation::~Animation() 00043 { 00044 destroyAllTracks(); 00045 } 00046 //--------------------------------------------------------------------- 00047 Real Animation::getLength(void) const 00048 { 00049 return mLength; 00050 } 00051 //--------------------------------------------------------------------- 00052 AnimationTrack* Animation::createTrack(unsigned short handle) 00053 { 00054 AnimationTrack* ret; 00055 00056 ret = new AnimationTrack(this); 00057 00058 mTrackList[handle] = ret; 00059 return ret; 00060 } 00061 //--------------------------------------------------------------------- 00062 AnimationTrack* Animation::createTrack(unsigned short handle, Node* node) 00063 { 00064 AnimationTrack* ret = createTrack(handle); 00065 00066 ret->setAssociatedNode(node); 00067 00068 return ret; 00069 } 00070 //--------------------------------------------------------------------- 00071 unsigned short Animation::getNumTracks(void) const 00072 { 00073 return (unsigned short)mTrackList.size(); 00074 } 00075 //--------------------------------------------------------------------- 00076 AnimationTrack* Animation::getTrack(unsigned short handle) const 00077 { 00078 TrackList::const_iterator i = mTrackList.find(handle); 00079 00080 if (i == mTrackList.end()) 00081 { 00082 Except(Exception::ERR_ITEM_NOT_FOUND, 00083 "Cannot find track with the specified handle", 00084 "Animation::getTrackByHandle"); 00085 } 00086 00087 return i->second; 00088 00089 } 00090 //--------------------------------------------------------------------- 00091 void Animation::destroyTrack(unsigned short handle) 00092 { 00093 TrackList::iterator i = mTrackList.find(handle); 00094 00095 delete i->second; 00096 00097 mTrackList.erase(i); 00098 } 00099 //--------------------------------------------------------------------- 00100 void Animation::destroyAllTracks(void) 00101 { 00102 TrackList::iterator i; 00103 for (i = mTrackList.begin(); i != mTrackList.end(); ++i) 00104 { 00105 delete i->second; 00106 } 00107 mTrackList.clear(); 00108 } 00109 //--------------------------------------------------------------------- 00110 const String& Animation::getName(void) const 00111 { 00112 return mName; 00113 } 00114 //--------------------------------------------------------------------- 00115 void Animation::apply(Real timePos, Real weight, bool accumulate) 00116 { 00117 TrackList::iterator i; 00118 for (i = mTrackList.begin(); i != mTrackList.end(); ++i) 00119 { 00120 i->second->apply(timePos, weight, accumulate); 00121 } 00122 00123 00124 } 00125 //--------------------------------------------------------------------- 00126 void Animation::apply(Skeleton* skel, Real timePos, Real weight, bool accumulate) 00127 { 00128 TrackList::iterator i; 00129 for (i = mTrackList.begin(); i != mTrackList.end(); ++i) 00130 { 00131 // get bone to apply to 00132 Bone* b = skel->getBone(i->first); 00133 i->second->applyToNode(b, timePos, weight, accumulate); 00134 } 00135 00136 00137 } 00138 //--------------------------------------------------------------------- 00139 void Animation::setInterpolationMode(InterpolationMode im) 00140 { 00141 mInterpolationMode = im; 00142 } 00143 //--------------------------------------------------------------------- 00144 Animation::InterpolationMode Animation::getInterpolationMode(void) const 00145 { 00146 return mInterpolationMode; 00147 } 00148 //--------------------------------------------------------------------- 00149 void Animation::setDefaultInterpolationMode(InterpolationMode im) 00150 { 00151 msDefaultInterpolationMode = im; 00152 } 00153 //--------------------------------------------------------------------- 00154 Animation::InterpolationMode Animation::getDefaultInterpolationMode(void) 00155 { 00156 return msDefaultInterpolationMode; 00157 } 00158 //--------------------------------------------------------------------- 00159 const Animation::TrackList& Animation::_getTrackList(void) const 00160 { 00161 return mTrackList; 00162 00163 } 00164 00165 } 00166 00167
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:21:51 2004