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.
38 #define BIGMYSTERY 1800.0
39 #define MAXANGLES 16384
41 #define fieldCoherence 0
42 #define fieldSpeed 12.0f
43 #define fieldRange 1000.0f
49 for (int i
= 0; i
< 3; i
++)
50 s
->position
[i
] = RandFlt(-100.0, 100.0);
54 void DrawSpark(flurry_info_t
* info
, Spark
* s
)
56 const float black
[4] = {0.0f
, 0.0f
, 0.0f
, 1.0f
};
67 width
= 60000.0f
* info
->sys_glWidth
/ 1024.0f
;
70 sx
= s
->position
[0] * info
->sys_glWidth
/ z
+ info
->sys_glWidth
* 0.5f
;
71 sy
= s
->position
[1] * info
->sys_glWidth
/ z
+ info
->sys_glHeight
* 0.5f
;
78 glTranslatef(screenx
,screeny
,0.0f
);
80 glScalef(scale
,scale
,0.0f
);
81 for (int k
= 0; k
< 12; k
++) {
82 a
= ((float)(random() % 3600)) / 10.0f
;
83 glRotatef(a
,0.0f
,0.0f
,1.0f
);
84 glBegin(GL_QUAD_STRIP
);
86 glVertex2f(-3.0f
,0.0f
);
87 a
= 2.0f
+ (float) (random() & 255) * c
;
90 glVertex2f(0.0f
,0.0f
);
93 glVertex2f(3.0f
,0.0f
);
103 UpdateSparkColour(flurry_info_t
* info
, Spark
* s
)
105 const float rotationsPerSecond
= (float)(2.0 * M_PI
* fieldSpeed
107 double thisPointInRadians
;
108 double thisAngle
= info
->fTime
*rotationsPerSecond
;
110 float cycleTime
= 20.0f
;
113 float greenPhaseShift
;
114 float bluePhaseShift
;
120 if (info
->currentColorMode
== rainbowColorMode
)
122 else if (info
->currentColorMode
== tiedyeColorMode
)
124 else if (info
->currentColorMode
== cyclicColorMode
)
126 else if (info
->currentColorMode
== slowCyclicColorMode
)
129 colorRot
= (float)(2.0 * M_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
= info
->fTime
;
134 if (info
->currentColorMode
== whiteColorMode
) {
138 } else if (info
->currentColorMode
== multiColorMode
) {
142 } else if (info
->currentColorMode
== darkColorMode
) {
147 if (info
->currentColorMode
< slowCyclicColorMode
)
148 colorTime
= (info
->currentColorMode
/ 6.0f
) * cycleTime
;
150 colorTime
= info
->fTime
+ info
->randomSeed
;
153 * ((float)cos((colorTime
+ redPhaseShift
) * colorRot
) + 1.0f
);
154 baseGreen
= 0.109375f
155 * ((float)cos((colorTime
+ greenPhaseShift
) * colorRot
) + 1.0f
);
157 * ((float)cos((colorTime
+ bluePhaseShift
) * colorRot
) + 1.0f
);
160 cf
= ((float)(cos(7.0 * ((info
->fTime
) * rotationsPerSecond
))
161 + cos(3.0 * ((info
->fTime
) * rotationsPerSecond
))
162 + cos(13.0 * ((info
->fTime
) * rotationsPerSecond
))));
165 thisPointInRadians
= 2.0 * M_PI
* (double) s
->mystery
/ (double) BIGMYSTERY
;
167 s
->color
[0] = baseRed
+ 0.0625f
168 * (0.5f
+ (float)cos((15.0 * (thisPointInRadians
+ 3.0*thisAngle
)))
169 + (float)sin((7.0 * (thisPointInRadians
+ thisAngle
))));
170 s
->color
[1] = baseGreen
+ 0.0625f
171 * (0.5f
+ (float)sin(((thisPointInRadians
) + thisAngle
)));
172 s
->color
[2] = baseBlue
+ 0.0625f
173 * (0.5f
+ (float)cos((37.0 * (thisPointInRadians
+ thisAngle
))));
178 UpdateSpark(flurry_info_t
* info
, Spark
* s
)
180 const float rotationsPerSecond
= (float) (2.0*M_PI
*fieldSpeed
/MAXANGLES
);
181 double thisPointInRadians
;
182 double thisAngle
= info
->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 (info
->currentColorMode
== rainbowColorMode
)
205 else if (info
->currentColorMode
== tiedyeColorMode
)
207 else if (info
->currentColorMode
== cyclicColorMode
)
209 else if (info
->currentColorMode
== slowCyclicColorMode
)
212 colorRot
= (float)(2.0 * M_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
= info
->fTime
;
217 if (info
->currentColorMode
== whiteColorMode
) {
221 } else if (info
->currentColorMode
== multiColorMode
) {
225 } else if (info
->currentColorMode
== darkColorMode
) {
230 if (info
->currentColorMode
< slowCyclicColorMode
)
231 colorTime
= (info
->currentColorMode
/ 6.0f
) * cycleTime
;
233 colorTime
= info
->fTime
+ info
->randomSeed
;
236 * ((float)cos((colorTime
+ redPhaseShift
) * colorRot
) + 1.0f
);
237 baseGreen
= 0.109375f
238 * ((float)cos((colorTime
+ greenPhaseShift
) * colorRot
) + 1.0f
);
240 * ((float)cos((colorTime
+ bluePhaseShift
) * colorRot
) + 1.0f
);
243 for (int i
= 0; i
< 3; i
++)
244 old
[i
] = s
->position
[i
];
246 cf
= ((float)cos(7.0 * ((info
->fTime
) * rotationsPerSecond
)
247 + (float)cos(3.0 * ((info
->fTime
) * rotationsPerSecond
))
248 + (float)cos(13.0 * ((info
->fTime
) * rotationsPerSecond
))));
251 thisPointInRadians
= 2.0 * M_PI
* (double)s
->mystery
/ (double)BIGMYSTERY
;
253 s
->color
[0] = baseRed
+ 0.0625f
254 * (0.5f
+ (float) cos((15.0 * (thisPointInRadians
+ 3.0*thisAngle
)))
255 + (float) sin((7.0 * (thisPointInRadians
+ thisAngle
))));
256 s
->color
[1] = baseGreen
+ 0.0625f
257 * (0.5f
+ (float) sin(((thisPointInRadians
) + thisAngle
)));
258 s
->color
[2] = baseBlue
+ 0.0625f
259 * (0.5f
+ (float) cos((37.0 * (thisPointInRadians
+ thisAngle
))));
260 s
->position
[0] = fieldRange
* cf
261 * (float)cos(11.0 * (thisPointInRadians
+ (3.0*thisAngle
)));
262 s
->position
[1] = fieldRange
* cf
*
263 (float) sin(12.0 * (thisPointInRadians
+ (4.0*thisAngle
)));
264 s
->position
[2] = fieldRange
*
265 (float) cos((23.0 * (thisPointInRadians
+ (12.0*thisAngle
))));
267 rotation
= thisAngle
* 0.501 + 5.01 * (double)s
->mystery
268 / (double)BIGMYSTERY
;
271 tmpX1
= s
->position
[0] * cr
- s
->position
[1] * sr
;
272 tmpY1
= s
->position
[1] * cr
+ s
->position
[0] * sr
;
273 tmpZ1
= s
->position
[2];
275 tmpX2
= tmpX1
* cr
- tmpZ1
* sr
;
277 tmpZ2
= tmpZ1
* cr
+ tmpX1
* sr
;
280 tmpY3
= tmpY2
* cr
- tmpZ2
* sr
;
281 tmpZ3
= tmpZ2
* cr
+ tmpY2
* sr
+ seraphDistance
;
283 rotation
= thisAngle
* 2.501 + 85.01 * (double)s
->mystery
284 / (double)BIGMYSTERY
;
287 tmpX4
= tmpX3
* cr
- tmpY3
* sr
;
288 tmpY4
= tmpY3
* cr
+ tmpX3
* sr
;
291 s
->position
[0] = (float) tmpX4
+ RandBell(5.0f
*fieldCoherence
);
292 s
->position
[1] = (float) tmpY4
+ RandBell(5.0f
*fieldCoherence
);
293 s
->position
[2] = (float) tmpZ4
+ RandBell(5.0f
*fieldCoherence
);
295 for (int i
= 0;i
< 3; i
++)
296 s
->delta
[i
] = (s
->position
[i
] - old
[i
]) / info
->fDeltaTime
;