Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Membres des namespaces | Composants | Déclarations

# ExCMesh3ds.cpp

Aller à la documentation de ce fichier.

    00001 /*
    00002  * ExNihilo 3D Engine
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  *
    00018  * Please read AUTHORS file !!!
    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         //copy data
    00052         for(unsigned int i=0;i<Current3ds->m_VecObject->size();i++)
    00053         {
    00054                 t3DObject Tmpt3dobj;
    00055                 //get object data
    00056                 Tmpt3dobj=Current3ds->m_VecObject->at(i);
    00057                 //std::cout<<"copy object:"<<Current3ds->m_VecObject->at(i).Material<<std::endl;
    00058                 //std::cout<<"test copy object:"<<Tmpt3dobj.Material<<std::endl;
    00059                 //modify objet data
    00060
    00061                 for(unsigned int j;j<Tmpt3dobj.Verts.size();j++)
    00062                 {
    00063                         Tmpt3dobj.Verts.at(j)=Current3ds->m_VecObject->at(i).Verts.at(j)+
    00064                                 ((Next3DS->m_VecObject->at(i).Verts.at(j)-Current3ds->m_VecObject->at(i).Verts.at(j))
    00065                                 /m_InterpolationPourcentage)*m_CurrentInterpolation;
    00066
    00067                         //std::cout<<"object copy"<<Tmpt3dobj.Verts.at(j)<<std::endl;
    00068                         //std::cout<<"object original"<<Current3ds->m_VecObject->at(i).Verts.at(j)<<std::endl;
    00069                         //std::cout<<"----------------------------------------------"<<std::endl;
    00070                 }
    00071
    00072                 Render3DS->m_VecObject->push_back(Tmpt3dobj);           //push the new object data
    00073         }
    00074         m_CurrentInterpolation++;
    00075
    00076
    00077         Render3DS->Draw();
    00078 */
    00079         /*std::cout<<"vec obj size:"<<Render3DS->m_VecObject->size()<<std::endl;
    00080
    00081         for(unsigned int i=0;i<Render3DS->m_VecObject->size();i++)
    00082         {
    00083                 std::cout<<"vec vertex size:"<<Render3DS->m_VecObject->at(i).Verts.size()<<std::endl;
    00084                 for(unsigned int j;j<Render3DS->m_VecObject->at(i).Verts.size();j++)
    00085                 {
    00086                         std::cout<<Render3DS->m_VecObject->at(i).Verts.at(j)<<std::endl;
    00087                 }
    00088         }*/
    00089
    00090
    00091         //Render3DS->m_VecObject.at();
    00092         //Current3ds->m_VecObject.at();
    00093
    00094 //              Render3DS->BuildList(RENDER_TEXTURES);
    00095 //              Render3DS->Draw();
    00096
    00097 /*      ManagerModel->GetObject(Render3DS->GetId())->m_Visible=true;
    00098         ManagerModel->GetObject(Render3DS->GetId())->Draw();
    00099         ManagerModel->GetObject(Render3DS->GetId())->m_Visible=false;
    00100 */
    00101         if(m_HasInterpolation)
    00102         {
    00103                 //Creat 3 pointer
    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                 //init new object
    00115                 Render3DS       = new ExCModel3DS;
    00116         Render3DS->m_VecObject=new std::vector<t3DObject>;
    00117                 Render3DS->SetManagerTexture(ManagerTexture);
    00118
    00119                 //copy all data
    00120                 for(unsigned int i=0;i<Current3ds->m_VecObject->size();i++)
    00121                 {
    00122                         t3DObject Tmpt3dobj;
    00123                         Tmpt3dobj=Current3ds->m_VecObject->at(i);
    00124                         //std::cout<<"copy object:"<<Current3ds->m_VecObject->at(i).Material<<std::endl;
    00125                         //std::cout<<"test copy object:"<<Tmpt3dobj.Material<<std::endl;
    00126                         //modify objet data
    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                                 //std::cout<<"object copy"<<Tmpt3dobj.Verts.at(j)<<std::endl;
    00134                                 //std::cout<<"object original"<<Current3ds->m_VecObject->at(i).Verts.at(j)<<std::endl;
    00135                                 //std::cout<<"----------------------------------------------"<<std::endl;
    00136                         }
    00137
    00138                         Render3DS->m_VecObject->push_back(Tmpt3dobj);           //push the new object data
    00139                 }
    00140                 m_CurrentInterpolation++;
    00141
    00142                 //draw the object
    00143                 Render3DS->m_Visible=true;
    00144                 Render3DS->HasList=false;
    00145                 Render3DS->Draw();
    00146                 //free memory
    00147                 //delete Render3DS;
    00148                 //delete Render3DS->m_VecObject;
    00149
    00150
    00151         }else
    00152         {
    00154                 //To draw witout interpolation
    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)//jump next frame
    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                 //----Read type
    00193                 memset(b,0,255);fin.getline(b,256,'\n');
    00194                 //----Read has interpol
    00195                 memset(b,0,255);fin.getline(b,256,'\n');
    00196                 m_HasInterpolation=(bool)ExNihilo::ExtractIntValueFromSring(b,"<HasInterpolation>","<#HasInterpolation>");
    00197                 //----Read numer of key
    00198                 memset(b,0,255);fin.getline(b,256,'\n');
    00199                 m_NumberKeyFrame=ExNihilo::ExtractFloatValueFromSring(b,"<NumberKeyFrame>","<#NumberKeyFrame>");
    00200                         //----Read all frame
    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