| 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of LEXIExporter |
|---|
| 4 | |
|---|
| 5 | Copyright 2006 NDS Limited |
|---|
| 6 | |
|---|
| 7 | Author(s): |
|---|
| 8 | Mark Folkenberg, |
|---|
| 9 | Bo Krohn |
|---|
| 10 | |
|---|
| 11 | This program is free software; you can redistribute it and/or modify it under |
|---|
| 12 | the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 13 | Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 14 | version. |
|---|
| 15 | |
|---|
| 16 | This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 18 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 19 | |
|---|
| 20 | You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 21 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 22 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 23 | http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 24 | ----------------------------------------------------------------------------- |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | #include "LexiStdAfx.h" |
|---|
| 28 | #include "LexiIntermediateAPI.h" |
|---|
| 29 | |
|---|
| 30 | // |
|---|
| 31 | |
|---|
| 32 | CIntermediateBone::CIntermediateBone(const char* pszName) |
|---|
| 33 | { |
|---|
| 34 | m_sName = pszName; |
|---|
| 35 | m_pParent = NULL; |
|---|
| 36 | m_iIndex = 0; |
|---|
| 37 | m_Handle = 0; |
|---|
| 38 | m_ParentHandle = 0; |
|---|
| 39 | |
|---|
| 40 | m_bindingPos = Ogre::Vector3::ZERO; |
|---|
| 41 | m_bindingOrientation = Ogre::Quaternion::IDENTITY; |
|---|
| 42 | m_bindingScale = Ogre::Vector3::ZERO; |
|---|
| 43 | |
|---|
| 44 | m_lAnimations.clear(); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | CIntermediateBone::~CIntermediateBone() |
|---|
| 48 | { |
|---|
| 49 | clear(); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | // |
|---|
| 53 | |
|---|
| 54 | void CIntermediateBone::clear() |
|---|
| 55 | { |
|---|
| 56 | m_sName.clear(); |
|---|
| 57 | |
|---|
| 58 | unsigned int iCount = m_Bones.size(); |
|---|
| 59 | for(unsigned int x = 0; x < iCount; x++) |
|---|
| 60 | { |
|---|
| 61 | CIntermediateBone* pBone = m_Bones[x]; |
|---|
| 62 | delete pBone; |
|---|
| 63 | } |
|---|
| 64 | m_Bones.clear(); |
|---|
| 65 | |
|---|
| 66 | std::map< Ogre::String, CAnimationData* >::iterator iter = m_lAnimations.begin(); |
|---|
| 67 | while(iter != m_lAnimations.end()) |
|---|
| 68 | { |
|---|
| 69 | delete (*iter).second; |
|---|
| 70 | iter++; |
|---|
| 71 | } |
|---|
| 72 | m_lAnimations.clear(); |
|---|
| 73 | |
|---|
| 74 | //m_Positions.clear(); |
|---|
| 75 | //m_Orientations.clear(); |
|---|
| 76 | //m_Scales.clear(); |
|---|
| 77 | //m_pParent = NULL; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | // |
|---|
| 81 | |
|---|
| 82 | std::string CIntermediateBone::GetName() const |
|---|
| 83 | { |
|---|
| 84 | return m_sName; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | void CIntermediateBone::SetHandle( ULONG handle ) |
|---|
| 88 | { |
|---|
| 89 | m_Handle = handle; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | ULONG CIntermediateBone::GetHandle( void ) |
|---|
| 93 | { |
|---|
| 94 | return m_Handle; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | void CIntermediateBone::SetParentHandle( ULONG handle ) |
|---|
| 98 | { |
|---|
| 99 | m_ParentHandle = handle; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | ULONG CIntermediateBone::GetParentHandle( void ) |
|---|
| 103 | { |
|---|
| 104 | return m_ParentHandle; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | void CIntermediateBone::SetIndex( unsigned int index ) |
|---|
| 108 | { |
|---|
| 109 | m_iIndex = index; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | unsigned int CIntermediateBone::GetIndex( void ) |
|---|
| 113 | { |
|---|
| 114 | return m_iIndex; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | // |
|---|
| 118 | |
|---|
| 119 | unsigned int CIntermediateBone::GetBoneCount() const |
|---|
| 120 | { |
|---|
| 121 | return m_Bones.size(); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | CIntermediateBone* CIntermediateBone::GetBone(unsigned int iBone) |
|---|
| 125 | { |
|---|
| 126 | return m_Bones[iBone]; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | const CIntermediateBone* CIntermediateBone::GetBone(unsigned int iBone) const |
|---|
| 130 | { |
|---|
| 131 | return m_Bones[iBone]; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | void CIntermediateBone::AddBone(CIntermediateBone* pBone) |
|---|
| 135 | { |
|---|
| 136 | m_Bones.push_back(pBone); |
|---|
| 137 | pBone->SetParent( this ); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | void CIntermediateBone::SetParent( CIntermediateBone* parent ) |
|---|
| 141 | { |
|---|
| 142 | m_pParent = parent; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | CIntermediateBone* CIntermediateBone::GetParent( void ) |
|---|
| 146 | { |
|---|
| 147 | return m_pParent; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | // |
|---|
| 151 | |
|---|
| 152 | unsigned int CIntermediateBone::GetFrameCount( Ogre::String animationName ) const |
|---|
| 153 | { |
|---|
| 154 | std::map< Ogre::String, CAnimationData* >::const_iterator iter = m_lAnimations.find(animationName); |
|---|
| 155 | |
|---|
| 156 | if(iter == m_lAnimations.end()) |
|---|
| 157 | return false; // Animation with that name doesn´t exist |
|---|
| 158 | |
|---|
| 159 | return (*iter).second->GetNrFrames(); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | bool CIntermediateBone::CreateAnimation( const CAnimationSetting animSetting ) |
|---|
| 163 | { |
|---|
| 164 | std::map< Ogre::String, CAnimationData* >::iterator iter = m_lAnimations.find(animSetting.m_sAnimName); |
|---|
| 165 | |
|---|
| 166 | if(iter != m_lAnimations.end()) |
|---|
| 167 | return false; // Animation with that name already exists |
|---|
| 168 | |
|---|
| 169 | CAnimationData* newAnim = new CAnimationData();//animSetting.m_iEndFrame - animSetting.m_iStartFrame); |
|---|
| 170 | newAnim->SetOptimize(animSetting.m_bOptimize); |
|---|
| 171 | |
|---|
| 172 | m_lAnimations.insert( std::pair< Ogre::String, CAnimationData* >(animSetting.m_sAnimName, newAnim) ); |
|---|
| 173 | return true; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | bool CIntermediateBone::GetFrame( Ogre::String animName, unsigned int iFrame, float& fTimeInSecs, Ogre::Vector3& vPos, Ogre::Quaternion& qOri, Ogre::Vector3& vScale) const |
|---|
| 178 | { |
|---|
| 179 | std::map< Ogre::String, CAnimationData* >::const_iterator iter = m_lAnimations.find(animName); |
|---|
| 180 | if(iter == m_lAnimations.end()) |
|---|
| 181 | return false; |
|---|
| 182 | |
|---|
| 183 | //if(iFrame > (*iter).second->GetNrFrames() ) |
|---|
| 184 | // return false; |
|---|
| 185 | |
|---|
| 186 | return (*iter).second->GetFrame(iFrame, fTimeInSecs, vPos, qOri, vScale); |
|---|
| 187 | |
|---|
| 188 | //fTimeInSecs = (*iter).second->m_lTimes[iFrame]; |
|---|
| 189 | //vPos = (*iter).second->m_lPositions[iFrame]; |
|---|
| 190 | //qOri = (*iter).second->m_lOrientations[iFrame]; |
|---|
| 191 | //vScale = (*iter).second->m_lScales[iFrame]; |
|---|
| 192 | //return true; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | bool CIntermediateBone::AddFrame( const std::string animName, unsigned int frameNr, float timeInSecs, const Ogre::Vector3& vPos, const Ogre::Quaternion& qOri, const Ogre::Vector3& vScale) |
|---|
| 196 | { |
|---|
| 197 | std::map< Ogre::String, CAnimationData* >::const_iterator iter = m_lAnimations.find(animName); |
|---|
| 198 | if(iter == m_lAnimations.end()) |
|---|
| 199 | return false; |
|---|
| 200 | |
|---|
| 201 | // add only if it appends |
|---|
| 202 | if(frameNr != (*iter).second->GetNrFrames() ) |
|---|
| 203 | return false; |
|---|
| 204 | |
|---|
| 205 | (*iter).second->AddFrame(timeInSecs,vPos,qOri,vScale); |
|---|
| 206 | |
|---|
| 207 | //(*iter).second->m_lTimes.push_back(timeInSecs); |
|---|
| 208 | //(*iter).second->m_lPositions.push_back(vPos); |
|---|
| 209 | //(*iter).second->m_lOrientations.push_back(qOri); |
|---|
| 210 | //(*iter).second->m_lScales.push_back(vScale); |
|---|
| 211 | |
|---|
| 212 | return true; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | void CIntermediateBone::SetBindingPose(const Ogre::Vector3& vPos, const Ogre::Quaternion& qOri, const Ogre::Vector3& vScale) |
|---|
| 216 | { |
|---|
| 217 | m_bindingPos = vPos; |
|---|
| 218 | m_bindingOrientation = qOri; |
|---|
| 219 | m_bindingScale = vScale; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | void CIntermediateBone::GetBindingPose(Ogre::Vector3& vPos, Ogre::Quaternion& qOri, Ogre::Vector3& vScale) const |
|---|
| 223 | { |
|---|
| 224 | vPos = m_bindingPos; |
|---|
| 225 | qOri = m_bindingOrientation; |
|---|
| 226 | vScale = m_bindingScale; |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | std::map< Ogre::String, CAnimationData* > CIntermediateBone::GetAnimations( void ) |
|---|
| 230 | { |
|---|
| 231 | return m_lAnimations; |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | // |
|---|
| 235 | |
|---|