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. */
37 void InitSpark(Spark *s)
42 s->position[i] = RandFlt(-100.0, 100.0);
46 void DrawSpark(global_info_t *global, flurry_info_t *flurry, Spark *s)
48 const float black[4] = {0.0f,0.0f,0.0f,1.0f};
56 width = 60000.0f * global->sys_glWidth / 1024.0f;
59 sx = s->position[0] * global->sys_glWidth / z + global->sys_glWidth * 0.5f;
60 sy = s->position[1] * global->sys_glWidth / z + global->sys_glHeight * 0.5f;
67 glTranslatef(screenx,screeny,0.0f);
69 glScalef(scale,scale,0.0f);
72 a = ((float) (random() % 3600)) / 10.0f;
73 glRotatef(a,0.0f,0.0f,1.0f);
74 glBegin(GL_QUAD_STRIP);
76 glVertex2f(-3.0f,0.0f);
77 a = 2.0f + (float) (random() & 255) * c;
80 glVertex2f(0.0f,0.0f);
83 glVertex2f(3.0f,0.0f);
90 #define BIGMYSTERY 1800.0
91 #define MAXANGLES 16384
93 void UpdateSparkColour(global_info_t *global, flurry_info_t *flurry, Spark *s)
95 const float rotationsPerSecond = (float) (2.0*PI*fieldSpeed/MAXANGLES);
96 double thisPointInRadians;
97 double thisAngle = flurry->fTime*rotationsPerSecond;
99 float cycleTime = 20.0f;
102 float greenPhaseShift;
103 float bluePhaseShift;
109 if (flurry->currentColorMode == rainbowColorMode)
113 else if (flurry->currentColorMode == tiedyeColorMode)
117 else if (flurry->currentColorMode == cyclicColorMode)
121 else if (flurry->currentColorMode == slowCyclicColorMode)
125 colorRot = (float) (2.0*PI/cycleTime);
126 redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */
127 greenPhaseShift = cycleTime / 3.0f;
128 bluePhaseShift = cycleTime * 2.0f / 3.0f ;
129 colorTime = flurry->fTime;
130 if (flurry->currentColorMode == whiteColorMode)
136 else if (flurry->currentColorMode == multiColorMode)
142 else if (flurry->currentColorMode == darkColorMode)
150 if (flurry->currentColorMode < slowCyclicColorMode)
152 colorTime = (flurry->currentColorMode / 6.0f) * cycleTime;
156 colorTime = flurry->fTime + flurry->flurryRandomSeed;
158 baseRed = 0.109375f * ((float) cos((colorTime+redPhaseShift)*colorRot)+1.0f);
159 baseGreen = 0.109375f * ((float) cos((colorTime+greenPhaseShift)*colorRot)+1.0f);
160 baseBlue = 0.109375f * ((float) cos((colorTime+bluePhaseShift)*colorRot)+1.0f);
163 cf = ((float) (cos(7.0*((flurry->fTime)*rotationsPerSecond))+cos(3.0*((flurry->fTime)*rotationsPerSecond))+cos(13.0*((flurry->fTime)*rotationsPerSecond))));
166 thisPointInRadians = 2.0 * PI * (double) s->mystery / (double) BIGMYSTERY;
168 s->color[0] = baseRed + 0.0625f * (0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle))) + (float) sin((7.0 * (thisPointInRadians + thisAngle))));
169 s->color[1] = baseGreen + 0.0625f * (0.5f + (float) sin(((thisPointInRadians) + thisAngle)));
170 s->color[2] = baseBlue + 0.0625f * (0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle))));
173 void UpdateSpark(global_info_t *global, flurry_info_t *flurry, Spark *s)
175 const float rotationsPerSecond = (float) (2.0*PI*fieldSpeed/MAXANGLES);
176 double thisPointInRadians;
177 double thisAngle = flurry->fTime*rotationsPerSecond;
180 double tmpX1,tmpY1,tmpZ1;
181 double tmpX2,tmpY2,tmpZ2;
182 double tmpX3,tmpY3,tmpZ3;
183 double tmpX4,tmpY4,tmpZ4;
187 float cycleTime = 20.0f;
190 float greenPhaseShift;
191 float bluePhaseShift;
199 if (flurry->currentColorMode == rainbowColorMode) {
201 } else if (flurry->currentColorMode == tiedyeColorMode) {
203 } else if (flurry->currentColorMode == cyclicColorMode) {
205 } else if (flurry->currentColorMode == slowCyclicColorMode) {
208 colorRot = (float) (2.0*PI/cycleTime);
209 redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */
210 greenPhaseShift = cycleTime / 3.0f;
211 bluePhaseShift = cycleTime * 2.0f / 3.0f ;
212 colorTime = flurry->fTime;
213 if (flurry->currentColorMode == whiteColorMode) {
217 } else if (flurry->currentColorMode == multiColorMode) {
221 } else if (flurry->currentColorMode == darkColorMode) {
226 if(flurry->currentColorMode < slowCyclicColorMode) {
227 colorTime = (flurry->currentColorMode / 6.0f) * cycleTime;
229 colorTime = flurry->fTime + flurry->flurryRandomSeed;
231 baseRed = 0.109375f * ((float) cos((colorTime+redPhaseShift)*colorRot)+1.0f);
232 baseGreen = 0.109375f * ((float) cos((colorTime+greenPhaseShift)*colorRot)+1.0f);
233 baseBlue = 0.109375f * ((float) cos((colorTime+bluePhaseShift)*colorRot)+1.0f);
237 old[i] = s->position[i];
240 cf = ((float) (cos(7.0*((flurry->fTime)*rotationsPerSecond))+cos(3.0*((flurry->fTime)*rotationsPerSecond))+cos(13.0*((flurry->fTime)*rotationsPerSecond))));
243 thisPointInRadians = 2.0 * PI * (double) s->mystery / (double) BIGMYSTERY;
245 s->color[0] = baseRed + 0.0625f * (0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle))) + (float) sin((7.0 * (thisPointInRadians + thisAngle))));
246 s->color[1] = baseGreen + 0.0625f * (0.5f + (float) sin(((thisPointInRadians) + thisAngle)));
247 s->color[2] = baseBlue + 0.0625f * (0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle))));
248 s->position[0] = fieldRange * cf * (float) cos(11.0 * (thisPointInRadians + (3.0*thisAngle)));
249 s->position[1] = fieldRange * cf * (float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle)));
250 s->position[2] = fieldRange * (float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle))));
252 rotation = thisAngle*0.501 + 5.01 * (double) s->mystery / (double) BIGMYSTERY;
255 tmpX1 = s->position[0] * cr - s->position[1] * sr;
256 tmpY1 = s->position[1] * cr + s->position[0] * sr;
257 tmpZ1 = s->position[2];
259 tmpX2 = tmpX1 * cr - tmpZ1 * sr;
261 tmpZ2 = tmpZ1 * cr + tmpX1 * sr;
264 tmpY3 = tmpY2 * cr - tmpZ2 * sr;
265 tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance;
267 rotation = thisAngle*2.501 + 85.01 * (double) s->mystery / (double) BIGMYSTERY;
270 tmpX4 = tmpX3 * cr - tmpY3 * sr;
271 tmpY4 = tmpY3 * cr + tmpX3 * sr;
274 s->position[0] = (float) tmpX4 + RandBell(5.0f*fieldCoherence);
275 s->position[1] = (float) tmpY4 + RandBell(5.0f*fieldCoherence);
276 s->position[2] = (float) tmpZ4 + RandBell(5.0f*fieldCoherence);
279 s->delta[i] = (s->position[i] - old[i])/flurry->fDeltaTime;