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 "OgreAnimationState.h" 00032 #include "OgreQuaternion.h" 00033 #include "OgreVector3.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 virtual void removeAnimation(const String& name); 00214 00226 virtual void setAnimationState(const AnimationStateSet& animSet); 00227 00229 virtual const AnimationStateSet& getAnimationState(void) const; 00230 00231 00236 virtual void _initAnimationState(AnimationStateSet* animSet); 00237 00242 virtual void _refreshAnimationState(AnimationStateSet* animSet); 00243 00250 virtual void _getBoneMatrices(Matrix4* pMatrices); 00251 00253 virtual unsigned short getNumAnimations(void) const; 00254 00260 virtual Animation* getAnimation(unsigned short index) const; 00261 00262 00264 virtual SkeletonAnimationBlendMode getBlendMode(); 00266 virtual void setBlendMode(SkeletonAnimationBlendMode state); 00267 00269 virtual void _updateTransforms(void); 00270 00274 virtual void optimiseAllAnimations(void); 00275 00309 virtual void addLinkedSkeletonAnimationSource(const String& skelName, 00310 Real scale = 1.0f); 00312 virtual void removeAllLinkedSkeletonAnimationSources(void); 00313 00314 typedef std::vector<LinkedSkeletonAnimationSource> 00315 LinkedSkeletonAnimSourceList; 00316 typedef ConstVectorIterator<LinkedSkeletonAnimSourceList> 00317 LinkedSkeletonAnimSourceIterator; 00319 virtual LinkedSkeletonAnimSourceIterator 00320 getLinkedSkeletonAnimationSourceIterator(void) const; 00321 00322 protected: 00323 SkeletonAnimationBlendMode mBlendState; 00325 BoneList mBoneList; 00327 typedef std::map<String, Bone*> BoneListByName; 00328 BoneListByName mBoneListByName; 00329 00330 00332 mutable BoneList mRootBones; 00334 unsigned short mNextAutoHandle; 00335 00336 00338 typedef std::map<String, Animation*> AnimationList; 00339 AnimationList mAnimationsList; 00340 00342 AnimationStateSet mLastAnimationState; 00343 00345 mutable LinkedSkeletonAnimSourceList mLinkedSkeletonAnimSourceList; 00346 00352 void deriveRootBone(void) const; 00353 00355 void _dumpContents(const String& filename); 00356 00359 void loadImpl(void); 00360 00363 void unloadImpl(void); 00365 size_t calculateSize(void) const { return 0; } // TODO 00366 00367 }; 00368 00375 class _OgreExport SkeletonPtr : public SharedPtr<Skeleton> 00376 { 00377 public: 00378 SkeletonPtr() : SharedPtr<Skeleton>() {} 00379 explicit SkeletonPtr(Skeleton* rep) : SharedPtr<Skeleton>(rep) {} 00380 SkeletonPtr(const SkeletonPtr& r) : SharedPtr<Skeleton>(r) {} 00381 SkeletonPtr(const ResourcePtr& r) : SharedPtr<Skeleton>() 00382 { 00383 // lock & copy other mutex pointer 00384 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00385 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00386 pRep = static_cast<Skeleton*>(r.getPointer()); 00387 pUseCount = r.useCountPointer(); 00388 if (pUseCount) 00389 { 00390 ++(*pUseCount); 00391 } 00392 } 00393 00395 SkeletonPtr& operator=(const ResourcePtr& r) 00396 { 00397 if (pRep == static_cast<Skeleton*>(r.getPointer())) 00398 return *this; 00399 release(); 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 return *this; 00410 } 00411 }; 00412 00414 struct LinkedSkeletonAnimationSource 00415 { 00416 String skeletonName; 00417 SkeletonPtr pSkeleton; 00418 Real scale; 00419 LinkedSkeletonAnimationSource(const String& skelName, Real scl) 00420 : skeletonName(skelName), scale(scl) {} 00421 LinkedSkeletonAnimationSource(const String& skelName, Real scl, 00422 SkeletonPtr skelPtr) 00423 : skeletonName(skelName), pSkeleton(skelPtr), scale(scl) {} 00424 }; 00425 } 00426 00427 00428 #endif 00429
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:52 2006