Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

# OgreSkeleton.h

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 (c) 2000-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029
    00030 #ifndef __Skeleton_H__
    00031 #define __Skeleton_H__
    00032
    00033 #include "OgrePrerequisites.h"
    00034 #include "OgreResource.h"
    00035 #include "OgreQuaternion.h"
    00036 #include "OgreVector3.h"
    00037 #include "OgreIteratorWrappers.h"
    00038 #include "OgreStringVector.h"
    00039
    00040 namespace Ogre {
    00041
    00043     enum SkeletonAnimationBlendMode {
    00045         ANIMBLEND_AVERAGE,
    00047         ANIMBLEND_CUMULATIVE
    00048     };
    00049
    00050 #define OGRE_MAX_NUM_BONES 256
    00051
    00052
    00053     struct LinkedSkeletonAnimationSource;
    00054
    00080     class _OgreExport Skeleton : public Resource
    00081     {
    00082         friend class SkeletonInstance;
    00083     protected:
    00085         Skeleton();
    00086
    00087     public:
    00093         Skeleton(ResourceManager* creator, const String& name, ResourceHandle handle,
    00094             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00095         virtual ~Skeleton();
    00096
    00097
    00111         virtual Bone* createBone(void);
    00112
    00126         virtual Bone* createBone(unsigned short handle);
    00127
    00141         virtual Bone* createBone(const String& name);
    00142
    00153         virtual Bone* createBone(const String& name, unsigned short handle);
    00154
    00156         virtual unsigned short getNumBones(void) const;
    00157
    00169         virtual Bone* getRootBone(void) const;
    00170
    00171         typedef std::vector<Bone*> BoneList;
    00172         typedef VectorIterator<BoneList> BoneIterator;
    00174         virtual BoneIterator getRootBoneIterator(void);
    00176         virtual BoneIterator getBoneIterator(void);
    00177
    00179         virtual Bone* getBone(unsigned short handle) const;
    00180
    00182         virtual Bone* getBone(const String& name) const;
    00183
    00187         virtual void setBindingPose(void);
    00188
    00198         virtual void reset(bool resetManualBones = false);
    00199
    00204         virtual Animation* createAnimation(const String& name, Real length);
    00205
    00214         virtual Animation* getAnimation(const String& name,
    00215             const LinkedSkeletonAnimationSource** linker = 0) const;
    00216
    00218         virtual Animation* _getAnimationImpl(const String& name,
    00219             const LinkedSkeletonAnimationSource** linker = 0) const;
    00220
    00221
    00223         virtual bool hasAnimation(const String& name);
    00224
    00226         virtual void removeAnimation(const String& name);
    00227
    00239         virtual void setAnimationState(const AnimationStateSet& animSet);
    00240
    00241
    00246         virtual void _initAnimationState(AnimationStateSet* animSet);
    00247
    00252         virtual void _refreshAnimationState(AnimationStateSet* animSet);
    00253
    00260         virtual void _getBoneMatrices(Matrix4* pMatrices);
    00261
    00263         virtual unsigned short getNumAnimations(void) const;
    00264
    00270         virtual Animation* getAnimation(unsigned short index) const;
    00271
    00272
    00274         virtual SkeletonAnimationBlendMode getBlendMode() const;
    00276         virtual void setBlendMode(SkeletonAnimationBlendMode state);
    00277
    00279         virtual void _updateTransforms(void);
    00280
    00286         virtual void optimiseAllAnimations(bool preservingIdentityNodeTracks = false);
    00287
    00321         virtual void addLinkedSkeletonAnimationSource(const String& skelName,
    00322             Real scale = 1.0f);
    00324         virtual void removeAllLinkedSkeletonAnimationSources(void);
    00325
    00326         typedef std::vector<LinkedSkeletonAnimationSource>
    00327             LinkedSkeletonAnimSourceList;
    00328         typedef ConstVectorIterator<LinkedSkeletonAnimSourceList>
    00329             LinkedSkeletonAnimSourceIterator;
    00331         virtual LinkedSkeletonAnimSourceIterator
    00332             getLinkedSkeletonAnimationSourceIterator(void) const;
    00333
    00335         virtual void _notifyManualBonesDirty(void);
    00337         virtual void _notifyManualBoneStateChange(Bone* bone);
    00338
    00340         virtual bool getManualBonesDirty(void) const { return mManualBonesDirty; }
    00342         virtual bool hasManualBones(void) const { return !mManualBones.empty(); }
    00343
    00345         typedef std::vector<ushort> BoneHandleMap;
    00346
    00380         virtual void _mergeSkeletonAnimations(const Skeleton* source,
    00381             const BoneHandleMap& boneHandleMap,
    00382             const StringVector& animations = StringVector());
    00383
    00388         virtual void _buildMapBoneByHandle(const Skeleton* source,
    00389             BoneHandleMap& boneHandleMap) const;
    00390
    00395         virtual void _buildMapBoneByName(const Skeleton* source,
    00396             BoneHandleMap& boneHandleMap) const;
    00397
    00398     protected:
    00399         SkeletonAnimationBlendMode mBlendState;
    00401         BoneList mBoneList;
    00403         typedef std::map<String, Bone*> BoneListByName;
    00404         BoneListByName mBoneListByName;
    00405
    00406
    00408         mutable BoneList mRootBones;
    00410         unsigned short mNextAutoHandle;
    00411         typedef std::set<Bone*> BoneSet;
    00413         BoneSet mManualBones;
    00415         bool mManualBonesDirty;
    00416
    00417
    00419         typedef std::map<String, Animation*> AnimationList;
    00420         AnimationList mAnimationsList;
    00421
    00423         mutable LinkedSkeletonAnimSourceList mLinkedSkeletonAnimSourceList;
    00424
    00430         void deriveRootBone(void) const;
    00431
    00433         void _dumpContents(const String& filename);
    00434
    00437         void loadImpl(void);
    00438
    00441         void unloadImpl(void);
    00443         size_t calculateSize(void) const { return 0; } // TODO
    00444
    00445     };
    00446
    00453     class _OgreExport SkeletonPtr : public SharedPtr<Skeleton>
    00454     {
    00455     public:
    00456         SkeletonPtr() : SharedPtr<Skeleton>() {}
    00457         explicit SkeletonPtr(Skeleton* rep) : SharedPtr<Skeleton>(rep) {}
    00458         SkeletonPtr(const SkeletonPtr& r) : SharedPtr<Skeleton>(r) {}
    00459         SkeletonPtr(const ResourcePtr& r) : SharedPtr<Skeleton>()
    00460         {
    00461             // lock & copy other mutex pointer
    00462             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00463             {
    00464                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00465                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00466                 pRep = static_cast<Skeleton*>(r.getPointer());
    00467                 pUseCount = r.useCountPointer();
    00468                 if (pUseCount)
    00469                 {
    00470                     ++(*pUseCount);
    00471                 }
    00472             }
    00473         }
    00474
    00476         SkeletonPtr& operator=(const ResourcePtr& r)
    00477         {
    00478             if (pRep == static_cast<Skeleton*>(r.getPointer()))
    00479                 return *this;
    00480             release();
    00481             // lock & copy other mutex pointer
    00482             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00483             {
    00484                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00485                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00486                 pRep = static_cast<Skeleton*>(r.getPointer());
    00487                 pUseCount = r.useCountPointer();
    00488                 if (pUseCount)
    00489                 {
    00490                     ++(*pUseCount);
    00491                 }
    00492             }
    00493             else
    00494             {
    00495                 // RHS must be a null pointer
    00496                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    00497                 setNull();
    00498             }
    00499             return *this;
    00500         }
    00501     };
    00502
    00504     struct LinkedSkeletonAnimationSource
    00505     {
    00506         String skeletonName;
    00507         SkeletonPtr pSkeleton;
    00508         Real scale;
    00509         LinkedSkeletonAnimationSource(const String& skelName, Real scl)
    00510             : skeletonName(skelName), scale(scl) {}
    00511             LinkedSkeletonAnimationSource(const String& skelName, Real scl,
    00512                 SkeletonPtr skelPtr)
    00513                 : skeletonName(skelName), pSkeleton(skelPtr), scale(scl) {}
    00514     };
    00515 }
    00516
    00517
    00518 #endif
    00519

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Mar 6 09:46:26 2008