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 "ExCComposed.h"
00025
00026 ExCComposed::ExCComposed(void)
00027 {
00028 m_RenderMode=RENDER_LINES;
00029 }
00030
00031 ExCComposed::~ExCComposed(void)
00032 {
00033 }
00034
00035 void ExCComposed::MakeList(void)
00036 {
00037 Guard(void ExCComposed::MakeList(void))
00038
00039 m_GlListId=glGenLists(1);
00040 glNewList(m_GlListId,GL_COMPILE);
00041 for(m_ItVecEntite=m_VecEntite.begin();m_ItVecEntite!=m_VecEntite.end();m_ItVecEntite++)
00042 {
00043 m_ItVecEntite->DrawWithoutList();
00044
00045 }
00046 glEndList();
00047 UnGuard
00048 }
00049
00050 void ExCComposed::SetRenderMode(int RenderMode)
00051 {
00052 Guard(void ExCComposed::SetRenderMode(int RenderMode))
00053 for(m_ItVecEntite=m_VecEntite.begin();m_ItVecEntite!=m_VecEntite.end();m_ItVecEntite++)
00054 {
00055 m_ItVecEntite->SetRenderMode(RenderMode);
00056 glDeleteLists(m_ItVecEntite->GetGlListId(),1);
00057 }
00058 MakeList();
00059 UnGuard
00060 }
00061
00062 void ExCComposed::BuildPvsBox(void)
00063 {
00064 for(m_ItVecEntite=m_VecEntite.begin();m_ItVecEntite!=m_VecEntite.end();m_ItVecEntite++)
00065 {
00066 m_ItVecEntite->BuildPvsBox();
00067 }
00068 }
00069
00070 void ExCComposed::SetManagerTexture(ExManagerTexture * Texture)
00071 {
00072 ManagerTexture=Texture;
00073 for(m_ItVecEntite=m_VecEntite.begin();m_ItVecEntite!=m_VecEntite.end();m_ItVecEntite++)
00074 {
00075 m_ItVecEntite->SetManagerTexture(Texture);
00076 }
00077 }
00078
00079 void ExCComposed::Draw(void)
00080 {
00081 double tmplife;
00082 ExCVec3D ForceResult;
00083 ExCMatrix4x4 Matr;
00084 ExQuaternion quat;
00085
00086
00087
00088
00089
00090
00091 tmplife=(double)((double)glutGet(GLUT_ELAPSED_TIME)/1000)-m_StartingLife;
00092 if(tmplife-m_Life>=m_RefreshTime)
00093 {
00094
00095 if(m_Acceleration!=0.0f)
00096 {
00097 if(m_Velocity.m_Vector[0]!=0.0f)
00098 {
00099 m_Velocity.m_Vector[0]=m_Velocity.m_Vector[0]+((double)m_Acceleration*((double)(tmplife-m_Life)/1000));
00100 }
00101 if(m_Velocity.m_Vector[1]!=0.0f)
00102 {
00103 m_Velocity.m_Vector[1]=m_Velocity.m_Vector[1]+((double)m_Acceleration*((double)(tmplife-m_Life)/1000));
00104 }
00105 if(m_Velocity.m_Vector[2]!=0.0f)
00106 {
00107 m_Velocity.m_Vector[2]=m_Velocity.m_Vector[2]+((double)m_Acceleration*((double)(tmplife-m_Life)/1000));
00108 }
00109 }
00110
00111 quat=GetQuaternionFromEuler(m_AngleX,m_AngleY,m_AngleZ);
00112
00113 Matr=GetMatrixFromEuler(m_AngleX,m_AngleY,m_AngleZ);
00114
00115 ForceResult.m_Vector[0]= (Matr.m_Matrix[0]*m_Velocity.m_Vector[0])+
00116 (Matr.m_Matrix[4]*m_Velocity.m_Vector[1])+
00117 (Matr.m_Matrix[8]*m_Velocity.m_Vector[2])+
00118 (Matr.m_Matrix[12]*0.0f);
00119
00120
00121 ForceResult.m_Vector[1]= (Matr.m_Matrix[1]*m_Velocity.m_Vector[0])+
00122 (Matr.m_Matrix[5]*m_Velocity.m_Vector[1])+
00123 (Matr.m_Matrix[9]*m_Velocity.m_Vector[2])+
00124 (Matr.m_Matrix[13]*0.0f);
00125
00126 ForceResult.m_Vector[2]= (Matr.m_Matrix[2]*m_Velocity.m_Vector[0])+
00127 (Matr.m_Matrix[6]*m_Velocity.m_Vector[1])+
00128 (Matr.m_Matrix[10]*m_Velocity.m_Vector[2])+
00129 (Matr.m_Matrix[14]*0.0f);
00130
00131
00132
00133
00134
00135 m_Position=m_Position+m_Velocity-m_Gravity+ForceResult;
00136
00137
00138 m_Life=(double)((double)glutGet(GLUT_ELAPSED_TIME)/1000)-m_StartingLife;
00139 }
00140
00141
00142 glPushMatrix();
00143 glTranslatef(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ());
00144 glRotatef(m_AngleX,1.0f,0.0f,0.0f);
00145 glRotatef(m_AngleY,0.0f,1.0f,0.0f);
00146 glRotatef(-90,0.0f,0.0f,1.0f);
00147 glRotatef(m_AngleZ,0.0f,0.0f,1.0f);
00148
00149 glCallList(m_GlListId);
00150 if(m_ShowInfo && m_CurrentObject)ShowInfo();
00151 glPopMatrix();
00152
00153 }
00154
00155 bool ExCComposed::LoadAsc(char *FileName)
00156 {
00157 Guard(void LoadAsc(char *FileName))
00158 bool endfile=false;
00159 int FileSize;
00160 int RetVal;
00161 int TmpFilePosition;
00162 int i,j,k;
00163 FILE *MyFile;
00164 std::cout<<"Load File :"<<FileName;
00165 MyFile=fopen (FileName,"r");
00166 if(!MyFile)
00167 {
00168 return false;
00169 }
00170 fseek(MyFile,0,SEEK_END);
00171 FileSize=ftell(MyFile);
00172 std::cout<<" Size:"<<FileSize<<std::endl;
00173
00174 fseek(MyFile,0,SEEK_SET);
00175 do
00176 {
00177 bool Textured=false;
00178 ExCEntite EntiteBuff;
00179 const char *Name;
00180 char ch;
00181 std::string SName;
00182 std::string SNumber;
00183 ExCVertex VertexBuff;
00184
00185
00186
00187 do
00188 {
00189 RetVal=fread(&ch,sizeof(char),1,MyFile);
00190 }while(ch!=34);
00191 TmpFilePosition=ftell(MyFile);
00192 i=0;
00193 do
00194 {
00195 RetVal=fread(&ch,sizeof(char),1,MyFile);i++;
00196 }while(ch!=34);
00197 fseek(MyFile,TmpFilePosition,SEEK_SET);
00198 for(j=0;j<i-1;j++)
00199 {
00200 RetVal=fread(&ch,sizeof(char),1,MyFile);
00201 SName=SName+ch;
00202 }
00203 Name = SName.data();
00204 EntiteBuff.SetName(Name);
00205 std::cout<<"Name :"<<EntiteBuff.GetName()<<std::endl;
00206
00207
00208
00209 do
00210 {
00211 RetVal=fread(&ch,sizeof(char),1,MyFile);
00212 }while(ch!=':');
00213 RetVal=fread(&ch,sizeof(char),1,MyFile);
00214 do
00215 {
00216 RetVal=fread(&ch,sizeof(char),1,MyFile);
00217 SNumber=SNumber+ch;
00218 }while(ch!=' ');
00219 EntiteBuff.SetNumberVertex(atol(SNumber.data()));
00220
00221 SNumber.erase(SNumber.begin(),SNumber.end());
00222 do
00223 {
00224 RetVal=fread(&ch,sizeof(char),1,MyFile);
00225 }while(ch!=':');
00226 RetVal=fread(&ch,sizeof(char),1,MyFile);
00227 do
00228 {
00229 RetVal=fread(&ch,sizeof(char),1,MyFile);
00230 SNumber=SNumber+ch;
00231 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00232 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00233 EntiteBuff.SetNumberMesh(atol(SNumber.data()));
00234 std::cout<<"Number of Vertex :"<<EntiteBuff.GetNumberVertex()<<" Number of Mesh :"<<EntiteBuff.GetNumberMesh()<<std::endl;
00235
00236
00237
00238 for(j=0;j<EntiteBuff.GetNumberVertex();j++)
00239 {
00240 SNumber.erase(SNumber.begin(),SNumber.end());
00241 do
00242 {
00243 RetVal=fread(&ch,sizeof(char),1,MyFile);
00244 }while(ch!='X');
00245 RetVal=fread(&ch,sizeof(char),1,MyFile);
00246 do
00247 {
00248 RetVal=fread(&ch,sizeof(char),1,MyFile);
00249 SNumber=SNumber+ch;
00250 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00251 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00252 try
00253 {
00254 VertexBuff.SetX(atof(SNumber.data()));
00255 }catch(...)
00256 {
00257 VertexBuff.SetV(0.0f);
00258 std::cout<<"Error on vertex V:"<<j<<std::endl;
00259 }
00260
00261 SNumber.erase(SNumber.begin(),SNumber.end());
00262 do
00263 {
00264 RetVal=fread(&ch,sizeof(char),1,MyFile);
00265 }while(ch!='Y');
00266 RetVal=fread(&ch,sizeof(char),1,MyFile);
00267 do
00268 {
00269 RetVal=fread(&ch,sizeof(char),1,MyFile);
00270 SNumber=SNumber+ch;
00271 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00272 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00273 try
00274 {
00275 VertexBuff.SetY(atof(SNumber.data()));
00276 }catch(...)
00277 {
00278 VertexBuff.SetV(0.0f);
00279 std::cout<<"Error on vertex V:"<<j<<std::endl;
00280 }
00281
00282 SNumber.erase(SNumber.begin(),SNumber.end());
00283 do
00284 {
00285 RetVal=fread(&ch,sizeof(char),1,MyFile);
00286 }while(ch!='Z');
00287 RetVal=fread(&ch,sizeof(char),1,MyFile);
00288 do
00289 {
00290 RetVal=fread(&ch,sizeof(char),1,MyFile);
00291 SNumber=SNumber+ch;
00292 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00293 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00294 try
00295 {
00296 VertexBuff.SetZ(atof(SNumber.data()));
00297 }catch(...)
00298 {
00299 VertexBuff.SetV(0.0f);
00300 std::cout<<"Error on vertex V:"<<j<<std::endl;
00301 }
00302
00303
00304 RetVal=fread(&ch,sizeof(char),1,MyFile);
00305 if(ch==' ')
00306 {
00307 Textured=true;
00308
00309 SNumber.erase(SNumber.begin(),SNumber.end());
00310 do
00311 {
00312 RetVal=fread(&ch,sizeof(char),1,MyFile);
00313 }while(ch!='U');
00314 RetVal=fread(&ch,sizeof(char),1,MyFile);
00315 do
00316 {
00317 RetVal=fread(&ch,sizeof(char),1,MyFile);
00318 SNumber=SNumber+ch;
00319 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00320 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00321 VertexBuff.SetU(atof(SNumber.data()));
00322
00323 SNumber.erase(SNumber.begin(),SNumber.end());
00324 do
00325 {
00326 RetVal=fread(&ch,sizeof(char),1,MyFile);
00327 }while(ch!='V');
00328 RetVal=fread(&ch,sizeof(char),1,MyFile);
00329 do
00330 {
00331 RetVal=fread(&ch,sizeof(char),1,MyFile);
00332 SNumber=SNumber+ch;
00333 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00334 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00335 VertexBuff.SetV(atof(SNumber.data()));
00336
00337 }
00338
00339 EntiteBuff.AddVertex(VertexBuff);
00340
00341 }
00342
00343
00344
00345 for(j=0;j<EntiteBuff.GetNumberMesh();j++)
00346 {
00347 ExCMesh MeshBuff;
00348 MeshBuff.m_MeshNumber=j;
00349 SNumber.erase(SNumber.begin(),SNumber.end());
00350 do
00351 {
00352 RetVal=fread(&ch,sizeof(char),1,MyFile);
00353 }while(ch!='A');
00354 RetVal=fread(&ch,sizeof(char),1,MyFile);
00355
00356 do
00357 {
00358 RetVal=fread(&ch,sizeof(char),1,MyFile);
00359 SNumber=SNumber+ch;
00360 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00361 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00362 MeshBuff.A=EntiteBuff.GetVertex(atoi(SNumber.data()));
00363
00364
00365 SNumber.erase(SNumber.begin(),SNumber.end());
00366 do
00367 {
00368 RetVal=fread(&ch,sizeof(char),1,MyFile);
00369 }while(ch!='B');
00370 RetVal=fread(&ch,sizeof(char),1,MyFile);
00371 do
00372 {
00373 RetVal=fread(&ch,sizeof(char),1,MyFile);
00374 SNumber=SNumber+ch;
00375 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00376 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00377 MeshBuff.B=EntiteBuff.GetVertex(atoi(SNumber.data()));
00378
00379 SNumber.erase(SNumber.begin(),SNumber.end());
00380 do
00381 {
00382 RetVal=fread(&ch,sizeof(char),1,MyFile);
00383 }while(ch!='C');
00384 RetVal=fread(&ch,sizeof(char),1,MyFile);
00385 do
00386 {
00387 RetVal=fread(&ch,sizeof(char),1,MyFile);
00388 SNumber=SNumber+ch;
00389 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00390 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00391 MeshBuff.C=EntiteBuff.GetVertex(atoi(SNumber.data()));
00392
00393 do
00394 {
00395 RetVal=fread(&ch,sizeof(char),1,MyFile);
00396 }while(ch!='B');
00397 RetVal=fread(&ch,sizeof(char),1,MyFile);
00398 SNumber.erase(SNumber.begin(),SNumber.end());
00399 do
00400 {
00401 RetVal=fread(&ch,sizeof(char),1,MyFile);
00402 SNumber=SNumber+ch;
00403 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00404 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00405 MeshBuff.m_AB=atoi(SNumber.data());
00406 do
00407 {
00408 RetVal=fread(&ch,sizeof(char),1,MyFile);
00409 }while(ch!='C');
00410 RetVal=fread(&ch,sizeof(char),1,MyFile);
00411 SNumber.erase(SNumber.begin(),SNumber.end());
00412 do
00413 {
00414 RetVal=fread(&ch,sizeof(char),1,MyFile);
00415 SNumber=SNumber+ch;
00416 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00417 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00418 MeshBuff.m_BC=atoi(SNumber.data());
00419 do
00420 {
00421 RetVal=fread(&ch,sizeof(char),1,MyFile);
00422 }while(ch!='A');
00423 RetVal=fread(&ch,sizeof(char),1,MyFile);
00424 SNumber.erase(SNumber.begin(),SNumber.end());
00425 do
00426 {
00427 RetVal=fread(&ch,sizeof(char),1,MyFile);
00428 SNumber=SNumber+ch;
00429 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00430 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00431 MeshBuff.m_CA=atoi(SNumber.data());
00432 if(Textured)
00433 {
00434
00435
00436
00437 std::string Material;
00438 do
00439 {
00440 RetVal=fread(&ch,sizeof(char),1,MyFile);
00441 }while(ch!=34);
00442 TmpFilePosition=ftell(MyFile);
00443 i=0;
00444 do
00445 {
00446 RetVal=fread(&ch,sizeof(char),1,MyFile);i++;
00447 }while(ch!=34);
00448 fseek(MyFile,TmpFilePosition,SEEK_SET);
00449 for(k=0;k<i-1;k++)
00450 {
00451 RetVal=fread(&ch,sizeof(char),1,MyFile);
00452 Material=Material+ch;
00453 }
00454 MeshBuff.SetMaterial(Material.data());
00455 ManagerTexture->Add(Material);
00456 }
00457
00458
00459
00460 do
00461 {
00462 RetVal=fread(&ch,sizeof(char),1,MyFile);
00463 }while(ch!=':');
00464 RetVal=fread(&ch,sizeof(char),1,MyFile);
00465 SNumber.erase(SNumber.begin(),SNumber.end());
00466 do
00467 {
00468 RetVal=fread(&ch,sizeof(char),1,MyFile);
00469 SNumber=SNumber+ch;
00470 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00471 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00472 MeshBuff.m_Smoothing=atoi(SNumber.data());
00473
00474 EntiteBuff.AddMesh(MeshBuff);
00475 }
00476
00477 m_VecEntite.push_back(EntiteBuff);
00478
00479 TmpFilePosition=ftell(MyFile);
00480 std::cout<<TmpFilePosition<<std::endl;
00481 if(TmpFilePosition+100>FileSize)
00482 {
00483 endfile=true;
00484 }else
00485 {
00486 endfile=false;
00487 }
00488 }while(!endfile);
00489
00490
00491 fclose(MyFile);
00492 BuildPvsBox();
00493 return true;
00494 UnGuard
00495 }