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