OSDN Git Service

fix cmake/Macros.cmake
[moflib/moflib.git] / moflib-1.0 / moflib / moflib / mof / stream / DataBasedAnimation.cpp
1 #include "mof/DataBasedAnimation.h"
2 #include "mof/KeyFrameAnimation.h"
3 #include "mof/CSVFile.h"
4 #include <boost/lexical_cast.hpp>
5
6
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é
13         loadNextKeyFrame();
14         
15 }
16
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é
23         loadNextKeyFrame();
24         
25 }
26
27 void mof::DataBasedAnimation::loadNextKeyFrame(){
28         if(!m_pFile->hasNextValue())return;
29         
30         //KeyFrame
31         int keyFrame = boost::lexical_cast<int>(m_pFile->getNextValue());
32
33         //Position
34         {
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("")){
40                         mof::tstring buf3;
41                         if(m_pFile->hasNextValue())buf3 = m_pFile->getNextValue();
42                         if(buf3 != _T("")){
43                                 //z\8dÀ\95W\82à\97L\8cø\82È\8fê\8d\87\82Í\82R\8e\9f\8c³\8dÀ\95W\82Æ\82µ\82Ä\88µ\82¤
44                                 mof::Vector3D pos(
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);
50                         }
51                         else m_pBody->setPosition(keyFrame , mof::Vector2D(boost::lexical_cast<int>(buf1) , boost::lexical_cast<int>(buf2)));
52                 }
53                 else if(m_pFile->hasNextValue())m_pFile->getNextValue();//PositionZ\82ð\8eÌ\82Ä\82é
54         }
55
56         //Color
57         {
58                 if(!m_pFile->hasNextValue())goto END;
59                 mof::tstring buf1 = m_pFile->getNextValue();
60                 if(buf1 != _T("")){
61                         m_pBody->setColor(keyFrame , mof::createColor(buf1));
62                 }
63         }
64
65         //Texture
66         {
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)));
79                 }
80         }
81
82         //Scale
83         {
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("")){
89                         mof::tstring buf3;
90                         if(m_pFile->hasNextValue())buf3 = m_pFile->getNextValue();
91                         if(buf3 != _T("")){
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)));
95                         }
96                         else {
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)));
99                         }
100                 }
101                 else if(m_pFile->hasNextValue())m_pFile->getNextValue();//Depth\82ð\8eÌ\82Ä\82é
102         }
103
104         //Rotate
105         {
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("")){
111                         mof::tstring buf3;
112                         if(m_pFile->hasNextValue())buf3 = m_pFile->getNextValue();
113                         if(buf3 != _T("")){
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)));
117                         }
118                         else {
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)));
121                         }
122                 }
123                 else if(m_pFile->hasNextValue())m_pFile->getNextValue();//RotZ\82ð\8eÌ\82Ä\82é
124         }
125
126
127         //finalize\83V\83O\83i\83\8b
128         {
129                 if(!m_pFile->hasNextValue())goto END;
130                 mof::tstring buf1 = m_pFile->getNextValue();
131                 if(buf1 != _T("")){
132                         m_pBody->setFinalKey(boost::lexical_cast<int>(buf1));
133                 }
134         }
135
136
137 END:
138         m_pFile->nextLine();
139 }
140
141
142 mof::DataBasedAnimation::~DataBasedAnimation(void){
143         delete m_pBody;
144         delete m_pFile;
145 }
146
147
148 bool mof::DataBasedAnimation::update(){
149         if(!isPlaying())return false;
150         m_pBody->update();
151
152         loadNextKeyFrame();
153         return false;
154 }
155
156
157 bool mof::DataBasedAnimation::isFinalized(){
158         return m_pBody->isFinalized();
159 }
160
161
162 mof::Vector2D mof::DataBasedAnimation::getPosition(){
163         return m_pBody->getPosition();
164 }
165
166         
167 float mof::DataBasedAnimation::getWidth(){
168         return m_pBody->getWidth();
169 }
170
171
172 float mof::DataBasedAnimation::getHeight(){
173         return m_pBody->getHeight();
174 }
175
176
177 float mof::DataBasedAnimation::getDepth(){
178         return m_pBody->getDepth();
179 }
180
181 mof::Color mof::DataBasedAnimation::getColor(){
182         return m_pBody->getColor();
183 }
184
185                 
186 mof::Matrix3D mof::DataBasedAnimation::getWorldTransform(mof::Matrix3D& matrix){
187         return m_pBody->getWorldTransform(matrix);
188 }
189
190                 
191 mof::Line2D mof::DataBasedAnimation::getTextureRectangle(){
192         return m_pBody->getTextureRectangle();
193 }