1 #include "mof/DataBasedAnimation.h"
2 #include "mof/KeyFrameAnimation.h"
3 #include "mof/CSVFile.h"
4 #include <boost/lexical_cast.hpp>
7 mof::DataBasedAnimation::DataBasedAnimation(const TCHAR * const pPath , mof::Vector3D& denormalizeScale , bool isLooping )
8 : mof::Animation(isLooping) , m_denormalizeScale(denormalizeScale){
9 m_pBody = new KeyFrameAnimation(isLooping);
10 m_pFile = new CSVFile(pPath);
11 m_pFile->setIgnoreNL(false);
12 m_pFile->nextLine();//1
\8ds
\96Ú
\82Í
\97ñ
\92è
\8b`
\82È
\82Ì
\82Å
\8eÌ
\82Ä
\82é
17 mof::DataBasedAnimation::DataBasedAnimation(const TCHAR * const pPath , bool isLooping )
18 : mof::Animation(isLooping) , m_denormalizeScale(1 , 1 , 1){
19 m_pBody = new KeyFrameAnimation(isLooping);
20 m_pFile = new CSVFile(pPath);
21 m_pFile->setIgnoreNL(false);
22 m_pFile->nextLine();//1
\8ds
\96Ú
\82Í
\97ñ
\92è
\8b`
\82È
\82Ì
\82Å
\8eÌ
\82Ä
\82é
27 void mof::DataBasedAnimation::loadNextKeyFrame(){
28 if(!m_pFile->hasNextValue())return;
31 int keyFrame = boost::lexical_cast<int>(m_pFile->getNextValue());
35 if(!m_pFile->hasNextValue())goto END;
36 mof::tstring buf1 = m_pFile->getNextValue();
37 if(!m_pFile->hasNextValue())goto END;
38 mof::tstring buf2 = m_pFile->getNextValue();
39 if(buf1 != _T("") && buf2 != _T("")){
41 if(m_pFile->hasNextValue())buf3 = m_pFile->getNextValue();
43 //z
\8dÀ
\95W
\82à
\97L
\8cø
\82È
\8fê
\8d\87\82Í
\82R
\8e\9f\8c³
\8dÀ
\95W
\82Æ
\82µ
\82Ä
\88µ
\82¤
45 boost::lexical_cast<float>(buf1) , boost::lexical_cast<float>(buf2) , boost::lexical_cast<float>(buf3));
46 pos.x = pos.x * m_denormalizeScale.x;
47 pos.y = pos.y * m_denormalizeScale.y;
48 pos.z = pos.z * m_denormalizeScale.z;
49 m_pBody->setPosition(keyFrame , pos);
51 else m_pBody->setPosition(keyFrame , mof::Vector2D(boost::lexical_cast<int>(buf1) , boost::lexical_cast<int>(buf2)));
53 else if(m_pFile->hasNextValue())m_pFile->getNextValue();//PositionZ
\82ð
\8eÌ
\82Ä
\82é
58 if(!m_pFile->hasNextValue())goto END;
59 mof::tstring buf1 = m_pFile->getNextValue();
61 m_pBody->setColor(keyFrame , mof::createColor(buf1));
67 if(!m_pFile->hasNextValue())goto END;
68 mof::tstring tux = m_pFile->getNextValue();
69 if(!m_pFile->hasNextValue())goto END;
70 mof::tstring tuy = m_pFile->getNextValue();
71 if(!m_pFile->hasNextValue())goto END;
72 mof::tstring tvx = m_pFile->getNextValue();
73 if(!m_pFile->hasNextValue())goto END;
74 mof::tstring tvy = m_pFile->getNextValue();
75 if(tux != _T("") && tuy != _T("") && tvx != _T("") && tvy != _T("")){
76 m_pBody->setTextureRectangle(keyFrame , mof::Line2D(
77 boost::lexical_cast<int>(tux) , boost::lexical_cast<int>(tuy) ,
78 boost::lexical_cast<int>(tvx) , boost::lexical_cast<int>(tvy)));
84 if(!m_pFile->hasNextValue())goto END;
85 mof::tstring buf1 = m_pFile->getNextValue();
86 if(!m_pFile->hasNextValue())goto END;
87 mof::tstring buf2 = m_pFile->getNextValue();
88 if(buf1 != _T("") && buf2 != _T("")){
90 if(m_pFile->hasNextValue())buf3 = m_pFile->getNextValue();
92 //
\89\9c\8ds
\82«
\82à
\97L
\8cø
\82È
\8fê
\8d\87\82Í
\82R
\8e\9f\8c³
\8dÀ
\95W
\82Æ
\82µ
\82Ä
\88µ
\82¤
93 m_pBody->setScale(keyFrame , mof::Vector3D(
94 boost::lexical_cast<float>(buf1) , boost::lexical_cast<float>(buf2) , boost::lexical_cast<float>(buf3)));
97 //ToDo
\82Q
\8e\9f\8c³
\82Ì
\83X
\83P
\81[
\83\8b
98 //m_pBody->set(keyFrame , mof::Vector2D(boost::lexical_cast<int>(buf1) , boost::lexical_cast<int>(buf2)));
101 else if(m_pFile->hasNextValue())m_pFile->getNextValue();//Depth
\82ð
\8eÌ
\82Ä
\82é
106 if(!m_pFile->hasNextValue())goto END;
107 mof::tstring buf1 = m_pFile->getNextValue();
108 if(!m_pFile->hasNextValue())goto END;
109 mof::tstring buf2 = m_pFile->getNextValue();
110 if(buf1 != _T("") && buf2 != _T("")){
112 if(m_pFile->hasNextValue())buf3 = m_pFile->getNextValue();
114 //Z
\8e²
\92\86\90S
\82à
\97L
\8cø
\82È
\8fê
\8d\87\82Í
\82R
\8e\9f\8c³
\8dÀ
\95W
\82Æ
\82µ
\82Ä
\88µ
\82¤
115 m_pBody->setRotation(keyFrame , mof::Vector3D(
116 boost::lexical_cast<float>(buf1) , boost::lexical_cast<float>(buf2) , boost::lexical_cast<float>(buf3)));
119 //ToDo
\82Q
\8e\9f\8c³
\82Ì
\89ñ
\93]
120 //m_pBody->set(keyFrame , mof::Vector2D(boost::lexical_cast<int>(buf1) , boost::lexical_cast<int>(buf2)));
123 else if(m_pFile->hasNextValue())m_pFile->getNextValue();//RotZ
\82ð
\8eÌ
\82Ä
\82é
127 //finalize
\83V
\83O
\83i
\83\8b
129 if(!m_pFile->hasNextValue())goto END;
130 mof::tstring buf1 = m_pFile->getNextValue();
132 m_pBody->setFinalKey(boost::lexical_cast<int>(buf1));
142 mof::DataBasedAnimation::~DataBasedAnimation(void){
148 bool mof::DataBasedAnimation::update(){
149 if(!isPlaying())return false;
157 bool mof::DataBasedAnimation::isFinalized(){
158 return m_pBody->isFinalized();
162 mof::Vector2D mof::DataBasedAnimation::getPosition(){
163 return m_pBody->getPosition();
167 float mof::DataBasedAnimation::getWidth(){
168 return m_pBody->getWidth();
172 float mof::DataBasedAnimation::getHeight(){
173 return m_pBody->getHeight();
177 float mof::DataBasedAnimation::getDepth(){
178 return m_pBody->getDepth();
181 mof::Color mof::DataBasedAnimation::getColor(){
182 return m_pBody->getColor();
186 mof::Matrix3D mof::DataBasedAnimation::getWorldTransform(mof::Matrix3D& matrix){
187 return m_pBody->getWorldTransform(matrix);
191 mof::Line2D mof::DataBasedAnimation::getTextureRectangle(){
192 return m_pBody->getTextureRectangle();