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

# ExCSkyBox.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 "ExCSkyBox.h"
    00025
    00026 ExCSkyBox::ExCSkyBox(void)
    00027 {
    00028                 m_Size=1000;
    00029
    00030 }
    00031
    00032 ExCSkyBox::~ExCSkyBox(void)
    00033 {
    00034 }
    00035
    00036 void ExCSkyBox::BuildBox(void)
    00037 {
    00038 Guard(void ExCSkyBox::BuildBox(void))
    00039         m_TabVertices= new float[72];
    00040         m_TabTextures= new float[48];
    00041
    00042
    00043         // Front Face
    00044         int i=0,j=0;
    00045         m_TabVertices[i+0]=-1;m_TabVertices[i+1]= 1;m_TabVertices[i+2]= 1;
    00046         m_TabVertices[i+3]= 1;m_TabVertices[i+4]= 1;m_TabVertices[i+5]= 1;
    00047         m_TabVertices[i+6]= 1;m_TabVertices[i+7]=-1;m_TabVertices[i+8]= 1;
    00048         m_TabVertices[i+9]=-1;m_TabVertices[i+10]=-1;m_TabVertices[i+11]= 1;
    00049
    00050         m_TabTextures[j+0]=1.0f;m_TabTextures[j+1]=1.0f;
    00051         m_TabTextures[j+2]=0.0f;m_TabTextures[j+3]=1.0f;
    00052         m_TabTextures[j+4]=0.0f;m_TabTextures[j+5]=0.0f;
    00053         m_TabTextures[j+6]=1.0f;m_TabTextures[j+7]=0.0f;
    00054
    00055         // Back Face
    00056         i=12,j=8;
    00057         m_TabVertices[i+0]= 1;m_TabVertices[i+1]=-1;m_TabVertices[i+2]= -1;
    00058         m_TabVertices[i+3]= 1;m_TabVertices[i+4]= 1;m_TabVertices[i+5]= -1;
    00059         m_TabVertices[i+6]=-1;m_TabVertices[i+7]= 1;m_TabVertices[i+8]= -1;
    00060         m_TabVertices[i+9]=-1;m_TabVertices[i+10]=-1;m_TabVertices[i+11]= -1;
    00061
    00062         m_TabTextures[j+0]=1.0f;m_TabTextures[j+1]=0.0f;
    00063         m_TabTextures[j+2]=1.0f;m_TabTextures[j+3]=1.0f;
    00064         m_TabTextures[j+4]=0.0f;m_TabTextures[j+5]=1.0f;
    00065         m_TabTextures[j+6]=0.0f;m_TabTextures[j+7]=0.0f;
    00066         // Top Face
    00067         i=24,j=16;
    00068         m_TabVertices[i+0]= 1;m_TabVertices[i+1]= 1;m_TabVertices[i+2]= -1;
    00069         m_TabVertices[i+3]= 1;m_TabVertices[i+4]= 1;m_TabVertices[i+5]= 1;
    00070         m_TabVertices[i+6]=-1;m_TabVertices[i+7]= 1;m_TabVertices[i+8]= 1;
    00071         m_TabVertices[i+9]=-1;m_TabVertices[i+10]= 1;m_TabVertices[i+11]= -1;
    00072
    00073         m_TabTextures[j+0]=1.0f;m_TabTextures[j+1]=0.0f;
    00074         m_TabTextures[j+2]=1.0f;m_TabTextures[j+3]=1.0f;
    00075         m_TabTextures[j+4]=0.0f;m_TabTextures[j+5]=1.0f;
    00076         m_TabTextures[j+6]=0.0f;m_TabTextures[j+7]=0.0f;
    00077         // Bottom Face
    00078         i=36,j=24;
    00079         m_TabVertices[i+0]=-1;m_TabVertices[i+1]=-1;m_TabVertices[i+2]= 1;
    00080         m_TabVertices[i+3]= 1;m_TabVertices[i+4]=-1;m_TabVertices[i+5]= 1;
    00081         m_TabVertices[i+6]= 1;m_TabVertices[i+7]=-1;m_TabVertices[i+8]= -1;
    00082         m_TabVertices[i+9]=-1;m_TabVertices[i+10]=-1;m_TabVertices[i+11]= -1;
    00083
    00084         m_TabTextures[j+0]=0.0f;m_TabTextures[j+1]=0.0f;
    00085         m_TabTextures[j+2]=1.0f;m_TabTextures[j+3]=0.0f;
    00086         m_TabTextures[j+4]=1.0f;m_TabTextures[j+5]=1.0f;
    00087         m_TabTextures[j+6]=0.0f;m_TabTextures[j+7]=1.0f;
    00088         // Right face
    00089         i=48,j=32;
    00090         m_TabVertices[i+0]= 1;m_TabVertices[i+1]=-1;m_TabVertices[i+2]= 1;
    00091         m_TabVertices[i+3]= 1;m_TabVertices[i+4]= 1;m_TabVertices[i+5]= 1;
    00092         m_TabVertices[i+6]= 1;m_TabVertices[i+7]= 1;m_TabVertices[i+8]= -1;
    00093         m_TabVertices[i+9]= 1;m_TabVertices[i+10]=-1;m_TabVertices[i+11]= -1;
    00094
    00095         m_TabTextures[j+0]=1.0f;m_TabTextures[j+1]=0.0f;
    00096         m_TabTextures[j+2]=1.0f;m_TabTextures[j+3]=1.0f;
    00097         m_TabTextures[j+4]=0.0f;m_TabTextures[j+5]=1.0f;
    00098         m_TabTextures[j+6]=0.0f;m_TabTextures[j+7]=0.0f;
    00099         // Left Face
    00100         i=60,j=40;
    00101         m_TabVertices[i+0]=-1;m_TabVertices[i+1]= 1;m_TabVertices[i+2]= -1;
    00102         m_TabVertices[i+3]=-1;m_TabVertices[i+4]= 1;m_TabVertices[i+5]= 1;
    00103         m_TabVertices[i+6]=-1;m_TabVertices[i+7]=-1;m_TabVertices[i+8]= 1;
    00104         m_TabVertices[i+9]=-1;m_TabVertices[i+10]=-1;m_TabVertices[i+11]= -1;
    00105
    00106         m_TabTextures[j+0]=1.0f;m_TabTextures[j+1]=1.0f;
    00107         m_TabTextures[j+2]=0.0f;m_TabTextures[j+3]=1.0f;
    00108         m_TabTextures[j+4]=0.0f;m_TabTextures[j+5]=0.0f;
    00109         m_TabTextures[j+6]=1.0f;m_TabTextures[j+7]=0.0f;
    00110 UnGuard
    00111 }
    00112
    00113 void ExCSkyBox::Load(std::string FileName)
    00114 {
    00115 Guard(void ExCSkyBox::Load(std::string FileName))
    00116         BuildBox();
    00117         char                    buffer[255],b[255];
    00118         std::string buffstring;
    00119         std::ifstream file;
    00120
    00121         #ifdef UNIX_SRC
    00122         sprintf(buffer, PREFIX "/ExNihilo/Data/Map/%s", FileName.data());
    00123         #else
    00124         sprintf(buffer, "../Data/Map/%s", FileName.data());
    00125         #endif
    00126         file.open(buffer,std::ios::in);
    00127         if(file.is_open())
    00128         {
    00129
    00130                 try
    00131                 {
    00132
    00133                         memset(b,0,255);file.getline(b,256,'\n');//pass comment line
    00134                         memset(b,0,255);file.getline(b,256,'\n');
    00135                         m_SkyBox.m_Size=ExNihilo::ExtractFloatValueFromSring(b,"<Size>","<#Size>");
    00136                         for(int j=0;j<4;j++)
    00137                         {
    00138                                 memset(b,0,255);file.getline(b,256,'\n');//pass comment line
    00139                                 memset(b,0,255);file.getline(b,256,'\n');
    00140                                 m_SkyBox.m_Texture[j][SKY_TOP]=ExNihilo::ExtracValueFromSring(b,"<Texture_top>","<#Texture_top>");
    00141                                 ManagerTexture->SetCurrentObject(m_SkyBox.m_Texture[j][SKY_TOP]);
    00142                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    00143                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    00144                                 memset(b,0,255);file.getline(b,256,'\n');
    00145                                 m_SkyBox.m_Texture[j][SKY_BOTTOM]=ExNihilo::ExtracValueFromSring(b,"<Texture_bottom>","<#Texture_bottom>");
    00146                                 ManagerTexture->SetCurrentObject(m_SkyBox.m_Texture[j][SKY_BOTTOM]);
    00147                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    00148                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    00149                                 memset(b,0,255);file.getline(b,256,'\n');
    00150                                 m_SkyBox.m_Texture[j][SKY_FRONT]=ExNihilo::ExtracValueFromSring(b,"<Texture_front>","<#Texture_front>");
    00151                                 ManagerTexture->SetCurrentObject(m_SkyBox.m_Texture[j][SKY_FRONT]);
    00152                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    00153                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    00154                                 memset(b,0,255);file.getline(b,256,'\n');
    00155                                 m_SkyBox.m_Texture[j][SKY_BACK]=ExNihilo::ExtracValueFromSring(b,"<Texture_back>","<#Texture_back>");
    00156                                 ManagerTexture->SetCurrentObject(m_SkyBox.m_Texture[j][SKY_BACK]);
    00157                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    00158                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    00159                                 memset(b,0,255);file.getline(b,256,'\n');
    00160                                 m_SkyBox.m_Texture[j][SKY_LEFT]=ExNihilo::ExtracValueFromSring(b,"<Texture_left>","<#Texture_left>");
    00161                                 ManagerTexture->SetCurrentObject(m_SkyBox.m_Texture[j][SKY_LEFT]);
    00162                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    00163                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    00164                                 memset(b,0,255);file.getline(b,256,'\n');
    00165                                 m_SkyBox.m_Texture[j][SKY_RIGHT]=ExNihilo::ExtracValueFromSring(b,"<Texture_right>","<#Texture_right>");
    00166                                 ManagerTexture->SetCurrentObject(m_SkyBox.m_Texture[j][SKY_RIGHT]);
    00167                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    00168                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    00169
    00170                         }
    00171
    00172                 }catch(ExCExpStringNotFound){std::cout<<"Bad file type "<<buffer<<std::endl;}
    00173         }else
    00174         {
    00175                 std::cout<<"File not found:"<<buffer<<std::endl;
    00176                 throw   ExCExpFileNotFound();
    00177         }
    00178
    00179 UnGuard
    00180 }
    00181
    00182
    00183 void ExCSkyBox::Draw(void)
    00184 {
    00185 Guard(void ExCSkyBox::Draw(void))
    00186         glPushAttrib(GL_ALL_ATTRIB_BITS);
    00187         glEnable(GL_TEXTURE_2D);
    00188         glDisable(GL_LIGHTING);
    00189                 glColor3f(1.0f,1.0f,1.0f);
    00190                 glPushMatrix();
    00191                         glTranslatef(0,4000,0);
    00192                         glScalef(m_SkyBox.m_Size,m_SkyBox.m_Size,m_SkyBox.m_Size);
    00193                         for(int i=0;i<6;i++)
    00194                         {
    00195                                 ManagerTexture->SetTexture(3,m_SkyBox.m_Texture[3][i]);
    00196                                 glTexCoordPointer(2,GL_FLOAT,0,m_TabTextures);
    00197                                 ManagerTexture->SetTexture(2,m_SkyBox.m_Texture[2][i]);
    00198                                 glTexCoordPointer(2,GL_FLOAT,0,m_TabTextures);
    00199                                 ManagerTexture->SetTexture(1,m_SkyBox.m_Texture[1][i]);
    00200                                 glTexCoordPointer(2,GL_FLOAT,0,m_TabTextures);
    00201                                 ManagerTexture->SetTexture(0,m_SkyBox.m_Texture[0][i]);
    00202                                 glTexCoordPointer(2,GL_FLOAT,0,m_TabTextures);
    00203                                 glVertexPointer(3,GL_FLOAT,0,m_TabVertices);
    00204                                 glDrawArrays( GL_QUADS, 0+(i*4), 4 );
    00205                                 ManagerTexture->ResetMultitexture();
    00206                         }
    00207                 glPopMatrix();
    00208         glPopAttrib();
    00209 UnGuard
    00210 }
    00211
    00212
    00213