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 <sprites/ExplosionLaserBeamRenderer.h>
22 #include <sprites/ExplosionTextures.h>
23 #include <common/Defines.h>
24 #include <console/Console.h>
25 #include <image/ImageFactory.h>
26 #include <sound/SoundUtils.h>
27 #include <client/ScorchedClient.h>
28 #include <graph/ParticleEmitter.h>
29 #include <graph/ParticleEngine.h>
30 
31 REGISTER_CLASS_SOURCE(ExplosionLaserBeamRenderer);
32 
33 GLTextureReference ExplosionLaserBeamRenderer::_texture(ImageID(S3D::eModLocation,
34 			"data/textures/waves.bmp",
35 			"data/textures/waves.bmp",
36 			false));
37 
~ExplosionLaserBeamRenderer()38 ExplosionLaserBeamRenderer::~ExplosionLaserBeamRenderer()
39 {
40 }
41 
ExplosionLaserBeamRenderer()42 ExplosionLaserBeamRenderer::ExplosionLaserBeamRenderer():
43 	totalTime_(0), time_(0), size_(12.0f), angle_(0)
44 {
45 
46 }
47 
init(unsigned int playerId,Vector & position,Vector & velocity,const char * data)48 void ExplosionLaserBeamRenderer::init(unsigned int playerId,
49 	Vector &position, Vector &velocity, const char *data)
50 {
51 	if (0 != strcmp("none", data))
52 	{
53 		SoundBuffer *firedSound =
54 			Sound::instance()->fetchOrCreateBuffer(
55 				S3D::getModFile(data));
56 		SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction,
57 			firedSound, position);
58 	}
59 
60 	for (int j=0;j<layers;j++){
61 		for(int i=0;i<sides;i++){
62 			points[j][i]=Vector((float)(360/sides)*i,(double)((size_/(layers+1))*(j+1)));
63 		}
64 	}
65 
66 	position_ = position;
67 
68 	ParticleEmitter emmiter;
69 	emmiter.setAttributes(
70 			10.0f, 0.9f, // Life
71 			0.5f, 9.5f, // Mass
72 			0.0f, 0.0f, // Friction
73 			Vector::getNullVector(), Vector::getNullVector(), // Velocity
74 			Vector(0.9f, 0.9f, 0.1f), 0.9f, // StartColor1
75 			Vector(0.9f, 0.9f, 0.1f), 0.1f, // StartColor2
76 			Vector(0.6f, 0.6f, 0.95f), 0.0f, // EndColor1
77 			Vector(0.8f, 0.8f, 1.0f), 0.1f, // EndColor2
78 			0.0f, 0.0f, 0.5f, 0.5f, // Start Size
79 			0.0f, 0.0f, 10.0f, 10.0f, // EndSize
80 			Vector(0.0f, 0.0f, 10.0f), // Gravity
81 			true,
82 			false);
83 
84 		Vector newPos1 = position_ + Vector(-4.0f, -4.0f, 0.0f);
85 		Vector newPos2 = position_ + Vector(4.0f, 4.0f, 0.0f);
86 		GLTextureSet *texture = ExplosionTextures::instance()->getTextureSetByName("particle");
87 		emmiter.emitLinear(800, newPos1, newPos2,
88 			ScorchedClient::instance()->getParticleEngine(),
89 			ParticleRendererQuads::getInstance(),
90 			texture,
91 			false);
92 }
93 
draw(Action * action)94 void ExplosionLaserBeamRenderer::draw(Action *action)
95 {
96 	GLState currentState(GLState::TEXTURE_ON | GLState::BLEND_ON);
97 	_texture.draw();
98 
99 	glPushMatrix();
100 	glTranslatef(position_[0],position_[1],0.0f);
101 	glScalef(time_*0.05f,time_*0.05f,1.0f);
102 
103 	for (int j=0;j<layers;j++){
104 		glRotatef(angle_,0.0f,0.0f,1.0f);
105 		glBegin(GL_TRIANGLE_STRIP);
106 		int tempheight=(int)(time_*time_*time_);
107 		if (tempheight>100) tempheight=100;
108 		Vector height(0,0,tempheight);
109 
110 		glColor4f(0.0f,0.6f,0.9f, 0.4f);
111 
112 		for (int i=0;i<(sides+1);i++){
113 
114 			glNormal3fv ((float*)(points[j][i%sides]));
115 			if (i%2){
116 				glTexCoord2f(0.0f, 0.0f+((layers-j)*time_));
117 			}else{
118 				glTexCoord2f(2.0f, 0.0f+((layers-j)*time_));
119 			}
120 			glVertex3fv((float*)(points[j][i%sides]+height));
121 			glNormal3fv ((float*)(points[j][i%sides]));
122 			if (i%2){
123 				glTexCoord2f(0.0f, (float)(tempheight/10)+((layers-j)*time_));
124 			}else{
125 				glTexCoord2f(2.0f, (float)(tempheight/10)+((layers-j)*time_));
126 			}
127 			glVertex3fv((float*)(points[j][i%sides]));
128 		}
129 		for (int i=0;i<(sides+1);i++){
130 
131 			glNormal3fv ((float*)(points[j][i%sides]));
132 			if (i%2){
133 				glTexCoord2f(0.0f, 0.0f-((layers-j)*time_));
134 			}else{
135 				glTexCoord2f(2.0f, 0.0f-((layers-j)*time_));
136 			}
137 			glVertex3fv((float*)(points[j][i%sides]));
138 			glNormal3fv ((float*)(points[j][i%sides]));
139 			if (i%2){
140 				glTexCoord2f(0.0f, (float)(tempheight/10)-((layers-j)*time_));
141 			}else{
142 				glTexCoord2f(2.0f, (float)(tempheight/10)-((layers-j)*time_));
143 			}
144 			glVertex3fv((float*)(points[j][i%sides]+height));
145 		}
146 
147 		glEnd();
148 	}
149 	glPopMatrix();
150 
151 }
simulate(Action * action,float frameTime,bool & remove)152 void ExplosionLaserBeamRenderer::simulate(Action *action, float frameTime, bool &remove)
153 {
154 
155 	totalTime_ += frameTime;
156 	time_ += frameTime;
157 	angle_=(angle_+3.0f);
158 	if (angle_>360.0f){
159 		angle_=0.0f;
160 	}
161 	if ((time_)>size_){
162 		remove=true;
163 	}else{
164 		remove=false;
165 	}
166 
167 
168 }
169 
170