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

# ExCEntity.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 "ExCEntity.h"
    00025
    00026 ExCEntity::ExCEntity(void)
    00027 {
    00028 Guard(ExCEntity::ExCEntity(void))
    00029         SetName("ExCEntity");
    00030         SetType(typeid(this).name());
    00031         m_Visible=true;
    00032 UnGuard
    00033 }
    00034
    00035 ExCEntity::~ExCEntity(void)
    00036 {
    00037 Guard(ExCEntity::~ExCEntity(void))
    00038 UnGuard
    00039 }
    00040
    00041 void ExCEntity::Draw(void)
    00042 {
    00043 Guard(void ExCEntity::Draw(void))
    00044         if(!m_Visible)return;
    00045         glPushMatrix();
    00046         glDisable(GL_LIGHTING);
    00047                 glTranslatef(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ());
    00048
    00049
    00050                 /*glRotatef(m_Angle.GetX(),1,0,0);
    00051                 glRotatef(m_Angle.GetY(),0,1,0);
    00052                 glRotatef(m_Angle.GetZ(),0,0,1);
    00053 */
    00054                 ExQuaternion qRotationY,qRotationX,qRotationZ,qresult;
    00055                 float matrix[16];
    00056
    00057                 qRotationX.CreateFromAxisAngle(1, 0, 0, m_Angle.GetX());
    00058                 qRotationY.CreateFromAxisAngle(0, 1, 0, m_Angle.GetY());
    00059                 qRotationZ.CreateFromAxisAngle(0, 0, 1, m_Angle.GetZ());
    00060
    00061                 qRotationY.CreateMatrix(matrix);
    00062                 glMultMatrixf(matrix);
    00063                 qRotationZ.CreateMatrix(matrix);
    00064                 glMultMatrixf(matrix);
    00065                 qRotationX.CreateMatrix(matrix);
    00066                 glMultMatrixf(matrix);
    00067
    00068
    00069                 glScalef(m_Scale.GetX(),m_Scale.GetY(),m_Scale.GetZ());
    00070                 if(strcmpi("ExManagerModel",m_ManagerType.data())==0)
    00071                 {
    00072                         ManagerModel->GetObject(m_MeshId)->m_Visible=true;
    00073                         ManagerModel->GetObject(m_MeshId)->Draw();
    00074                         ManagerModel->GetObject(m_MeshId)->m_Visible=false;
    00075                 }
    00076                 if(strcmpi("ExManagerMesh",m_ManagerType.data())==0)
    00077                 {
    00078                         ManagerMesh->GetObject(m_MeshId)->m_Visible=true;
    00079                         ManagerMesh->GetObject(m_MeshId)->Draw();
    00080                         ManagerMesh->GetObject(m_MeshId)->m_Visible=false;
    00081                 }
    00082
    00083
    00084         glPopMatrix();
    00085 UnGuard
    00086 }
    00087
    00088 bool ExCEntity::LoadFile(std::string FileName)
    00089 {
    00090 Guard(bool ExCEntity::LoadFile(std::string FileName))
    00091
    00092         //char                  buffer[255];
    00093         //sprintf(buffer, "../Data/Animation/%s", FileName.data());
    00094         std::ifstream fin;
    00095         std::string buffstring;
    00096         char b[256];
    00097         fin.open(FileName.data(),std::ios::in);
    00098         if(fin.is_open())
    00099         {
    00100                 try
    00101                 {
    00102                         //----Read Type
    00103                         memset(b,0,255);fin.getline(b,256,'\n');
    00104                         //----Read File property
    00105                         memset(b,0,255);fin.getline(b,256,'\n');
    00106                         m_FileProperty=ExNihilo::ExtracValueFromSring(b,"<ObjectProperty>","<#ObjectProperty>");
    00107                         //----Read File MEsh
    00108                         memset(b,0,255);fin.getline(b,256,'\n');
    00109                         m_FileMesh=ExNihilo::ExtracValueFromSring(b,"<ObjectGraphic>","<#ObjectGraphic>");
    00110                         //----Read File Gizmo
    00111                         memset(b,0,255);fin.getline(b,256,'\n');
    00112                         m_FileGizmo=ExNihilo::ExtracValueFromSring(b,"<CollisionGizmo>","<#CollisionGizmo>");
    00113                         //read property later in other file
    00114                         //----Read File Name
    00115                         memset(b,0,255);fin.getline(b,256,'\n');
    00116                         m_ObjectName=ExNihilo::ExtracValueFromSring(b,"<ObjectName>","<#ObjectName>");
    00117                         //---- Read Position
    00118                         memset(b,0,255);fin.getline(b,256,'\n');
    00119                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Position>","<#Position>");
    00120                         m_Position.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00121                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00122                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00123                         //---- Read Angle
    00124                         memset(b,0,255);fin.getline(b,256,'\n');
    00125                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Angle>","<#Angle>");
    00126                         m_Angle.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00127                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00128                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00129                         //---- Read scale
    00130                         memset(b,0,255);fin.getline(b,256,'\n');
    00131                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Scale>","<#Scale>");
    00132                         m_Scale.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00133                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00134                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00135                         fin.close();
    00136                 }
    00137                 catch(ExCExpStringNotFound)
    00138                 {
    00139                         std::cout<<"ExCExpStringNotFound"<<std::endl;
    00140                 }
    00141                 catch(...)
    00142                 {
    00143                         std::cout<<"ExCExpFileReadError"<<std::endl;
    00144                         throw ExCExpFileReadError();
    00145                 }
    00146         }else throw   ExCExpFileNotFound();
    00147
    00148         //Find manager where is the object and get pointer to object
    00149         try
    00150         {
    00151
    00152                 if(strcmpi(ExNihilo::GetFileExtension(m_FileMesh).data(),"exme")==0)
    00153                 {
    00154                         m_ManagerType="ExManagerMesh";
    00155                         m_MeshId=ManagerMesh->Load(m_FileMesh);
    00156                         ManagerMesh->GetObject(m_MeshId)->m_Visible=false;
    00157                         return true;
    00158                 }
    00159                 if(strcmpi(ExNihilo::GetFileExtension(m_FileMesh).data(),"3ds")==0)
    00160                 {
    00161                         m_ManagerType="ExManagerModel";
    00162                         m_MeshId=ManagerModel->Load(m_FileMesh);
    00163                         ManagerModel->GetObject(m_MeshId)->m_Visible=false;
    00164                         return true;
    00165                 }
    00166                 if(strcmpi(ExNihilo::GetFileExtension(m_FileMesh).data(),"md2")==0)
    00167                 {
    00168                         m_ManagerType="ExManagerModel";
    00169                         m_MeshId=ManagerModel->Load(m_FileMesh);
    00170                         ManagerModel->GetObject(m_MeshId)->m_Visible=false;
    00171                         return true;
    00172                 }
    00173         }catch (...)
    00174         {
    00175                 std::cout<<"Wrong Graphic object chek name or object type in your graphic file"<<std::endl;
    00176                 return false;
    00177         }
    00178         return false;
    00179
    00180         //read 3ds
    00181
    00182         //read gizmo
    00183
    00184         return true;
    00185 UnGuard
    00186 }
    00187
    00188 bool ExCEntity::LoadFile(std::ifstream *fin)
    00189 {
    00190 Guard(bool ExCEntity::LoadFile(std::ifstream *fin))
    00191         std::string buffstring;
    00192         char b[256];
    00193 //      fin.open(FileName.data(),std::ios::in);
    00194         if(fin->is_open())
    00195         {
    00196                 try
    00197                 {
    00198                         //----Read Type
    00199                         memset(b,0,255);fin->getline(b,256,'\n');
    00200                         //----Read File property
    00201                         memset(b,0,255);fin->getline(b,256,'\n');
    00202                         m_FileProperty=ExNihilo::ExtracValueFromSring(b,"<ObjectProperty>","<#ObjectProperty>");
    00203                         //----Read File MEsh
    00204                         memset(b,0,255);fin->getline(b,256,'\n');
    00205                         m_FileMesh=ExNihilo::ExtracValueFromSring(b,"<ObjectGraphic>","<#ObjectGraphic>");
    00206                         //----Read File Gizmo
    00207                         memset(b,0,255);fin->getline(b,256,'\n');
    00208                         m_FileGizmo=ExNihilo::ExtracValueFromSring(b,"<CollisionGizmo>","<#CollisionGizmo>");
    00209                         //read property later in other file
    00210                         //----Read File Name
    00211                         memset(b,0,255);fin->getline(b,256,'\n');
    00212                         m_ObjectName=ExNihilo::ExtracValueFromSring(b,"<ObjectName>","<#ObjectName>");
    00213                         //---- Read Position
    00214                         memset(b,0,255);fin->getline(b,256,'\n');
    00215                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Position>","<#Position>");
    00216                         m_Position.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00217                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00218                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00219                         //---- Read Angle
    00220                         memset(b,0,255);fin->getline(b,256,'\n');
    00221                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Angle>","<#Angle>");
    00222                         m_Angle.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00223                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00224                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00225                         //---- Read scale
    00226                         memset(b,0,255);fin->getline(b,256,'\n');
    00227                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Scale>","<#Scale>");
    00228                         m_Scale.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00229                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00230                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00231
    00232                 }
    00233                 catch(ExCExpStringNotFound)
    00234                 {
    00235                         std::cout<<"ExCExpStringNotFound"<<std::endl;
    00236                 }
    00237                 catch(...)
    00238                 {
    00239                         std::cout<<"ExCExpFileReadError"<<std::endl;
    00240                         throw ExCExpFileReadError();
    00241                 }
    00242         }else throw   ExCExpFileNotFound();
    00243
    00244         //Find manager where is the object and get pointer to object
    00245         try
    00246         {
    00247
    00248                 if(strcmpi(ExNihilo::GetFileExtension(m_FileMesh).data(),"exme")==0)
    00249                 {
    00250                         m_ManagerType="ExManagerMesh";
    00251                         m_MeshId=ManagerMesh->Load(m_FileMesh);
    00252                         ManagerMesh->GetObject(m_MeshId)->m_Visible=false;
    00253                         return true;
    00254                 }
    00255                 if(strcmpi(ExNihilo::GetFileExtension(m_FileMesh).data(),"3ds")==0)
    00256                 {
    00257                         m_ManagerType="ExManagerModel";
    00258                         m_MeshId=ManagerModel->Load(m_FileMesh);
    00259                         ManagerModel->GetObject(m_MeshId)->m_Visible=false;
    00260                         return true;
    00261                 }
    00262                 if(strcmpi(ExNihilo::GetFileExtension(m_FileMesh).data(),"md2")==0)
    00263                 {
    00264                         m_ManagerType="ExManagerModel";
    00265                         m_MeshId=ManagerModel->Load(m_FileMesh);
    00266                         ManagerModel->GetObject(m_MeshId)->m_Visible=false;
    00267                         return true;
    00268                 }
    00269         }catch (...)
    00270         {
    00271                 std::cout<<"Wrong Graphic object chek name or object type in your graphic file"<<std::endl;
    00272                 return false;
    00273         }
    00274         return false;
    00275
    00276         //read 3ds
    00277
    00278         //read gizmo
    00279
    00280         return true;
    00281         UnGuard
    00282 }