2
* Copyright (C) 2005 Terence M. Welsh
3
* Ported to Linux by Tugrul Galatali <tugrul@galatali.com>
5
* This file is part of Hyperspace.
7
* Hyperspace is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License version 2 as
9
* published by the Free Software Foundation.
11
* Hyperspace 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.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34
#include "starBurst.h"
35
#include "wavyNormalCubeMaps.h"
36
#include "rsMath/rsMath.h"
39
extern int xsize, ysize;
40
extern float aspectRatio;
41
extern float frameTime;
42
extern float camPos[3];
43
extern int numAnimTexFrames;
44
extern wavyNormalCubeMaps* theWNCM;
45
extern unsigned int nebulatex;
46
extern unsigned int goo_vp, goo_fp;
47
extern int whichTexture;
52
starBurst::starBurst(){
58
stars = new stretchedParticle*[SB_NUM_STARS];
59
stars_active = new bool[SB_NUM_STARS];
60
stars_velocity = new float*[SB_NUM_STARS];
61
for(i=0; i<SB_NUM_STARS; i++){
62
stars[i] = new stretchedParticle;
64
stars_velocity[i] = new float[3];
65
vel[0] = rsRandf(1.0f) - 0.5f;
66
vel[1] = rsRandf(1.0f) - 0.5f;
67
vel[2] = rsRandf(1.0f) - 0.5f;
68
normalizer = (rsRandf(0.75f) + 0.25f)
69
/ sqrtf(vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2]);
70
stars_velocity[i][0] = vel[0] * normalizer;
71
stars_velocity[i][1] = vel[1] * normalizer;
72
stars_velocity[i][2] = vel[2] * normalizer;
76
float ci, si, cj, sj, cjj, sjj;
77
call_list = glGenLists(1);
78
glNewList(call_list, GL_COMPILE);
80
cj = cosf(float(j) * RS_PIx2 / 32.0f);
81
sj = sinf(float(j) * RS_PIx2 / 32.0f);
82
cjj = cosf(float(j+1) * RS_PIx2 / 32.0f);
83
sjj = sinf(float(j+1) * RS_PIx2 / 32.0f);
84
glBegin(GL_TRIANGLE_STRIP);
86
ci = cosf(float(i) * RS_PIx2 / 32.0f);
87
si = sinf(float(i) * RS_PIx2 / 32.0f);
107
void starBurst::restart(float* position){
110
for(i=0; i<SB_NUM_STARS; i++){ // don't restart if any star is still active
114
if(size < 3.0f) // or if flare hasn't faded out completely
118
color[0] = rsRandf(1.0f);
119
color[1] = rsRandf(1.0f);
120
color[2] = rsRandf(1.0f);
121
color[rsRandi(3)] = 1.0f;
122
for(i=0; i<SB_NUM_STARS; i++){
124
stars[i]->pos[0] = position[0];
125
stars[i]->pos[1] = position[1];
126
stars[i]->pos[2] = position[2];
127
stars[i]->color[0] = color[0];
128
stars[i]->color[1] = color[1];
129
stars[i]->color[2] = color[2];
133
pos[0] = position[0];
134
pos[1] = position[1];
135
pos[2] = position[2];
139
void starBurst::drawStars(){
144
glEnable(GL_TEXTURE_2D);
145
glBindTexture(GL_TEXTURE_2D, flaretex[0]);
146
for(i=0; i<SB_NUM_STARS; i++){
147
stars[i]->pos[0] += stars_velocity[i][0] * frameTime;
148
stars[i]->pos[1] += stars_velocity[i][1] * frameTime;
149
stars[i]->pos[2] += stars_velocity[i][2] * frameTime;
150
distance = sqrtf((stars[i]->pos[0] - camPos[0]) * (stars[i]->pos[0] - camPos[0])
151
+ (stars[i]->pos[1] - camPos[1]) * (stars[i]->pos[1] - camPos[1])
152
+ (stars[i]->pos[2] - camPos[2]) * (stars[i]->pos[2] - camPos[2]));
156
stars[i]->draw(camPos);
161
void starBurst::draw(){
164
size += frameTime * 0.5f;
169
float brightness = 1.0f - (size * 0.333333f);
170
if(brightness > 0.0f){
175
flare(p, 1.0f, 1.0f, 1.0f, brightness);
178
glMatrixMode(GL_MODELVIEW);
180
glTranslatef(pos[0], pos[1], pos[2]);
181
glScalef(size, size, size);
184
glBindTexture(GL_TEXTURE_2D, nebulatex);
185
glEnable(GL_TEXTURE_2D);
186
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
187
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
188
glEnable(GL_TEXTURE_GEN_S);
189
glEnable(GL_TEXTURE_GEN_T);
191
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
193
glColor4f(brightness, brightness, brightness, 1.0f);
194
glCallList(call_list);
196
glDisable(GL_TEXTURE_GEN_S);
197
glDisable(GL_TEXTURE_GEN_T);
204
void starBurst::draw(float lerp){
207
size += frameTime * 0.5f;
212
float brightness = 1.0f - (size * 0.333333f);
213
if(brightness > 0.0f){
218
flare(p, 1.0f, 1.0f, 1.0f, brightness);
221
glMatrixMode(GL_MODELVIEW);
223
glTranslatef(pos[0], pos[1], pos[2]);
224
glScalef(size, size, size);
227
glDisable(GL_TEXTURE_2D);
228
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
229
glActiveTextureARB(GL_TEXTURE2_ARB);
230
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, nebulatex);
231
glActiveTextureARB(GL_TEXTURE1_ARB);
232
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, theWNCM->texture[(whichTexture + 1) % numAnimTexFrames]);
233
glActiveTextureARB(GL_TEXTURE0_ARB);
234
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, theWNCM->texture[whichTexture]);
235
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, goo_vp);
236
glEnable(GL_VERTEX_PROGRAM_ARB);
237
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, goo_fp);
238
glEnable(GL_FRAGMENT_PROGRAM_ARB);
240
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
242
glColor4f(brightness, brightness, brightness, lerp);
243
glCallList(call_list);
245
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
246
glDisable(GL_VERTEX_PROGRAM_ARB);
247
glDisable(GL_FRAGMENT_PROGRAM_ARB);