00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ExCMesh3ds.h"
00025
00026 ExCMesh3ds::ExCMesh3ds()
00027 {
00028 Guard(ExCMesh3ds::ExCMesh3ds())
00029 SetName("ExCMesh3ds");
00030 SetType(typeid(this).name());
00031 m_CurrentAnimation=0;
00032 m_TimeForNextFrame=100;
00033 m_InterpolationPourcentage=10;
00034 m_CurrentInterpolation=0;
00035 m_HasInterpolation=false;
00036 UnGuard
00037 }
00038
00039 ExCMesh3ds::~ExCMesh3ds()
00040 {
00041 Guard(ExCMesh3ds::~ExCMesh3ds())
00042 UnGuard
00043 }
00044
00045
00046 void ExCMesh3ds::Draw(void)
00047 {
00048 Guard(void ExCMesh3ds::Draw(void))
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 if(m_HasInterpolation)
00102 {
00103
00104 ExCModel3DS *Current3ds,*Next3DS,*Render3DS;
00105 Current3ds =(ExCModel3DS *) ManagerModel->GetObject(m_VecObjectIDKey.at(m_CurrentAnimation).first);
00106 if(m_CurrentAnimation>=m_NumberKeyFrame-1)
00107 {
00108 Next3DS =(ExCModel3DS *) ManagerModel->GetObject(m_VecObjectIDKey.at(0).first);
00109 }else
00110 {
00111 Next3DS =(ExCModel3DS *) ManagerModel->GetObject(m_VecObjectIDKey.at(m_CurrentAnimation+1).first);
00112 }
00113
00114
00115 Render3DS = new ExCModel3DS;
00116 Render3DS->m_VecObject=new std::vector<t3DObject>;
00117 Render3DS->SetManagerTexture(ManagerTexture);
00118
00119
00120 for(unsigned int i=0;i<Current3ds->m_VecObject->size();i++)
00121 {
00122 t3DObject Tmpt3dobj;
00123 Tmpt3dobj=Current3ds->m_VecObject->at(i);
00124
00125
00126
00127 for(unsigned int j;j<Tmpt3dobj.Verts.size();j++)
00128 {
00129 Tmpt3dobj.Verts.at(j)=Current3ds->m_VecObject->at(i).Verts.at(j)+
00130 ((Next3DS->m_VecObject->at(i).Verts.at(j)-Current3ds->m_VecObject->at(i).Verts.at(j))
00131 /m_InterpolationPourcentage)*m_CurrentInterpolation;
00132
00133
00134
00135
00136 }
00137
00138 Render3DS->m_VecObject->push_back(Tmpt3dobj);
00139 }
00140 m_CurrentInterpolation++;
00141
00142
00143 Render3DS->m_Visible=true;
00144 Render3DS->HasList=false;
00145 Render3DS->Draw();
00146
00147
00148
00149
00150
00151 }else
00152 {
00154
00155
00156 ManagerModel->GetObject(m_VecObjectIDKey.at(m_CurrentAnimation).first)->m_Visible=true;
00157 ManagerModel->GetObject(m_VecObjectIDKey.at(m_CurrentAnimation).first)->Draw();
00158 ManagerModel->GetObject(m_VecObjectIDKey.at(m_CurrentAnimation).first)->m_Visible=false;
00159 }
00160
00161 double currenttime=glutGet(GLUT_ELAPSED_TIME);
00162 if(currenttime>m_TimeLastKeyFrame+m_TimeForNextFrame)
00163 {
00164 m_TimeLastKeyFrame=currenttime;
00165 m_CurrentAnimation++;
00166 m_CurrentInterpolation=0;
00167 }
00168
00169 if(m_CurrentAnimation>=m_NumberKeyFrame)m_CurrentAnimation=0;
00170 UnGuard
00171 }
00172
00173 bool ExCMesh3ds::Load(std::string FileName)
00174 {
00175 Guard(bool ExCMesh3ds::Load(std::string FileName))
00176 m_CurrentAnimation=0;
00177 char buffer[255];
00178 #ifdef UNIX_SRC
00179 sprintf(buffer, PREFIX "/ExNihilo/Data/Mesh/%s", FileName.data());
00180 #else
00181 sprintf(buffer, "../Data/Mesh/%s", FileName.data());
00182 #endif
00183 std::ifstream fin;
00184 std::string buffstring;
00185 char b[256];
00186 std::pair<ExNihilo::ExId , int> PEX;
00187 fin.open(buffer,std::ios::in);
00188 if(fin.is_open())
00189 {
00190 try
00191 {
00192
00193 memset(b,0,255);fin.getline(b,256,'\n');
00194
00195 memset(b,0,255);fin.getline(b,256,'\n');
00196 m_HasInterpolation=(bool)ExNihilo::ExtractIntValueFromSring(b,"<HasInterpolation>","<#HasInterpolation>");
00197
00198 memset(b,0,255);fin.getline(b,256,'\n');
00199 m_NumberKeyFrame=ExNihilo::ExtractFloatValueFromSring(b,"<NumberKeyFrame>","<#NumberKeyFrame>");
00200
00201 for(int i=0;i<m_NumberKeyFrame;i++)
00202 {
00203 memset(b,0,255);
00204 fin.getline(b,256,'\n');
00205 try
00206 {
00207 buffstring=ExNihilo::ExtracValueFromSring(b,"<KeyFrameFile>","<#KeyFrameFile>");
00208 PEX.first=ManagerModel->Load(buffstring) ;
00209 PEX.second=i;
00210 ManagerModel->GetObject(PEX.first)->m_Visible=false;
00211 m_VecObjectIDKey.push_back(PEX);
00212 }catch(ExCExpStringNotFound){}
00213 }
00214 fin.close();
00215 }catch(...){throw ExCExpFileReadError();}
00216 }else throw ExCExpFileNotFound();
00217 return true;
00218 UnGuard
00219 }
00220