Wall.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <client/ScorchedClient.h>
00022 #include <landscapemap/LandscapeMaps.h>
00023 #include <landscape/Wall.h>
00024 #include <sound/SoundUtils.h>
00025 #include <image/ImageFactory.h>
00026 #include <common/Defines.h>
00027 
00028 Wall::Wall() : createdTexture_(false)
00029 {
00030         for (int i=0; i<4; i++) fadeTime_[i] = 0.0f;
00031 }
00032 
00033 Wall::~Wall()
00034 {
00035 }
00036 
00037 void Wall::draw()
00038 {
00039         if (!createdTexture_)
00040         {
00041                 createdTexture_ = true;
00042                 std::string file1 = S3D::getDataFile("data/textures/bordershield/grid.bmp");
00043                 std::string file2 = S3D::getDataFile("data/textures/bordershield/grid.bmp");
00044                 ImageHandle map = ImageFactory::loadImageHandle(file1.c_str(), file2.c_str(), false);
00045                 texture_.create(map, true);
00046         }
00047 
00048         float arenaX = (float) ScorchedClient::instance()->getLandscapeMaps().
00049                         getGroundMaps().getArenaX();
00050         float arenaY = (float) ScorchedClient::instance()->getLandscapeMaps().
00051                         getGroundMaps().getArenaY();
00052         float arenaWidth = (float) ScorchedClient::instance()->getLandscapeMaps().
00053                         getGroundMaps().getArenaWidth();
00054         float arenaHeight = (float) ScorchedClient::instance()->getLandscapeMaps().
00055                         getGroundMaps().getArenaHeight();
00056 
00057         Vector botA(arenaX, arenaY, 0.0f);
00058         Vector botB(arenaX + arenaWidth, arenaY, 0.0f);
00059         Vector botC(arenaX + arenaWidth, arenaY + arenaHeight, 0.0f);
00060         Vector botD(arenaX, arenaY + arenaHeight, 0.0f);
00061         Vector topA(arenaX, arenaY, 256.0f);
00062         Vector topB(arenaX + arenaWidth, arenaY, 256.0f);
00063         Vector topC(arenaX + arenaWidth, arenaY + arenaHeight, 256.0f);
00064         Vector topD(arenaX, arenaY + arenaHeight, 256.0f);
00065 
00066         if (fadeTime_[OptionsTransient::LeftSide] > 0.0f ||
00067                 fadeTime_[OptionsTransient::BotSide] > 0.0f ||
00068                 fadeTime_[OptionsTransient::RightSide] > 0.0f ||
00069                 fadeTime_[OptionsTransient::TopSide] > 0.0f)
00070         {
00071                 GLState currentState(GLState::BLEND_ON | GLState::TEXTURE_ON);
00072 
00073                 texture_.draw();
00074                 drawWall(botA, botB, topB, topA, fadeTime_[OptionsTransient::TopSide]);
00075                 drawWall(botB, botC, topC, topB, fadeTime_[OptionsTransient::RightSide]);
00076                 drawWall(botC, botD, topD, topC, fadeTime_[OptionsTransient::BotSide]);
00077                 drawWall(botD, botA, topA, topD, fadeTime_[OptionsTransient::LeftSide]);
00078         }
00079 }
00080 
00081 void Wall::drawWall(Vector &cornerA, Vector &cornerB, 
00082                                                  Vector &cornerC, Vector &cornerD,
00083                                                  float fade)
00084 {
00085         if (fade <= 0.0f) return;
00086 
00087         int rot = 0;//int(fade * 75) % 2;
00088         float pos = float(int(fade * 75) % 2) * 5.0f;
00089 
00090         Vector &wallColor = ScorchedClient::instance()->getOptionsTransient().getWallColor();
00091         glColor4f(wallColor[0], wallColor[1], wallColor[2], fade);
00092         glBegin(GL_QUADS);
00093                 // Don't draw the wall if we are behind it
00094                 // as its z-ordering obscures other objects
00095                 /*switch(rot)
00096                 {
00097                 case 0: glTexCoord2f(20.0f + pos, 20.0f + pos); break;
00098                 case 1: glTexCoord2f(0.0f + pos, 20.0f + pos); break;
00099                 }
00100                 glVertex3fv(cornerA);
00101                 switch(rot)
00102                 {
00103                 case 0: glTexCoord2f(0.0f + pos, 20.0f + pos); break;
00104                 case 1: glTexCoord2f(0.0f + pos, 0.0f + pos); break;
00105                 }               
00106                 glVertex3fv(cornerB);
00107                 switch(rot)
00108                 {
00109                 case 0: glTexCoord2f(0.0f, 0.0f); break;
00110                 case 1: glTexCoord2f(20.0f, 0.0f); break;
00111                 }       
00112                 glVertex3fv(cornerC);
00113                 switch(rot)
00114                 {
00115                 case 0: glTexCoord2f(20.0f, 0.0f); break;
00116                 case 1: glTexCoord2f(20.0f, 20.0f); break;
00117                 }       
00118                 glVertex3fv(cornerD);*/
00119 
00120                 switch(rot)
00121                 {
00122                 case 0: glTexCoord2f(20.0f + pos, 0.0f + pos); break;
00123                 case 1: glTexCoord2f(20.0f + pos, 20.0f + pos); break;
00124                 }       
00125                 glVertex3fv(cornerD);
00126                 switch(rot)
00127                 {
00128                 case 0: glTexCoord2f(0.0f + pos, 0.0f + pos); break;
00129                 case 1: glTexCoord2f(20.0f + pos, 0.0f + pos); break;
00130                 }       
00131                 glVertex3fv(cornerC);
00132                 switch(rot)
00133                 {
00134                 case 0: glTexCoord2f(0.0f, 20.0f); break;
00135                 case 1: glTexCoord2f(0.0f, 0.0f); break;
00136                 }       
00137                 glVertex3fv(cornerB);
00138                 switch(rot)
00139                 {
00140                 case 0: glTexCoord2f(20.0f, 20.0f); break;
00141                 case 1: glTexCoord2f(0.0f, 20.0f); break;
00142                 }
00143                 glVertex3fv(cornerA);
00144         glEnd();
00145 }
00146 
00147 void Wall::wallHit(Vector &position, OptionsTransient::WallSide side)
00148 {
00149         fadeTime_[side] = 1.0f;
00150         CACHE_SOUND(sound, S3D::getDataFile("data/wav/shield/hit2.wav"));
00151         SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction,
00152                 sound, position);
00153 }
00154 
00155 void Wall::simulate(float time)
00156 {
00157         fadeTime_[OptionsTransient::LeftSide] -= time / 2.0f;
00158         fadeTime_[OptionsTransient::BotSide] -= time / 2.0f;
00159         fadeTime_[OptionsTransient::TopSide] -= time / 2.0f;
00160         fadeTime_[OptionsTransient::RightSide] -= time / 2.0f;
00161 }

Generated on Mon Feb 16 15:14:47 2009 for Scorched3D by  doxygen 1.5.3