Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreAnimationState.cpp

Go to the documentation of this file.
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 
00029 namespace Ogre 
00030 {
00031 
00032     //---------------------------------------------------------------------
00033     AnimationState::AnimationState()
00034     {
00035         mTimePos = 0;
00036         mLength = 0;
00037         mInvLength = 0;
00038         mWeight = 1.0;
00039 
00040     }
00041     //---------------------------------------------------------------------
00042     AnimationState::~AnimationState()
00043     {
00044     }
00045     //---------------------------------------------------------------------
00046     AnimationState::AnimationState(const String& animName, Real timePos, Real length, Real weight, bool enabled)
00047         : mAnimationName(animName), mTimePos(timePos), mWeight(weight), mEnabled(enabled)
00048     {
00049         setLength(length);
00050     }
00051     //---------------------------------------------------------------------
00052     const String& AnimationState::getAnimationName() const
00053     {
00054         return mAnimationName;
00055     }
00056     //---------------------------------------------------------------------
00057     void AnimationState::setAnimationName(const String& name)
00058     {
00059         mAnimationName = name;
00060     }
00061     //---------------------------------------------------------------------
00062     Real AnimationState::getTimePosition(void) const
00063     {
00064         return mTimePos;
00065     }
00066     //---------------------------------------------------------------------
00067     void AnimationState::setTimePosition(Real timePos)
00068     {
00069         mTimePos = timePos;
00070     }
00071     //---------------------------------------------------------------------
00072     Real AnimationState::getLength() const
00073     {
00074         return mLength;
00075     }
00076     //---------------------------------------------------------------------
00077     void AnimationState::setLength(Real len)
00078     {
00079         mLength = len;
00080         if (len != 0)
00081         {
00082             mInvLength = 1/len;
00083         }
00084         else
00085         {
00086             mInvLength = 0;
00087         }
00088     }
00089     //---------------------------------------------------------------------
00090     Real AnimationState::getWeight(void) const
00091     {
00092         return mWeight;
00093     }
00094     //---------------------------------------------------------------------
00095     void AnimationState::setWeight(Real weight)
00096     {
00097         mWeight = weight;
00098     }
00099     //---------------------------------------------------------------------
00100     void AnimationState::addTime(Real offset)
00101     {
00102         mTimePos = mTimePos + offset;
00103 
00104         // Wrap over upper bound
00105         while (mTimePos >= mLength)
00106         {
00107             mTimePos -= mLength;
00108         }
00109 
00110         // Wrap over lower bound
00111         while (mTimePos < 0)
00112         {
00113             mTimePos += mLength;
00114         }
00115     }
00116     //---------------------------------------------------------------------
00117     bool AnimationState::getEnabled(void) const
00118     {
00119         return mEnabled;
00120     }
00121     //---------------------------------------------------------------------
00122     void AnimationState::setEnabled(bool enabled)
00123     {
00124         mEnabled = enabled;
00125     }
00126     //---------------------------------------------------------------------
00127     bool AnimationState::operator==(const AnimationState& rhs) const
00128     {
00129         if (mAnimationName == rhs.mAnimationName &&
00130             mEnabled == rhs.mEnabled &&
00131             mTimePos == rhs.mTimePos &&
00132             mWeight == rhs.mWeight &&
00133             mLength == rhs.mLength)
00134         {
00135             return true;
00136         }
00137         else
00138         {
00139             return false;
00140         }
00141     }
00142     //---------------------------------------------------------------------
00143     bool AnimationState::operator!=(const AnimationState& rhs) const
00144     {
00145         return !(*this == rhs);
00146     }
00147     //---------------------------------------------------------------------
00148     Real AnimationState::getValue(void) const
00149     {
00150         return mTimePos * mInvLength;
00151     }
00152     //---------------------------------------------------------------------
00153     void AnimationState::setValue(Real value)
00154     {
00155         mTimePos = value * mLength;
00156     }
00157 
00158 
00159 
00160 }
00161 

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:01 2004