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 /* -*- Mode: C; tab-width: 4 c-basic-offset: 4 indent-tabs-mode: t -*- */
47 #include "gltrackball.h"
49 typedef struct _global_info_t global_info_t;
50 typedef struct _flurry_info_t flurry_info_t;
52 #define sqr(X) ((X) * (X))
53 #define PI 3.14159265358979323846f
54 #define DEG2RAD(X) (PI*(X)/180.0)
55 #define RAD2DEG(X) ((X)*180.0/PI)
56 #define rnd() (frand(1.0))
58 /* fabs: Absolute function. */
60 /* #define abs(a) ( (a) > 0 ? (a) : -(a) ) */
62 /* Force sign clamping to (-1;0;1) */
63 #define sgn(a) ((a)<0?-1:((a)?1:0))
65 /* used to compute the min and max of two expresions */
66 #define MIN_(a, b) (((a) < (b)) ? (a) : (b))
67 #define MAX_(a, b) (((a) > (b)) ? (a) : (b))
82 vector unsigned int v;
87 typedef struct SmokeParticleV
89 floatToVector color[4];
90 floatToVector position[3];
91 floatToVector oldposition[3];
92 floatToVector delta[3];
95 intToVector animFrame;
98 #define NUMSMOKEPARTICLES 3600
100 typedef struct SmokeV
102 SmokeParticleV p[NUMSMOKEPARTICLES/4];
105 float lastParticleTime;
109 floatToVector seraphimVertices[NUMSMOKEPARTICLES*2+1];
110 floatToVector seraphimColors[NUMSMOKEPARTICLES*4+1];
111 float seraphimTextures[NUMSMOKEPARTICLES*2*4];
114 void InitSmoke(SmokeV *s);
116 void UpdateSmoke_ScalarBase(global_info_t *global, flurry_info_t *flurry, SmokeV *s);
119 void UpdateSmoke_ScalarFrsqrte(global_info_t *global, flurry_info_t *flurry, SmokeV *s);
122 void UpdateSmoke_VectorBase(global_info_t *global, flurry_info_t *flurry, SmokeV *s);
123 void UpdateSmoke_VectorUnrolled(global_info_t *global, flurry_info_t *flurry, SmokeV *s);
127 void DrawSmoke_Scalar(global_info_t *global, flurry_info_t *flurry, SmokeV *s, float);
128 void DrawSmoke_Vector(global_info_t *global, flurry_info_t *flurry, SmokeV *s, float);
138 void UpdateStar(global_info_t *global, flurry_info_t *flurry, Star *s);
139 void InitStar(Star *s);
149 void UpdateSparkColour(global_info_t *info, flurry_info_t *flurry, Spark *s);
150 void InitSpark(Spark *s);
151 void UpdateSpark(global_info_t *info, flurry_info_t *flurry, Spark *s);
152 void DrawSpark(global_info_t *info, flurry_info_t *flurry, Spark *s);
154 /* #define FastDistance2D(x,y) hypot(x,y) */
156 /* UInt8 sys_glBPP=32; */
157 /* int SSMODE = FALSE; */
158 /* int currentVideoMode = 0; */
159 /* int cohesiveness = 7; */
160 /* int fieldStrength; */
161 /* int colorCoherence = 7; */
162 /* int fieldIncoherence = 0; */
163 /* int ifieldSpeed = 120; */
165 static inline float FastDistance2D(float x, float y)
167 /* this function computes the distance from 0,0 to x,y with ~3.5% error */
169 /* first compute the absolute value of x,y */
170 x = (x < 0.0f) ? -x : x;
171 y = (y < 0.0f) ? -y : y;
173 /* compute the minimum of x,y */
176 /* return the distance */
177 return(x+y-(mn*0.5f)-(mn*0.25f)+(mn*0.0625f));
183 static vector float FastDistance2DV(vector float x, vector float y) {
184 vector float mn, temp;
190 temp = vec_madd(mn, (vector float)(-0.6875), temp);
197 #define RandFlt(min, max) ((min) + frand((max) - (min)))
199 #define RandBell(scale) ((scale) * (-(frand(.5) + frand(.5) + frand(.5))))
201 extern GLuint theTexture;
203 void MakeTexture(void);
205 #define OPT_MODE_SCALAR_BASE 0x0
209 #define OPT_MODE_SCALAR_FRSQRTE 0x1
213 #define OPT_MODE_VECTOR_SIMPLE 0x2
214 #define OPT_MODE_VECTOR_UNROLLED 0x3
218 typedef enum _ColorModes
235 #define gravity 1500000.0f
237 #define incohesion 0.07f
238 #define colorIncoherence 0.15f
239 #define streamSpeed 450.0
240 #define fieldCoherence 0
241 #define fieldSpeed 12.0f
242 #define numParticles 250
244 #define seraphDistance 2000.0f
245 #define streamSize 25000.0f
246 #define fieldRange 1000.0f
247 #define streamBias 7.0f
249 #define MAX_SPARKS 64
251 struct _flurry_info_t {
253 ColorModes currentColorMode;
256 Spark *spark[MAX_SPARKS];
257 float streamExpansion;
259 double flurryRandomSeed;
268 struct _global_info_t {
270 GLXContext *glx_context;
277 flurry_info_t *flurry;
280 #define kNumSpectrumEntries 512
283 double TimeInSecondsSinceStart(void);
285 #endif /* Include/Define */