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-2005 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 00026 #ifndef __Skeleton_H__ 00027 #define __Skeleton_H__ 00028 00029 #include "OgrePrerequisites.h" 00030 #include "OgreResource.h" 00031 #include "OgreQuaternion.h" 00032 #include "OgreVector3.h" 00033 #include "OgreIteratorWrappers.h" 00034 00035 namespace Ogre { 00036 00038 enum SkeletonAnimationBlendMode { 00040 ANIMBLEND_AVERAGE, 00042 ANIMBLEND_CUMULATIVE 00043 }; 00044 00045 #define OGRE_MAX_NUM_BONES 256 00046 00047 00048 struct LinkedSkeletonAnimationSource; 00049 00075 class _OgreExport Skeleton : public Resource 00076 { 00077 friend class SkeletonInstance; 00078 protected: 00080 Skeleton(); 00081 00082 public: 00088 Skeleton(ResourceManager* creator, const String& name, ResourceHandle handle, 00089 const String& group, bool isManual = false, ManualResourceLoader* loader = 0); 00090 virtual ~Skeleton(); 00091 00092 00106 virtual Bone* createBone(void); 00107 00121 virtual Bone* createBone(unsigned short handle); 00122 00136 virtual Bone* createBone(const String& name); 00137 00148 virtual Bone* createBone(const String& name, unsigned short handle); 00149 00151 virtual unsigned short getNumBones(void) const; 00152 00164 virtual Bone* getRootBone(void) const; 00165 00166 typedef std::vector<Bone*> BoneList; 00167 typedef VectorIterator<BoneList> BoneIterator; 00169 virtual BoneIterator getRootBoneIterator(void); 00171 virtual BoneIterator getBoneIterator(void); 00172 00174 virtual Bone* getBone(unsigned short handle) const; 00175 00177 virtual Bone* getBone(const String& name) const; 00178 00182 virtual void setBindingPose(void); 00183 00193 virtual void reset(bool resetManualBones = false); 00194 00199 virtual Animation* createAnimation(const String& name, Real length); 00200 00209 virtual Animation* getAnimation(const String& name, 00210 const LinkedSkeletonAnimationSource** linker = 0) const; 00211 00213 Animation* _getAnimationImpl(const String& name, 00214 const LinkedSkeletonAnimationSource** linker = 0) const; 00215 00216 00218 virtual bool hasAnimation(const String& name); 00219 00221 virtual void removeAnimation(const String& name); 00222 00234 virtual void setAnimationState(const AnimationStateSet& animSet); 00235 00236 00241 virtual void _initAnimationState(AnimationStateSet* animSet); 00242 00247 virtual void _refreshAnimationState(AnimationStateSet* animSet); 00248 00255 virtual void _getBoneMatrices(Matrix4* pMatrices); 00256 00258 virtual unsigned short getNumAnimations(void) const; 00259 00265 virtual Animation* getAnimation(unsigned short index) const; 00266 00267 00269 virtual SkeletonAnimationBlendMode getBlendMode() const; 00271 virtual void setBlendMode(SkeletonAnimationBlendMode state); 00272 00274 virtual void _updateTransforms(void); 00275 00279 virtual void optimiseAllAnimations(void); 00280 00314 virtual void addLinkedSkeletonAnimationSource(const String& skelName, 00315 Real scale = 1.0f); 00317 virtual void removeAllLinkedSkeletonAnimationSources(void); 00318 00319 typedef std::vector<LinkedSkeletonAnimationSource> 00320 LinkedSkeletonAnimSourceList; 00321 typedef ConstVectorIterator<LinkedSkeletonAnimSourceList> 00322 LinkedSkeletonAnimSourceIterator; 00324 virtual LinkedSkeletonAnimSourceIterator 00325 getLinkedSkeletonAnimationSourceIterator(void) const; 00326 00328 virtual void _notifyManualBonesDirty(void); 00330 virtual void _notifyManualBoneStateChange(Bone* bone); 00331 00333 virtual bool getManualBonesDirty(void) const { return mManualBonesDirty; } 00335 virtual bool hasManualBones(void) const { return !mManualBones.empty(); } 00336 00337 protected: 00338 SkeletonAnimationBlendMode mBlendState; 00340 BoneList mBoneList; 00342 typedef std::map<String, Bone*> BoneListByName; 00343 BoneListByName mBoneListByName; 00344 00345 00347 mutable BoneList mRootBones; 00349 unsigned short mNextAutoHandle; 00350 typedef std::set<Bone*> BoneSet; 00352 BoneSet mManualBones; 00354 bool mManualBonesDirty; 00355 00356 00358 typedef std::map<String, Animation*> AnimationList; 00359 AnimationList mAnimationsList; 00360 00362 mutable LinkedSkeletonAnimSourceList mLinkedSkeletonAnimSourceList; 00363 00369 void deriveRootBone(void) const; 00370 00372 void _dumpContents(const String& filename); 00373 00376 void loadImpl(void); 00377 00380 void unloadImpl(void); 00382 size_t calculateSize(void) const { return 0; } // TODO 00383 00384 }; 00385 00392 class _OgreExport SkeletonPtr : public SharedPtr<Skeleton> 00393 { 00394 public: 00395 SkeletonPtr() : SharedPtr<Skeleton>() {} 00396 explicit SkeletonPtr(Skeleton* rep) : SharedPtr<Skeleton>(rep) {} 00397 SkeletonPtr(const SkeletonPtr& r) : SharedPtr<Skeleton>(r) {} 00398 SkeletonPtr(const ResourcePtr& r) : SharedPtr<Skeleton>() 00399 { 00400 // lock & copy other mutex pointer 00401 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00402 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00403 pRep = static_cast<Skeleton*>(r.getPointer()); 00404 pUseCount = r.useCountPointer(); 00405 if (pUseCount) 00406 { 00407 ++(*pUseCount); 00408 } 00409 } 00410 00412 SkeletonPtr& operator=(const ResourcePtr& r) 00413 { 00414 if (pRep == static_cast<Skeleton*>(r.getPointer())) 00415 return *this; 00416 release(); 00417 // lock & copy other mutex pointer 00418 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00419 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00420 pRep = static_cast<Skeleton*>(r.getPointer()); 00421 pUseCount = r.useCountPointer(); 00422 if (pUseCount) 00423 { 00424 ++(*pUseCount); 00425 } 00426 return *this; 00427 } 00428 }; 00429 00431 struct LinkedSkeletonAnimationSource 00432 { 00433 String skeletonName; 00434 SkeletonPtr pSkeleton; 00435 Real scale; 00436 LinkedSkeletonAnimationSource(const String& skelName, Real scl) 00437 : skeletonName(skelName), scale(scl) {} 00438 LinkedSkeletonAnimationSource(const String& skelName, Real scl, 00439 SkeletonPtr skelPtr) 00440 : skeletonName(skelName), pSkeleton(skelPtr), scale(scl) {} 00441 }; 00442 } 00443 00444 00445 #endif 00446
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:50 2006