Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/Tools/3dsmaxExport/LEXIExporter/LexiExport/Sources/LexiIntermediateBone.cpp @ 11

Last change on this file since 11 was 6, checked in by anonymous, 18 years ago

=…

File size: 5.7 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of LEXIExporter
4
5Copyright 2006 NDS Limited
6
7Author(s):
8Mark Folkenberg,
9Bo Krohn
10
11This program is free software; you can redistribute it and/or modify it under
12the terms of the GNU Lesser General Public License as published by the Free Software
13Foundation; either version 2 of the License, or (at your option) any later
14version.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
19
20You should have received a copy of the GNU Lesser General Public License along with
21this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22Place - Suite 330, Boston, MA 02111-1307, USA, or go to
23http://www.gnu.org/copyleft/lesser.txt.
24-----------------------------------------------------------------------------
25*/
26
27#include "LexiStdAfx.h"
28#include "LexiIntermediateAPI.h"
29
30//
31
32CIntermediateBone::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
47CIntermediateBone::~CIntermediateBone()
48{
49        clear();
50}
51
52//
53
54void 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
82std::string CIntermediateBone::GetName() const
83{
84        return m_sName;
85}
86
87void CIntermediateBone::SetHandle( ULONG handle )
88{
89        m_Handle = handle;
90}
91
92ULONG CIntermediateBone::GetHandle( void )
93{
94        return m_Handle;
95}
96
97void CIntermediateBone::SetParentHandle( ULONG handle )
98{
99        m_ParentHandle = handle;
100}
101
102ULONG CIntermediateBone::GetParentHandle( void )
103{
104        return m_ParentHandle;
105}
106
107void CIntermediateBone::SetIndex( unsigned int index )
108{
109        m_iIndex = index;
110}
111
112unsigned int CIntermediateBone::GetIndex( void )
113{
114        return m_iIndex;
115}
116
117//
118
119unsigned int CIntermediateBone::GetBoneCount() const
120{
121        return m_Bones.size();
122}
123
124CIntermediateBone* CIntermediateBone::GetBone(unsigned int iBone)
125{
126        return m_Bones[iBone];
127}
128
129const CIntermediateBone* CIntermediateBone::GetBone(unsigned int iBone) const
130{
131        return m_Bones[iBone];
132}
133
134void CIntermediateBone::AddBone(CIntermediateBone* pBone)
135{
136        m_Bones.push_back(pBone);
137        pBone->SetParent( this );
138}
139
140void CIntermediateBone::SetParent( CIntermediateBone* parent )
141{
142        m_pParent = parent;
143}
144
145CIntermediateBone* CIntermediateBone::GetParent( void )
146{
147        return m_pParent;
148}
149
150//
151
152unsigned 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
162bool 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
177bool 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
195bool 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
215void 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
222void 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
229std::map< Ogre::String, CAnimationData* > CIntermediateBone::GetAnimations( void )
230{
231        return m_lAnimations;
232}
233
234//
235
Note: See TracBrowser for help on using the repository browser.