source: OGRE/trunk/ogrenew/OgreMain/src/OgreAnimationState.cpp @ 657

Revision 657, 6.4 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26
27#include "OgreAnimationState.h"
28#include "OgreException.h"
29
30namespace Ogre
31{
32
33    //---------------------------------------------------------------------
34    AnimationState::AnimationState()
35    {
36        mTimePos = 0;
37        mLength = 0;
38        mInvLength = 0;
39        mWeight = 1.0;
40        mLoop = true;
41    }
42        //---------------------------------------------------------------------
43        AnimationState::~AnimationState()
44        {
45        }
46    //---------------------------------------------------------------------
47    AnimationState::AnimationState(const String& animName, Real timePos, Real length, Real weight, bool enabled)
48        : mAnimationName(animName), mTimePos(timePos), mWeight(weight), mEnabled(enabled)
49    {
50        mLoop = true;
51        setLength(length);
52    }
53    //---------------------------------------------------------------------
54    const String& AnimationState::getAnimationName() const
55    {
56        return mAnimationName;
57    }
58    //---------------------------------------------------------------------
59    void AnimationState::setAnimationName(const String& name)
60    {
61        mAnimationName = name;
62    }
63    //---------------------------------------------------------------------
64    Real AnimationState::getTimePosition(void) const
65    {
66        return mTimePos;
67    }
68    //---------------------------------------------------------------------
69    void AnimationState::setTimePosition(Real timePos)
70    {
71        mTimePos = timePos;
72        if (mLoop)
73        {
74            // Wrap
75            mTimePos = fmod(mTimePos, mLength);
76            if(mTimePos < 0)
77                mTimePos += mLength;     
78        }
79        else
80        {
81            // Clamp
82            if(mTimePos < 0)
83                mTimePos = 0;
84            else if (mTimePos > mLength)
85                mTimePos = mLength;
86        }
87    }
88    //---------------------------------------------------------------------
89    Real AnimationState::getLength() const
90    {
91        return mLength;
92    }
93    //---------------------------------------------------------------------
94    void AnimationState::setLength(Real len)
95    {
96        mLength = len;
97        if (len != 0)
98        {
99            mInvLength = 1/len;
100        }
101        else
102        {
103            mInvLength = 0;
104        }
105    }
106    //---------------------------------------------------------------------
107    Real AnimationState::getWeight(void) const
108    {
109        return mWeight;
110    }
111    //---------------------------------------------------------------------
112    void AnimationState::setWeight(Real weight)
113    {
114        mWeight = weight;
115    }
116    //---------------------------------------------------------------------
117    void AnimationState::addTime(Real offset)
118    {
119        setTimePosition(mTimePos += offset);
120    }
121    //---------------------------------------------------------------------
122    bool AnimationState::getEnabled(void) const
123    {
124        return mEnabled;
125    }
126    //---------------------------------------------------------------------
127    void AnimationState::setEnabled(bool enabled)
128    {
129        mEnabled = enabled;
130    }
131    //---------------------------------------------------------------------
132    bool AnimationState::operator==(const AnimationState& rhs) const
133    {
134        if (mAnimationName == rhs.mAnimationName &&
135            mEnabled == rhs.mEnabled &&
136            mTimePos == rhs.mTimePos &&
137            mWeight == rhs.mWeight &&
138            mLength == rhs.mLength &&
139            mLoop == rhs.mLoop)
140        {
141            return true;
142        }
143        else
144        {
145            return false;
146        }
147    }
148    //---------------------------------------------------------------------
149    bool AnimationState::operator!=(const AnimationState& rhs) const
150    {
151        return !(*this == rhs);
152    }
153    //---------------------------------------------------------------------
154    Real AnimationState::getValue(void) const
155    {
156        return mTimePos * mInvLength;
157    }
158    //---------------------------------------------------------------------
159    void AnimationState::setValue(Real value)
160    {
161        mTimePos = value * mLength;
162    }
163    //---------------------------------------------------------------------
164    void AnimationState::copyStateFrom(const AnimationState& animState)
165    {
166        mTimePos = animState.mTimePos;
167        mLength = animState.mLength;
168        mInvLength = animState.mInvLength;
169        mWeight = animState.mWeight;
170        mEnabled = animState.mEnabled;
171        mLoop = animState.mLoop;
172    }
173
174    //---------------------------------------------------------------------
175    void CopyAnimationStateSubset(AnimationStateSet& target, const AnimationStateSet& source)
176    {
177        AnimationStateSet::iterator i, iend;
178        iend = target.end();
179        for (i = target.begin(); i != iend; ++i) {
180            AnimationStateSet::const_iterator iother = source.find(i->first);
181            if (iother == source.end()) {
182                OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "No animation entry found named " + i->first,
183                    "CopyAnimationStateSubset");
184            } else {
185                i->second.copyStateFrom(iother->second);
186            }
187        }
188    }
189
190
191}
192
Note: See TracBrowser for help on using the repository browser.