3 Copyright (c) 2002, Calum Robinson
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
16 * Neither the name of the author nor the names of its contributors may be used
17 to endorse or promote products derived from this software without specific
18 prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* Spark.cpp: implementation of the Spark class. */
41 void InitSpark(Spark *s)
46 s->position[i] = RandFlt(-100.0, 100.0);
50 void DrawSpark(global_info_t *global, flurry_info_t *flurry, Spark *s)
52 const float black[4] = {0.0f,0.0f,0.0f,1.0f};
60 width = 60000.0f * global->sys_glWidth / 1024.0f;
63 sx = s->position[0] * global->sys_glWidth / z + global->sys_glWidth * 0.5f;
64 sy = s->position[1] * global->sys_glWidth / z + global->sys_glHeight * 0.5f;
71 glTranslatef(screenx,screeny,0.0f);
73 glScalef(scale,scale,0.0f);
76 a = ((float) (random() % 3600)) / 10.0f;
77 glRotatef(a,0.0f,0.0f,1.0f);
78 glBegin(GL_QUAD_STRIP);
80 glVertex2f(-3.0f,0.0f);
81 a = 2.0f + (float) (random() & 255) * c;
84 glVertex2f(0.0f,0.0f);
87 glVertex2f(3.0f,0.0f);
94 #define BIGMYSTERY 1800.0
95 #define MAXANGLES 16384
97 void UpdateSparkColour(global_info_t *global, flurry_info_t *flurry, Spark *s)
99 const float rotationsPerSecond = (float) (2.0*PI*fieldSpeed/MAXANGLES);
100 double thisPointInRadians;
101 double thisAngle = flurry->fTime*rotationsPerSecond;
103 float cycleTime = 20.0f;
106 float greenPhaseShift;
107 float bluePhaseShift;
113 if (flurry->currentColorMode == rainbowColorMode)
117 else if (flurry->currentColorMode == tiedyeColorMode)
121 else if (flurry->currentColorMode == cyclicColorMode)
125 else if (flurry->currentColorMode == slowCyclicColorMode)
129 colorRot = (float) (2.0*PI/cycleTime);
130 redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */
131 greenPhaseShift = cycleTime / 3.0f;
132 bluePhaseShift = cycleTime * 2.0f / 3.0f ;
133 colorTime = flurry->fTime;
134 if (flurry->currentColorMode == whiteColorMode)
140 else if (flurry->currentColorMode == multiColorMode)
146 else if (flurry->currentColorMode == darkColorMode)
154 if (flurry->currentColorMode < slowCyclicColorMode)
156 colorTime = (flurry->currentColorMode / 6.0f) * cycleTime;
160 colorTime = flurry->fTime + flurry->flurryRandomSeed;
162 baseRed = 0.109375f * ((float) cos((colorTime+redPhaseShift)*colorRot)+1.0f);
163 baseGreen = 0.109375f * ((float) cos((colorTime+greenPhaseShift)*colorRot)+1.0f);
164 baseBlue = 0.109375f * ((float) cos((colorTime+bluePhaseShift)*colorRot)+1.0f);
167 cf = ((float) (cos(7.0*((flurry->fTime)*rotationsPerSecond))+cos(3.0*((flurry->fTime)*rotationsPerSecond))+cos(13.0*((flurry->fTime)*rotationsPerSecond))));
170 thisPointInRadians = 2.0 * PI * (double) s->mystery / (double) BIGMYSTERY;
172 s->color[0] = baseRed + 0.0625f * (0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle))) + (float) sin((7.0 * (thisPointInRadians + thisAngle))));
173 s->color[1] = baseGreen + 0.0625f * (0.5f + (float) sin(((thisPointInRadians) + thisAngle)));
174 s->color[2] = baseBlue + 0.0625f * (0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle))));
177 void UpdateSpark(global_info_t *global, flurry_info_t *flurry, Spark *s)
179 const float rotationsPerSecond = (float) (2.0*PI*fieldSpeed/MAXANGLES);
180 double thisPointInRadians;
181 double thisAngle = flurry->fTime*rotationsPerSecond;
184 double tmpX1,tmpY1,tmpZ1;
185 double tmpX2,tmpY2,tmpZ2;
186 double tmpX3,tmpY3,tmpZ3;
187 double tmpX4,tmpY4,tmpZ4;
191 float cycleTime = 20.0f;
194 float greenPhaseShift;
195 float bluePhaseShift;
203 if (flurry->currentColorMode == rainbowColorMode) {
205 } else if (flurry->currentColorMode == tiedyeColorMode) {
207 } else if (flurry->currentColorMode == cyclicColorMode) {
209 } else if (flurry->currentColorMode == slowCyclicColorMode) {
212 colorRot = (float) (2.0*PI/cycleTime);
213 redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */
214 greenPhaseShift = cycleTime / 3.0f;
215 bluePhaseShift = cycleTime * 2.0f / 3.0f ;
216 colorTime = flurry->fTime;
217 if (flurry->currentColorMode == whiteColorMode) {
221 } else if (flurry->currentColorMode == multiColorMode) {
225 } else if (flurry->currentColorMode == darkColorMode) {
230 if(flurry->currentColorMode < slowCyclicColorMode) {
231 colorTime = (flurry->currentColorMode / 6.0f) * cycleTime;
233 colorTime = flurry->fTime + flurry->flurryRandomSeed;
235 baseRed = 0.109375f * ((float) cos((colorTime+redPhaseShift)*colorRot)+1.0f);
236 baseGreen = 0.109375f * ((float) cos((colorTime+greenPhaseShift)*colorRot)+1.0f);
237 baseBlue = 0.109375f * ((float) cos((colorTime+bluePhaseShift)*colorRot)+1.0f);
241 old[i] = s->position[i];
244 cf = ((float) (cos(7.0*((flurry->fTime)*rotationsPerSecond))+cos(3.0*((flurry->fTime)*rotationsPerSecond))+cos(13.0*((flurry->fTime)*rotationsPerSecond))));
247 thisPointInRadians = 2.0 * PI * (double) s->mystery / (double) BIGMYSTERY;
249 s->color[0] = baseRed + 0.0625f * (0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle))) + (float) sin((7.0 * (thisPointInRadians + thisAngle))));
250 s->color[1] = baseGreen + 0.0625f * (0.5f + (float) sin(((thisPointInRadians) + thisAngle)));
251 s->color[2] = baseBlue + 0.0625f * (0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle))));
252 s->position[0] = fieldRange * cf * (float) cos(11.0 * (thisPointInRadians + (3.0*thisAngle)));
253 s->position[1] = fieldRange * cf * (float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle)));
254 s->position[2] = fieldRange * (float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle))));
256 rotation = thisAngle*0.501 + 5.01 * (double) s->mystery / (double) BIGMYSTERY;
259 tmpX1 = s->position[0] * cr - s->position[1] * sr;
260 tmpY1 = s->position[1] * cr + s->position[0] * sr;
261 tmpZ1 = s->position[2];
263 tmpX2 = tmpX1 * cr - tmpZ1 * sr;
265 tmpZ2 = tmpZ1 * cr + tmpX1 * sr;
268 tmpY3 = tmpY2 * cr - tmpZ2 * sr;
269 tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance;
271 rotation = thisAngle*2.501 + 85.01 * (double) s->mystery / (double) BIGMYSTERY;
274 tmpX4 = tmpX3 * cr - tmpY3 * sr;
275 tmpY4 = tmpY3 * cr + tmpX3 * sr;
278 s->position[0] = (float) tmpX4 + RandBell(5.0f*fieldCoherence);
279 s->position[1] = (float) tmpY4 + RandBell(5.0f*fieldCoherence);
280 s->position[2] = (float) tmpZ4 + RandBell(5.0f*fieldCoherence);
283 s->delta[i] = (s->position[i] - old[i])/flurry->fDeltaTime;