00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <GLEXT/GLState.h>
00022 #include <image/ImageFactory.h>
00023 #include <sprites/WallActionRenderer.h>
00024 #include <engine/ScorchedContext.h>
00025 #include <client/ScorchedClient.h>
00026 #include <landscape/Wall.h>
00027 #include <landscape/Landscape.h>
00028 #include <landscapemap/LandscapeMaps.h>
00029 #include <landscapedef/LandscapeDefn.h>
00030 #include <common/OptionsTransient.h>
00031 #include <common/Defines.h>
00032
00033 GLTexture WallActionRenderer::texture_ = GLTexture();
00034
00035 WallActionRenderer::WallActionRenderer(
00036 Vector &position, OptionsTransient::WallSide type) :
00037 position_(position), type_(type), fade_(1.0f), init_(false)
00038 {
00039
00040 }
00041
00042 WallActionRenderer::~WallActionRenderer()
00043 {
00044
00045 }
00046
00047 void WallActionRenderer::init()
00048 {
00049 init_ = true;
00050
00051 if (!texture_.textureValid())
00052 {
00053 std::string file = S3D::getDataFile("data/textures/bordershield/hit.bmp");
00054 ImageHandle map = ImageFactory::loadImageHandle(file.c_str(), file.c_str(), false);
00055 texture_.create(map, true);
00056 }
00057
00058 Landscape::instance()->getWall().wallHit(position_, type_);
00059 Vector pos = position_;
00060 Vector offSet1, offSet2, offSet3 ,offSet4;
00061
00062 static float offsetAmount = 0.1f;
00063 const float offset = offsetAmount;
00064 offsetAmount += 0.02f;
00065 if (offsetAmount > 0.4f) offsetAmount = 0.1f;
00066
00067 float arenaX = (float) ScorchedClient::instance()->getLandscapeMaps().
00068 getDefinitions().getDefn()->getArenaX();
00069 float arenaY = (float) ScorchedClient::instance()->getLandscapeMaps().
00070 getDefinitions().getDefn()->getArenaY();
00071 float arenaWidth = (float) ScorchedClient::instance()->getLandscapeMaps().
00072 getDefinitions().getDefn()->getArenaWidth();
00073 float arenaHeight = (float) ScorchedClient::instance()->getLandscapeMaps().
00074 getDefinitions().getDefn()->getArenaHeight();
00075
00076 switch (type_)
00077 {
00078 case OptionsTransient::LeftSide:
00079 pos[0] = arenaX;
00080 xOff_ = -offset; yOff_ = 0.0f;
00081 offSet1 = Vector(0.0f, 1.0f, 1.0f);
00082 offSet2 = Vector(0.0f, 1.0f, -1.0f);
00083 offSet3 = Vector(0.0f, -1.0f, -1.0f);
00084 offSet4 = Vector(0.0f, -1.0f, 1.0f);
00085 break;
00086 case OptionsTransient::RightSide:
00087 pos[0] = arenaX + arenaWidth;
00088 xOff_ = -offset; yOff_ = 0.0f;
00089 offSet1 = Vector(0.0f, 1.0f, 1.0f);
00090 offSet2 = Vector(0.0f, 1.0f, -1.0f);
00091 offSet3 = Vector(0.0f, -1.0f, -1.0f);
00092 offSet4 = Vector(0.0f, -1.0f, 1.0f);
00093 break;
00094 case OptionsTransient::TopSide:
00095 pos[1] = arenaY;
00096 xOff_ = 0.0f; yOff_ = offset;
00097 offSet1 = Vector(1.0f, 0.0f, 1.0f);
00098 offSet2 = Vector(1.0f, 0.0f, -1.0f);
00099 offSet3 = Vector(-1.0f, 0.0f, -1.0f);
00100 offSet4 = Vector(-1.0f, 0.0f, 1.0f);
00101 break;
00102 default:
00103 case OptionsTransient::BotSide:
00104 pos[1] = arenaY + arenaHeight;
00105 xOff_ = 0.0f; yOff_ = offset;
00106 offSet1 = Vector(1.0f, 0.0f, 1.0f);
00107 offSet2 = Vector(1.0f, 0.0f, -1.0f);
00108 offSet3 = Vector(-1.0f, 0.0f, -1.0f);
00109 offSet4 = Vector(-1.0f, 0.0f, 1.0f);
00110 break;
00111 }
00112
00113 const float size = 20.0f;
00114 cornerA_ = pos + offSet1 * size;
00115 cornerB_ = pos + offSet2 * size;
00116 cornerC_ = pos + offSet3 * size;
00117 cornerD_ = pos + offSet4 * size;
00118
00119 color_ = ScorchedClient::instance()->getOptionsTransient().getWallColor();
00120 }
00121
00122 void WallActionRenderer::simulate(float frameTime)
00123 {
00124 fade_ -= frameTime / 2.0f;
00125 }
00126
00127 void WallActionRenderer::draw()
00128 {
00129 if (!init_) init();
00130
00131 GLState currentState(GLState::BLEND_ON | GLState::TEXTURE_ON);
00132
00133 texture_.draw();
00134 glColor4f(color_[0], color_[1], color_[2], fade_);
00135 glPushMatrix();
00136 glTranslatef(xOff_, yOff_, 0.0f);
00137 glBegin(GL_QUADS);
00138 glTexCoord2f(1.0f, 1.0f);
00139 glVertex3fv(cornerA_);
00140 glTexCoord2f(0.0f, 1.0f);
00141 glVertex3fv(cornerB_);
00142 glTexCoord2f(0.0f, 0.0f);
00143 glVertex3fv(cornerC_);
00144 glTexCoord2f(1.0f, 0.0f);
00145 glVertex3fv(cornerD_);
00146 glEnd();
00147 glPopMatrix();
00148
00149 glPushMatrix();
00150 glTranslatef(-xOff_, -yOff_, 0.0f);
00151 glBegin(GL_QUADS);
00152 glTexCoord2f(0.0f, 0.0f);
00153 glVertex3fv(cornerD_);
00154 glTexCoord2f(1.0f, 0.0f);
00155 glVertex3fv(cornerC_);
00156 glTexCoord2f(1.0f, 1.0f);
00157 glVertex3fv(cornerB_);
00158 glTexCoord2f(0.0f, 1.0f);
00159 glVertex3fv(cornerA_);
00160 glEnd();
00161 glPopMatrix();
00162 }