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         mLoop = true;
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         mLoop = true;
00050         setLength(length);
00051     }
00052     //---------------------------------------------------------------------
00053     const String& AnimationState::getAnimationName() const
00054     {
00055         return mAnimationName;
00056     }
00057     //---------------------------------------------------------------------
00058     void AnimationState::setAnimationName(const String& name)
00059     {
00060         mAnimationName = name;
00061     }
00062     //---------------------------------------------------------------------
00063     Real AnimationState::getTimePosition(void) const
00064     {
00065         return mTimePos;
00066     }
00067     //---------------------------------------------------------------------
00068     void AnimationState::setTimePosition(Real timePos)
00069     {
00070         mTimePos = timePos;
00071         if (mLoop)
00072         {
00073             // Wrap
00074             mTimePos = fmod(mTimePos, mLength);
00075             if(mTimePos < 0)
00076                 mTimePos += mLength;     
00077         }
00078         else
00079         {
00080             // Clamp
00081             if(mTimePos < 0)
00082                 mTimePos = 0;
00083             else if (mTimePos > mLength)
00084                 mTimePos = mLength;
00085         }
00086     }
00087     //---------------------------------------------------------------------
00088     Real AnimationState::getLength() const
00089     {
00090         return mLength;
00091     }
00092     //---------------------------------------------------------------------
00093     void AnimationState::setLength(Real len)
00094     {
00095         mLength = len;
00096         if (len != 0)
00097         {
00098             mInvLength = 1/len;
00099         }
00100         else
00101         {
00102             mInvLength = 0;
00103         }
00104     }
00105     //---------------------------------------------------------------------
00106     Real AnimationState::getWeight(void) const
00107     {
00108         return mWeight;
00109     }
00110     //---------------------------------------------------------------------
00111     void AnimationState::setWeight(Real weight)
00112     {
00113         mWeight = weight;
00114     }
00115     //---------------------------------------------------------------------
00116     void AnimationState::addTime(Real offset)
00117     {
00118         setTimePosition(mTimePos += offset);
00119     }
00120     //---------------------------------------------------------------------
00121     bool AnimationState::getEnabled(void) const
00122     {
00123         return mEnabled;
00124     }
00125     //---------------------------------------------------------------------
00126     void AnimationState::setEnabled(bool enabled)
00127     {
00128         mEnabled = enabled;
00129     }
00130     //---------------------------------------------------------------------
00131     bool AnimationState::operator==(const AnimationState& rhs) const
00132     {
00133         if (mAnimationName == rhs.mAnimationName &&
00134             mEnabled == rhs.mEnabled &&
00135             mTimePos == rhs.mTimePos &&
00136             mWeight == rhs.mWeight &&
00137             mLength == rhs.mLength && 
00138             mLoop == rhs.mLoop)
00139         {
00140             return true;
00141         }
00142         else
00143         {
00144             return false;
00145         }
00146     }
00147     //---------------------------------------------------------------------
00148     bool AnimationState::operator!=(const AnimationState& rhs) const
00149     {
00150         return !(*this == rhs);
00151     }
00152     //---------------------------------------------------------------------
00153     Real AnimationState::getValue(void) const
00154     {
00155         return mTimePos * mInvLength;
00156     }
00157     //---------------------------------------------------------------------
00158     void AnimationState::setValue(Real value)
00159     {
00160         mTimePos = value * mLength;
00161     }
00162 
00163 
00164 
00165 }
00166 

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:21:51 2004