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-2004 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 "OgreSkeletonInstance.h" 00027 #include "OgreBone.h" 00028 #include "OgreTagPoint.h" 00029 00030 00031 namespace Ogre { 00032 //------------------------------------------------------------------------- 00033 SkeletonInstance::SkeletonInstance(Skeleton* masterCopy) 00034 : Skeleton(""), mSkeleton(masterCopy) 00035 { 00036 mNextTagPointAutoHandle = 0; 00037 } 00038 //------------------------------------------------------------------------- 00039 SkeletonInstance::~SkeletonInstance() 00040 { 00041 } 00042 //------------------------------------------------------------------------- 00043 unsigned short SkeletonInstance::getNumAnimations(void) const 00044 { 00045 return mSkeleton->getNumAnimations(); 00046 } 00047 //------------------------------------------------------------------------- 00048 Animation* SkeletonInstance::getAnimation(unsigned short index) const 00049 { 00050 return mSkeleton->getAnimation(index); 00051 } 00052 //------------------------------------------------------------------------- 00053 Animation* SkeletonInstance::createAnimation(const String& name, Real length) 00054 { 00055 return mSkeleton->createAnimation(name, length); 00056 } 00057 //------------------------------------------------------------------------- 00058 Animation* SkeletonInstance::getAnimation(const String& name) const 00059 { 00060 return mSkeleton->getAnimation(name); 00061 } 00062 //------------------------------------------------------------------------- 00063 void SkeletonInstance::removeAnimation(const String& name) 00064 { 00065 mSkeleton->removeAnimation(name); 00066 } 00067 //------------------------------------------------------------------------- 00068 void SkeletonInstance::cloneBoneAndChildren(Bone* source, Bone* parent) 00069 { 00070 Bone* newBone; 00071 if (source->getName() == "") 00072 { 00073 newBone = createBone(source->getHandle()); 00074 } 00075 else 00076 { 00077 newBone = createBone(source->getName(), source->getHandle()); 00078 } 00079 if (parent == NULL) 00080 { 00081 mRootBones.push_back(newBone); 00082 } 00083 else 00084 { 00085 parent->addChild(newBone); 00086 } 00087 newBone->setOrientation(source->getOrientation()); 00088 newBone->setPosition(source->getPosition()); 00089 newBone->setScale(source->getScale()); 00090 00091 // Process children 00092 Node::ChildNodeIterator it = source->getChildIterator(); 00093 while (it.hasMoreElements()) 00094 { 00095 cloneBoneAndChildren(static_cast<Bone*>(it.getNext()), newBone); 00096 } 00097 } 00098 //------------------------------------------------------------------------- 00099 void SkeletonInstance::load(void) 00100 { 00101 mNextAutoHandle = mSkeleton->mNextAutoHandle; 00102 mNextTagPointAutoHandle = 0; 00103 // construct self from master 00104 mBlendState = mSkeleton->mBlendState; 00105 // Copy bones 00106 BoneIterator i = mSkeleton->getRootBoneIterator(); 00107 while (i.hasMoreElements()) 00108 { 00109 Bone* b = i.getNext(); 00110 cloneBoneAndChildren(b, 0); 00111 b->_update(true, false); 00112 } 00113 setBindingPose(); 00114 mIsLoaded = true; 00115 } 00116 //------------------------------------------------------------------------- 00117 void SkeletonInstance::unload(void) 00118 { 00119 Skeleton::unload(); 00120 00121 // destroy TagPoints 00122 TagPointList::iterator itp; 00123 for (itp = mTagPointList.begin(); itp != mTagPointList.end(); ++itp) 00124 { 00125 delete itp->second; 00126 } 00127 mTagPointList.clear(); 00128 } 00129 00130 //------------------------------------------------------------------------- 00131 TagPoint* SkeletonInstance::createTagPointOnBone(Bone* bone, 00132 const Quaternion &offsetOrientation, 00133 const Vector3 &offsetPosition) 00134 { 00135 TagPoint* ret = new TagPoint(mNextTagPointAutoHandle++, this); 00136 mTagPointList[mNextTagPointAutoHandle] = ret; 00137 00138 ret->translate(offsetPosition); 00139 ret->rotate(offsetOrientation); 00140 ret->setBindingPose(); 00141 bone->addChild(ret); 00142 00143 return ret; 00144 } 00145 00146 } 00147
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:48 2004