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 00027 #include "OgreAnimationState.h" 00028 #include "OgreException.h" 00029 00030 namespace Ogre 00031 { 00032 00033 //--------------------------------------------------------------------- 00034 AnimationState::AnimationState() 00035 { 00036 mTimePos = 0; 00037 mLength = 0; 00038 mInvLength = 0; 00039 mWeight = 1.0; 00040 mLoop = true; 00041 } 00042 //--------------------------------------------------------------------- 00043 AnimationState::~AnimationState() 00044 { 00045 } 00046 //--------------------------------------------------------------------- 00047 AnimationState::AnimationState(const String& animName, Real timePos, Real length, Real weight, bool enabled) 00048 : mAnimationName(animName), mTimePos(timePos), mWeight(weight), mEnabled(enabled) 00049 { 00050 mLoop = true; 00051 setLength(length); 00052 } 00053 //--------------------------------------------------------------------- 00054 const String& AnimationState::getAnimationName() const 00055 { 00056 return mAnimationName; 00057 } 00058 //--------------------------------------------------------------------- 00059 void AnimationState::setAnimationName(const String& name) 00060 { 00061 mAnimationName = name; 00062 } 00063 //--------------------------------------------------------------------- 00064 Real AnimationState::getTimePosition(void) const 00065 { 00066 return mTimePos; 00067 } 00068 //--------------------------------------------------------------------- 00069 void AnimationState::setTimePosition(Real timePos) 00070 { 00071 mTimePos = timePos; 00072 if (mLoop) 00073 { 00074 // Wrap 00075 mTimePos = fmod(mTimePos, mLength); 00076 if(mTimePos < 0) 00077 mTimePos += mLength; 00078 } 00079 else 00080 { 00081 // Clamp 00082 if(mTimePos < 0) 00083 mTimePos = 0; 00084 else if (mTimePos > mLength) 00085 mTimePos = mLength; 00086 } 00087 } 00088 //--------------------------------------------------------------------- 00089 Real AnimationState::getLength() const 00090 { 00091 return mLength; 00092 } 00093 //--------------------------------------------------------------------- 00094 void AnimationState::setLength(Real len) 00095 { 00096 mLength = len; 00097 if (len != 0) 00098 { 00099 mInvLength = 1/len; 00100 } 00101 else 00102 { 00103 mInvLength = 0; 00104 } 00105 } 00106 //--------------------------------------------------------------------- 00107 Real AnimationState::getWeight(void) const 00108 { 00109 return mWeight; 00110 } 00111 //--------------------------------------------------------------------- 00112 void AnimationState::setWeight(Real weight) 00113 { 00114 mWeight = weight; 00115 } 00116 //--------------------------------------------------------------------- 00117 void AnimationState::addTime(Real offset) 00118 { 00119 setTimePosition(mTimePos += offset); 00120 } 00121 //--------------------------------------------------------------------- 00122 bool AnimationState::getEnabled(void) const 00123 { 00124 return mEnabled; 00125 } 00126 //--------------------------------------------------------------------- 00127 void AnimationState::setEnabled(bool enabled) 00128 { 00129 mEnabled = enabled; 00130 } 00131 //--------------------------------------------------------------------- 00132 bool AnimationState::operator==(const AnimationState& rhs) const 00133 { 00134 if (mAnimationName == rhs.mAnimationName && 00135 mEnabled == rhs.mEnabled && 00136 mTimePos == rhs.mTimePos && 00137 mWeight == rhs.mWeight && 00138 mLength == rhs.mLength && 00139 mLoop == rhs.mLoop) 00140 { 00141 return true; 00142 } 00143 else 00144 { 00145 return false; 00146 } 00147 } 00148 //--------------------------------------------------------------------- 00149 bool AnimationState::operator!=(const AnimationState& rhs) const 00150 { 00151 return !(*this == rhs); 00152 } 00153 //--------------------------------------------------------------------- 00154 Real AnimationState::getValue(void) const 00155 { 00156 return mTimePos * mInvLength; 00157 } 00158 //--------------------------------------------------------------------- 00159 void AnimationState::setValue(Real value) 00160 { 00161 mTimePos = value * mLength; 00162 } 00163 //--------------------------------------------------------------------- 00164 void AnimationState::copyStateFrom(const AnimationState& animState) 00165 { 00166 mTimePos = animState.mTimePos; 00167 mLength = animState.mLength; 00168 mInvLength = animState.mInvLength; 00169 mWeight = animState.mWeight; 00170 mEnabled = animState.mEnabled; 00171 mLoop = animState.mLoop; 00172 } 00173 00174 //--------------------------------------------------------------------- 00175 void CopyAnimationStateSubset(AnimationStateSet& target, const AnimationStateSet& source) 00176 { 00177 AnimationStateSet::iterator i, iend; 00178 iend = target.end(); 00179 for (i = target.begin(); i != iend; ++i) { 00180 AnimationStateSet::const_iterator iother = source.find(i->first); 00181 if (iother == source.end()) { 00182 Except(Exception::ERR_ITEM_NOT_FOUND, "No animation entry found named " + i->first, 00183 "CopyAnimationStateSubset"); 00184 } else { 00185 i->second.copyStateFrom(iother->second); 00186 } 00187 } 00188 } 00189 00190 00191 } 00192
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:14 2004