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

ExCGroupEntity.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 "ExCGroupEntity.h"
00025 
00026 ExCGroupEntity::ExCGroupEntity(void)
00027 {
00028 Guard(ExCGroupEntity::ExCGroupEntity(void))
00029         SetName("ExCGroupEntity");
00030         SetType(typeid(this).name());
00031         m_Visible=true;
00032         m_HasGroupe=false;
00033         m_GroupeName="NONE";
00034 UnGuard
00035 }
00036 
00037 ExCGroupEntity::~ExCGroupEntity(void)
00038 {
00039 Guard(ExCGroupEntity::~ExCGroupEntity(void))
00040 UnGuard
00041 }
00042 
00043 void ExCGroupEntity::Draw(void)
00044 {
00045 Guard(void ExCGroupEntity::Draw(void))
00046         if(!m_Visible)return;
00047         glPushMatrix();
00048         glDisable(GL_LIGHTING);
00049                 glTranslatef(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ());
00050 
00051 
00052                 /*glRotatef(m_Angle.GetX(),1,0,0);
00053                 glRotatef(m_Angle.GetY(),0,1,0);
00054                 glRotatef(m_Angle.GetZ(),0,0,1);
00055 */
00056                 ExQuaternion qRotationY,qRotationX,qRotationZ,qresult;
00057                 float matrix[16];
00058 
00059                 qRotationX.CreateFromAxisAngle(1, 0, 0, m_Angle.GetX());
00060                 qRotationY.CreateFromAxisAngle(0, 1, 0, m_Angle.GetY());
00061                 qRotationZ.CreateFromAxisAngle(0, 0, 1, m_Angle.GetZ());
00062 
00063                 qRotationY.CreateMatrix(matrix);
00064                 glMultMatrixf(matrix);
00065                 qRotationZ.CreateMatrix(matrix);
00066                 glMultMatrixf(matrix);
00067                 qRotationX.CreateMatrix(matrix);
00068                 glMultMatrixf(matrix);
00069 
00070 
00071                 glScalef(m_Scale.GetX(),m_Scale.GetY(),m_Scale.GetZ());
00072                 //std::cout<<"Drw:EntityGroupe:"<<m_VecEntity.size()<<std::endl;
00073                 for( unsigned int i=0;i<m_VecEntity.size();i++)
00074                 {
00075                         m_VecEntity.at(i).Draw();
00076                         //std::cout<<"Drw:"<<m_VecEntity.at(i).GetName()<<std::endl;;
00077                 }
00078         glPopMatrix();
00079 UnGuard
00080 }
00081 
00082 bool ExCGroupEntity::LoadFile(std::string FileName)
00083 {
00084 Guard(bool ExCGroupEntity::LoadFile(std::string FileName))
00085 
00086         //char                  buffer[255];
00087         //sprintf(buffer, "../Data/Animation/%s", FileName.data());
00088         ExCEntity tmpEntity;
00089         std::ifstream fin;
00090         std::string buffstring;
00091         char b[256];
00092         fin.open(FileName.data(),std::ios::in);
00093         if(fin.is_open())
00094         {
00095                 try
00096                 {
00097                         //----Read Type
00098                         memset(b,0,255);fin.getline(b,256,'\n');
00099                         //----Read File property
00100                         memset(b,0,255);fin.getline(b,256,'\n');
00101                         m_FileProperty=ExNihilo::ExtracValueFromSring(b,"<ObjectProperty>","<#ObjectProperty>");
00102                         //----Read File MEsh
00103                         memset(b,0,255);fin.getline(b,256,'\n');
00104                         m_FileMesh=ExNihilo::ExtracValueFromSring(b,"<ObjectGraphic>","<#ObjectGraphic>");
00105                         //----Read File Gizmo
00106                         memset(b,0,255);fin.getline(b,256,'\n');
00107                         m_FileGizmo=ExNihilo::ExtracValueFromSring(b,"<CollisionGizmo>","<#CollisionGizmo>");
00108                         //read property later in other file
00109                         //----Read File Name
00110                         memset(b,0,255);fin.getline(b,256,'\n');
00111                         m_ObjectName=ExNihilo::ExtracValueFromSring(b,"<ObjectName>","<#ObjectName>");
00112                         //---- Read Position
00113                         memset(b,0,255);fin.getline(b,256,'\n');
00114                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Position>","<#Position>");
00115                         m_Position.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00116                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
00117                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
00118                         //---- Read Angle
00119                         memset(b,0,255);fin.getline(b,256,'\n');
00120                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Angle>","<#Angle>");
00121                         m_Angle.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00122                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
00123                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
00124                         //---- Read scale
00125                         memset(b,0,255);fin.getline(b,256,'\n');
00126                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Scale>","<#Scale>");
00127                         m_Scale.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00128                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
00129                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
00130                         //read number entity
00131                         memset(b,0,255);fin.getline(b,256,'\n');
00132                         m_NumberEntity=ExNihilo::ExtractIntValueFromSring(b,"<NumberEntity>","<#NumberEntity>");
00133                         //read entity
00134                         for(int i=0;i<m_NumberEntity;i++)
00135                         {
00136                                 //----Read Type
00137                                 memset(b,0,255);fin.getline(b,256,'\n');
00138                                 //----Read File property
00139                                 memset(b,0,255);fin.getline(b,256,'\n');
00140                                 tmpEntity.m_FileProperty=ExNihilo::ExtracValueFromSring(b,"<ObjectProperty>","<#ObjectProperty>");
00141                                 //----Read File MEsh
00142                                 memset(b,0,255);fin.getline(b,256,'\n');
00143                                 tmpEntity.m_FileMesh=ExNihilo::ExtracValueFromSring(b,"<ObjectGraphic>","<#ObjectGraphic>");
00144                                 //----Read File Gizmo
00145                                 memset(b,0,255);fin.getline(b,256,'\n');
00146                                 tmpEntity.m_FileGizmo=ExNihilo::ExtracValueFromSring(b,"<CollisionGizmo>","<#CollisionGizmo>");
00147                                 //read property later in other file
00148                                 //----Read File Name
00149                                 memset(b,0,255);fin.getline(b,256,'\n');
00150                                 tmpEntity.SetName(ExNihilo::ExtracValueFromSring(b,"<ObjectName>","<#ObjectName>"));
00151                                 //---- Read Position
00152                                 memset(b,0,255);fin.getline(b,256,'\n');
00153                                 buffstring=ExNihilo::ExtracValueFromSring(b,"<Position>","<#Position>");
00154                                 tmpEntity.m_Position.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00155                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
00156                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
00157                                 //---- Read Angle
00158                                 memset(b,0,255);fin.getline(b,256,'\n');
00159                                 buffstring=ExNihilo::ExtracValueFromSring(b,"<Angle>","<#Angle>");
00160                                 tmpEntity.m_Angle.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00161                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
00162                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
00163                                 //---- Read scale
00164                                 memset(b,0,255);fin.getline(b,256,'\n');
00165                                 buffstring=ExNihilo::ExtracValueFromSring(b,"<Scale>","<#Scale>");
00166                                 tmpEntity.m_Scale.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00167                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
00168                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
00169                                 //Find manager where is the object and get pointer to object
00170                                 try
00171                                 {
00172                                         tmpEntity.SetManagerGizmo(ManagerGizmo);
00173                                         tmpEntity.SetManagerMesh(ManagerMesh);
00174                                         tmpEntity.SetManagerModel(ManagerModel);
00175                                         tmpEntity.SetManagerId(ManagerId);
00176                                         std::cout<<tmpEntity.m_FileMesh<<std::endl;
00177                                         if(strcmpi(ExNihilo::GetFileExtension(tmpEntity.m_FileMesh).data(),"exme")==0)
00178                                         {
00179                                                 tmpEntity.m_ManagerType="ExManagerMesh";
00180                                                 tmpEntity.m_MeshId=ManagerMesh->Load(tmpEntity.m_FileMesh);
00181                                                 ManagerMesh->GetObject(tmpEntity.m_MeshId)->m_Visible=false;
00182                                                 return true;
00183                                         }
00184                                         if(strcmpi(ExNihilo::GetFileExtension(tmpEntity.m_FileMesh).data(),"3ds")==0)
00185                                         {
00186                                                 tmpEntity.m_ManagerType="ExManagerModel";
00187                                                 tmpEntity.m_MeshId=ManagerModel->Load(tmpEntity.m_FileMesh);
00188                                                 ManagerModel->GetObject(tmpEntity.m_MeshId)->m_Visible=false;
00189                                                 
00190                                         }
00191                                 }catch (...)
00192                                 {
00193                                         std::cout<<"Wrong Graphic object chek name or object type in your graphic file"<<std::endl;
00194                                         
00195                                 }
00196                                 m_VecEntity.push_back(tmpEntity);
00197                         }
00198                         
00199                         fin.close();
00200                 }
00201                 catch(ExCExpStringNotFound)
00202                 {
00203                         std::cout<<"ExCExpStringNotFound"<<std::endl;
00204                 }
00205                 catch(...)
00206                 {
00207                         std::cout<<"ExCExpFileReadError"<<std::endl;
00208                         throw ExCExpFileReadError();
00209                 }
00210         }else throw   ExCExpFileNotFound();
00211         return true;
00212 UnGuard
00213 }

Généré le Tue Oct 28 12:43:30 2003 pour ExNihilo par doxygen 1.3.4