1 /*
2  * Copyright (C) 2002  Terence M. Welsh
3  * Ported to Linux by Tugrul Galatali <tugrul@galatali.com>
4  *
5  * Skyrocket is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Skyrocket is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18 
19 #include <math.h>
20 #include <GL/gl.h>
21 
22 #include "skyrocket_shockwave.h"
23 #include "skyrocket_world.h"
24 
25 extern unsigned int cloudtex;
26 
27 float shockwavegeom[7][WAVESTEPS + 1][3];
28 
initShockwave()29 void initShockwave ()
30 {
31 	int i, j;
32 	float ch, sh;
33 
34 	shockwavegeom[0][0][0] = 1.0f;
35 	shockwavegeom[0][0][1] = 0.0f;
36 	shockwavegeom[0][0][2] = 0.0f;
37 	shockwavegeom[1][0][0] = 0.985f;
38 	shockwavegeom[1][0][1] = 0.035f;
39 	shockwavegeom[1][0][2] = 0.0f;
40 	shockwavegeom[2][0][0] = 0.95f;
41 	shockwavegeom[2][0][1] = 0.05f;
42 	shockwavegeom[2][0][2] = 0.0f;
43 	shockwavegeom[3][0][0] = 0.85f;
44 	shockwavegeom[3][0][1] = 0.05f;
45 	shockwavegeom[3][0][2] = 0.0f;
46 	shockwavegeom[4][0][0] = 0.75f;
47 	shockwavegeom[4][0][1] = 0.035f;
48 	shockwavegeom[4][0][2] = 0.0f;
49 	shockwavegeom[5][0][0] = 0.65f;
50 	shockwavegeom[5][0][1] = 0.01f;
51 	shockwavegeom[5][0][2] = 0.0f;
52 	shockwavegeom[6][0][0] = 0.5f;
53 	shockwavegeom[6][0][1] = 0.0f;
54 	shockwavegeom[6][0][2] = 0.0f;
55 
56 	for (i = 1; i <= WAVESTEPS; i++) {
57 		ch = cos (6.28318530718f * (float (i) / float (WAVESTEPS)));
58 		sh = sin (6.28318530718f * (float (i) / float (WAVESTEPS)));
59 		for (j = 0; j <= 6; j++) {
60 			shockwavegeom[j][i][0] = ch * shockwavegeom[j][0][0];
61 			shockwavegeom[j][i][1] = shockwavegeom[j][0][1];
62 			shockwavegeom[j][i][2] = sh * shockwavegeom[j][0][0];
63 		}
64 	}
65 }
66 
67 // temp influences color intensity (0.0 - 1.0)
68 // texmove is amount to advance the texture coordinates
drawShockwave(float temperature,float texmove)69 void drawShockwave (float temperature, float texmove)
70 {
71 	static int i, j;
72 	float colors[7][4];
73 	static float u, v1, v2;
74 	float temp;
75 
76 	// setup diminishing alpha values in color array
77 	if (temperature > 0.5f) {
78 		temp = 1.0f;
79 		colors[0][3] = 1.0f;
80 		colors[1][3] = 0.9f;
81 		colors[2][3] = 0.8f;
82 		colors[3][3] = 0.7f;
83 		colors[4][3] = 0.5f;
84 		colors[5][3] = 0.3f;
85 		colors[6][3] = 0.0f;
86 	} else {
87 		temp = temperature * 2.0f;
88 		colors[0][3] = temp;
89 		colors[1][3] = temp * 0.9f;
90 		colors[2][3] = temp * 0.8f;
91 		colors[3][3] = temp * 0.7f;
92 		colors[4][3] = temp * 0.5f;
93 		colors[5][3] = temp * 0.3f;
94 		colors[6][3] = 0.0f;
95 	}
96 	// setup rgb values in color array
97 	for (i = 0; i <= 5; i++) {
98 		colors[i][0] = 1.0f;
99 		//colors[i][1] = temp + (((1.0f - temp) * 0.5f) - (1.0f - temp) * float(i) * 0.1f);
100 		colors[i][1] = temp;
101 		colors[i][2] = temperature;
102 	}
103 
104 	glDisable (GL_CULL_FACE);
105 	glBlendFunc (GL_SRC_ALPHA, GL_ONE);
106 	glEnable (GL_BLEND);
107 	glEnable (GL_TEXTURE_2D);
108 	glBindTexture (GL_TEXTURE_2D, cloudtex);
109 
110 	// draw bottom of shockwave
111 	for (i = 0; i < 6; i++) {
112 		v1 = float (i + 1) * 0.07f - texmove;
113 		v2 = float (i) * 0.07f - texmove;
114 
115 		glBegin (GL_TRIANGLE_STRIP);
116 		for (j = 0; j <= WAVESTEPS; j++) {
117 			u = (float (j) / float (WAVESTEPS))*10.0f;
118 			glColor4fv (colors[i + 1]);
119 			glTexCoord2f (u, v1);
120 			glVertex3f (shockwavegeom[i + 1][j][0], -shockwavegeom[i + 1][j][1], shockwavegeom[i + 1][j][2]);
121 			glColor4fv (colors[i]);
122 			glTexCoord2f (u, v2);
123 			glVertex3f (shockwavegeom[i][j][0], -shockwavegeom[i][j][1], shockwavegeom[i][j][2]);
124 		}
125 		glEnd ();
126 	}
127 
128 	// keep colors a little warmer on top (more green)
129 	if (temperature < 0.5f)
130 		for (i = 1; i <= 5; i++)
131 			colors[i][1] = temperature + 0.5f;
132 
133 	// draw top of shockwave
134 	for (i = 0; i < 6; i++) {
135 		v1 = float (i) * 0.07f - texmove;
136 		v2 = float (i + 1) * 0.07f - texmove;
137 
138 		glBegin (GL_TRIANGLE_STRIP);
139 		for (j = 0; j <= WAVESTEPS; j++) {
140 			u = (float (j) / float (WAVESTEPS))*10.0f;
141 			glColor4fv (colors[i]);
142 			glTexCoord2f (u, v1);
143 			glVertex3f (shockwavegeom[i][j][0], shockwavegeom[i][j][1], shockwavegeom[i][j][2]);
144 			glColor4fv (colors[i + 1]);
145 			glTexCoord2f (u, v2);
146 			glVertex3f (shockwavegeom[i + 1][j][0], shockwavegeom[i + 1][j][1], shockwavegeom[i + 1][j][2]);
147 		}
148 		glEnd ();
149 	}
150 
151 	glEnable (GL_CULL_FACE);
152 }
153