1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2011
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20
21 #include <GLEXT/GLState.h>
22 #include <image/ImageFactory.h>
23 #include <sprites/WallActionRenderer.h>
24 #include <engine/ScorchedContext.h>
25 #include <client/ScorchedClient.h>
26 #include <landscape/Wall.h>
27 #include <landscape/Landscape.h>
28 #include <landscapemap/LandscapeMaps.h>
29 #include <landscapedef/LandscapeDefn.h>
30 #include <common/OptionsTransient.h>
31 #include <common/Defines.h>
32
33 GLTexture WallActionRenderer::texture_ = GLTexture();
34
WallActionRenderer(Vector & position,OptionsTransient::WallSide type)35 WallActionRenderer::WallActionRenderer(
36 Vector &position, OptionsTransient::WallSide type) :
37 position_(position), type_(type), fade_(1.0f), init_(false)
38 {
39
40 }
41
~WallActionRenderer()42 WallActionRenderer::~WallActionRenderer()
43 {
44
45 }
46
init()47 void WallActionRenderer::init()
48 {
49 init_ = true;
50
51 if (!texture_.textureValid())
52 {
53 Image map = ImageFactory::loadImage(
54 S3D::eModLocation,
55 "data/textures/bordershield/hit.bmp",
56 "data/textures/bordershield/hit.bmp",
57 false);
58 texture_.create(map, true);
59 }
60
61 Landscape::instance()->getWall().wallHit(position_, type_);
62 Vector pos = position_;
63 Vector offSet1, offSet2, offSet3 ,offSet4;
64
65 static float offsetAmount = 0.1f;
66 const float offset = offsetAmount;
67 offsetAmount += 0.02f;
68 if (offsetAmount > 0.4f) offsetAmount = 0.1f;
69
70 float arenaX = (float) ScorchedClient::instance()->getLandscapeMaps().
71 getDefinitions().getDefn()->getArenaX();
72 float arenaY = (float) ScorchedClient::instance()->getLandscapeMaps().
73 getDefinitions().getDefn()->getArenaY();
74 float arenaWidth = (float) ScorchedClient::instance()->getLandscapeMaps().
75 getDefinitions().getDefn()->getArenaWidth();
76 float arenaHeight = (float) ScorchedClient::instance()->getLandscapeMaps().
77 getDefinitions().getDefn()->getArenaHeight();
78
79 switch (type_)
80 {
81 case OptionsTransient::LeftSide:
82 pos[0] = arenaX;
83 xOff_ = -offset; yOff_ = 0.0f;
84 offSet1 = Vector(0.0f, 1.0f, 1.0f);
85 offSet2 = Vector(0.0f, 1.0f, -1.0f);
86 offSet3 = Vector(0.0f, -1.0f, -1.0f);
87 offSet4 = Vector(0.0f, -1.0f, 1.0f);
88 break;
89 case OptionsTransient::RightSide:
90 pos[0] = arenaX + arenaWidth;
91 xOff_ = -offset; yOff_ = 0.0f;
92 offSet1 = Vector(0.0f, 1.0f, 1.0f);
93 offSet2 = Vector(0.0f, 1.0f, -1.0f);
94 offSet3 = Vector(0.0f, -1.0f, -1.0f);
95 offSet4 = Vector(0.0f, -1.0f, 1.0f);
96 break;
97 case OptionsTransient::TopSide:
98 pos[1] = arenaY;
99 xOff_ = 0.0f; yOff_ = offset;
100 offSet1 = Vector(1.0f, 0.0f, 1.0f);
101 offSet2 = Vector(1.0f, 0.0f, -1.0f);
102 offSet3 = Vector(-1.0f, 0.0f, -1.0f);
103 offSet4 = Vector(-1.0f, 0.0f, 1.0f);
104 break;
105 default:
106 case OptionsTransient::BotSide:
107 pos[1] = arenaY + arenaHeight;
108 xOff_ = 0.0f; yOff_ = offset;
109 offSet1 = Vector(1.0f, 0.0f, 1.0f);
110 offSet2 = Vector(1.0f, 0.0f, -1.0f);
111 offSet3 = Vector(-1.0f, 0.0f, -1.0f);
112 offSet4 = Vector(-1.0f, 0.0f, 1.0f);
113 break;
114 }
115
116 const float size = 20.0f;
117 cornerA_ = pos + offSet1 * size;
118 cornerB_ = pos + offSet2 * size;
119 cornerC_ = pos + offSet3 * size;
120 cornerD_ = pos + offSet4 * size;
121
122 color_ = ScorchedClient::instance()->getOptionsTransient().getWallColor();
123 }
124
simulate(float frameTime)125 void WallActionRenderer::simulate(float frameTime)
126 {
127 fade_ -= frameTime / 2.0f;
128 }
129
draw()130 void WallActionRenderer::draw()
131 {
132 if (!init_) init();
133
134 GLState currentState(GLState::BLEND_ON | GLState::TEXTURE_ON);
135
136 texture_.draw();
137 glColor4f(color_[0], color_[1], color_[2], fade_);
138 glPushMatrix();
139 glTranslatef(xOff_, yOff_, 0.0f);
140 glBegin(GL_QUADS);
141 glTexCoord2f(1.0f, 1.0f);
142 glVertex3fv(cornerA_);
143 glTexCoord2f(0.0f, 1.0f);
144 glVertex3fv(cornerB_);
145 glTexCoord2f(0.0f, 0.0f);
146 glVertex3fv(cornerC_);
147 glTexCoord2f(1.0f, 0.0f);
148 glVertex3fv(cornerD_);
149 glEnd();
150 glPopMatrix();
151
152 glPushMatrix();
153 glTranslatef(-xOff_, -yOff_, 0.0f);
154 glBegin(GL_QUADS);
155 glTexCoord2f(0.0f, 0.0f);
156 glVertex3fv(cornerD_);
157 glTexCoord2f(1.0f, 0.0f);
158 glVertex3fv(cornerC_);
159 glTexCoord2f(1.0f, 1.0f);
160 glVertex3fv(cornerB_);
161 glTexCoord2f(0.0f, 1.0f);
162 glVertex3fv(cornerA_);
163 glEnd();
164 glPopMatrix();
165 }
166