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

# OgreAnimation.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 #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     Animation::RotationInterpolationMode
    00037         Animation::msDefaultRotationInterpolationMode = Animation::RIM_LINEAR;
    00038     //---------------------------------------------------------------------
    00039     Animation::Animation(const String& name, Real length) : mName(name), mLength(length)
    00040     {
    00041         mInterpolationMode = Animation::msDefaultInterpolationMode;
    00042         mRotationInterpolationMode = Animation::msDefaultRotationInterpolationMode;
    00043     }
    00044     //---------------------------------------------------------------------
    00045     Animation::~Animation()
    00046     {
    00047         destroyAllTracks();
    00048     }
    00049     //---------------------------------------------------------------------
    00050     Real Animation::getLength(void) const
    00051     {
    00052         return mLength;
    00053     }
    00054     //---------------------------------------------------------------------
    00055     AnimationTrack* Animation::createTrack(unsigned short handle)
    00056     {
    00057         AnimationTrack* ret;
    00058
    00059         ret = new AnimationTrack(this);
    00060
    00061         mTrackList[handle] = ret;
    00062         return ret;
    00063     }
    00064     //---------------------------------------------------------------------
    00065     AnimationTrack* Animation::createTrack(unsigned short handle, Node* node)
    00066     {
    00067         AnimationTrack* ret = createTrack(handle);
    00068
    00069         ret->setAssociatedNode(node);
    00070
    00071         return ret;
    00072     }
    00073     //---------------------------------------------------------------------
    00074     unsigned short Animation::getNumTracks(void) const
    00075     {
    00076         return (unsigned short)mTrackList.size();
    00077     }
    00078     //---------------------------------------------------------------------
    00079     AnimationTrack* Animation::getTrack(unsigned short handle) const
    00080     {
    00081         TrackList::const_iterator i = mTrackList.find(handle);
    00082
    00083         if (i == mTrackList.end())
    00084         {
    00085             Except(Exception::ERR_ITEM_NOT_FOUND,
    00086                 "Cannot find track with the specified handle",
    00087                 "Animation::getTrackByHandle");
    00088         }
    00089
    00090         return i->second;
    00091
    00092     }
    00093     //---------------------------------------------------------------------
    00094     void Animation::destroyTrack(unsigned short handle)
    00095     {
    00096         TrackList::iterator i = mTrackList.find(handle);
    00097
    00098         delete i->second;
    00099
    00100         mTrackList.erase(i);
    00101     }
    00102     //---------------------------------------------------------------------
    00103     void Animation::destroyAllTracks(void)
    00104     {
    00105         TrackList::iterator i;
    00106         for (i = mTrackList.begin(); i != mTrackList.end(); ++i)
    00107         {
    00108             delete i->second;
    00109         }
    00110         mTrackList.clear();
    00111     }
    00112     //---------------------------------------------------------------------
    00113     const String& Animation::getName(void) const
    00114     {
    00115         return mName;
    00116     }
    00117     //---------------------------------------------------------------------
    00118     void Animation::apply(Real timePos, Real weight, bool accumulate)
    00119     {
    00120         TrackList::iterator i;
    00121         for (i = mTrackList.begin(); i != mTrackList.end(); ++i)
    00122         {
    00123             i->second->apply(timePos, weight, accumulate);
    00124         }
    00125
    00126
    00127     }
    00128     //---------------------------------------------------------------------
    00129     void Animation::apply(Skeleton* skel, Real timePos, Real weight, bool accumulate)
    00130     {
    00131         TrackList::iterator i;
    00132         for (i = mTrackList.begin(); i != mTrackList.end(); ++i)
    00133         {
    00134             // get bone to apply to
    00135             Bone* b = skel->getBone(i->first);
    00136             i->second->applyToNode(b, timePos, weight, accumulate);
    00137         }
    00138
    00139
    00140     }
    00141     //---------------------------------------------------------------------
    00142     void Animation::setInterpolationMode(InterpolationMode im)
    00143     {
    00144         mInterpolationMode = im;
    00145     }
    00146     //---------------------------------------------------------------------
    00147     Animation::InterpolationMode Animation::getInterpolationMode(void) const
    00148     {
    00149         return mInterpolationMode;
    00150     }
    00151     //---------------------------------------------------------------------
    00152     void Animation::setDefaultInterpolationMode(InterpolationMode im)
    00153     {
    00154         msDefaultInterpolationMode = im;
    00155     }
    00156     //---------------------------------------------------------------------
    00157     Animation::InterpolationMode Animation::getDefaultInterpolationMode(void)
    00158     {
    00159         return msDefaultInterpolationMode;
    00160     }
    00161     //---------------------------------------------------------------------
    00162     const Animation::TrackList& Animation::_getTrackList(void) const
    00163     {
    00164         return mTrackList;
    00165
    00166     }
    00167     //---------------------------------------------------------------------
    00168     void Animation::setRotationInterpolationMode(RotationInterpolationMode im)
    00169     {
    00170         mRotationInterpolationMode = im;
    00171     }
    00172     //---------------------------------------------------------------------
    00173     Animation::RotationInterpolationMode Animation::getRotationInterpolationMode(void) const
    00174     {
    00175         return mRotationInterpolationMode;
    00176     }
    00177     //---------------------------------------------------------------------
    00178     void Animation::setDefaultRotationInterpolationMode(RotationInterpolationMode im)
    00179     {
    00180         msDefaultRotationInterpolationMode = im;
    00181     }
    00182     //---------------------------------------------------------------------
    00183     Animation::RotationInterpolationMode Animation::getDefaultRotationInterpolationMode(void)
    00184     {
    00185         return msDefaultRotationInterpolationMode;
    00186     }
    00187
    00188 }
    00189
    00190

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:14 2004