2 #include "goom_plugin_info.h"
3 #include "goom_tools.h"
7 /* TODO:-- FAIRE PROPREMENT... BOAH... */
10 /*static const int colval[] = {
29 static const int colval[] = {
48 /* The different modes of the visual FX.
49 * Put this values on fx_mode */
50 #define FIREWORKS_FX 0
55 typedef struct _FS_STAR
63 typedef struct _FS_DATA
75 PluginParam min_age_p;
76 PluginParam max_age_p;
77 PluginParam nbStars_p;
78 PluginParam nbStars_limit_p;
79 PluginParam fx_mode_p;
81 PluginParameters params;
85 fs_init (VisualFX * _this, PluginInfo * info)
90 data = (FSData *) malloc (sizeof (FSData));
92 data->fx_mode = FIREWORKS_FX;
93 data->maxStars = 4096;
94 data->stars = (Star *) malloc (data->maxStars * sizeof (Star));
97 data->max_age_p = secure_i_param ("Fireworks Smallest Bombs");
98 IVAL (data->max_age_p) = 80;
99 IMIN (data->max_age_p) = 0;
100 IMAX (data->max_age_p) = 100;
101 ISTEP (data->max_age_p) = 1;
103 data->min_age_p = secure_i_param ("Fireworks Largest Bombs");
104 IVAL (data->min_age_p) = 99;
105 IMIN (data->min_age_p) = 0;
106 IMAX (data->min_age_p) = 100;
107 ISTEP (data->min_age_p) = 1;
109 data->nbStars_limit_p = secure_i_param ("Max Number of Particules");
110 IVAL (data->nbStars_limit_p) = 512;
111 IMIN (data->nbStars_limit_p) = 0;
112 IMAX (data->nbStars_limit_p) = data->maxStars;
113 ISTEP (data->nbStars_limit_p) = 64;
115 data->fx_mode_p = secure_i_param ("FX Mode");
116 IVAL (data->fx_mode_p) = data->fx_mode;
117 IMIN (data->fx_mode_p) = 1;
118 IMAX (data->fx_mode_p) = 3;
119 ISTEP (data->fx_mode_p) = 1;
121 data->nbStars_p = secure_f_feedback ("Number of Particules (% of Max)");
123 data->params = plugin_parameters ("Particule System", 7);
124 data->params.params[0] = &data->fx_mode_p;
125 data->params.params[1] = &data->nbStars_limit_p;
126 data->params.params[2] = 0;
127 data->params.params[3] = &data->min_age_p;
128 data->params.params[4] = &data->max_age_p;
129 data->params.params[5] = 0;
130 data->params.params[6] = &data->nbStars_p;
132 _this->params = &data->params;
133 _this->fx_data = (void *) data;
137 fs_free (VisualFX * _this)
139 FSData *data = (FSData *) _this->fx_data;
141 goom_plugin_parameters_free (&data->params);
144 free (_this->fx_data);
149 * Cree une nouvelle 'bombe', c'est a dire une particule appartenant a une fusee d'artifice.
152 addABomb (FSData * fs, int mx, int my, float radius, float vage, float gravity,
160 if (fs->nbStars >= fs->maxStars)
167 ro = radius * (float) goom_irand (info->gRandom, 100) / 100.0f;
168 ro *= (float) goom_irand (info->gRandom, 100) / 100.0f + 1.0f;
169 theta = goom_irand (info->gRandom, 256);
171 fs->stars[i].vx = ro * cos256[theta];
172 fs->stars[i].vy = -0.2f + ro * sin256[theta];
175 fs->stars[i].ay = gravity;
177 fs->stars[i].age = 0;
178 if (vage < fs->min_age)
180 fs->stars[i].vage = vage;
185 * Met a jour la position et vitesse d'une particule.
188 updateStar (Star * s)
199 * Ajoute de nouvelles particules au moment d'un evenement sonore.
202 fs_sound_event_occured (VisualFX * _this, PluginInfo * info)
205 FSData *data = (FSData *) _this->fx_data;
208 int max = (int) ((1.0f + info->sound.goomPower) * goom_irand (info->gRandom,
211 (1.0f + info->sound.goomPower) * (float) (goom_irand (info->gRandom,
215 float vage, gravity = 0.02f;
217 switch (data->fx_mode) {
223 mx = goom_irand (info->gRandom, info->screen.width);
224 my = goom_irand (info->gRandom, info->screen.height);
225 dx = (mx - info->screen.width / 2);
226 dy = (my - info->screen.height / 2);
227 } while (dx * dx + dy * dy <
228 (info->screen.height / 2) * (info->screen.height / 2));
229 vage = data->max_age * (1.0f - info->sound.goomPower);
233 mx = goom_irand (info->gRandom, info->screen.width);
234 if (mx > info->screen.width / 2)
235 mx = info->screen.width;
238 my = -(info->screen.height / 3) - goom_irand (info->gRandom,
239 info->screen.width / 3);
244 my = info->screen.height + 2;
247 mx = info->screen.width / 2;
252 /* my = i R A N D (info->screen.height); vage = 0.01f; */
255 radius *= info->screen.height / 200.0f; /* why 200 ? because the FX was developped on 320x200 */
256 max *= info->screen.height / 200.0f;
258 if (info->sound.timeSinceLastBigGoom < 1) {
262 for (i = 0; i < max; ++i)
263 addABomb (data, mx, my, radius, vage, gravity, info);
268 * Main methode of the FX.
271 fs_apply (VisualFX * _this, Pixel * src, Pixel * dest, PluginInfo * info)
276 FSData *data = (FSData *) _this->fx_data;
278 /* Get the new parameters values */
279 data->min_age = 1.0f - (float) IVAL (data->min_age_p) / 100.0f;
280 data->max_age = 1.0f - (float) IVAL (data->max_age_p) / 100.0f;
281 FVAL (data->nbStars_p) = (float) data->nbStars / (float) data->maxStars;
282 data->nbStars_p.change_listener (&data->nbStars_p);
283 data->maxStars = IVAL (data->nbStars_limit_p);
284 data->fx_mode = IVAL (data->fx_mode_p);
286 /* look for events */
287 if (info->sound.timeSinceLastGoom < 1) {
288 fs_sound_event_occured (_this, info);
289 if (goom_irand (info->gRandom, 20) == 1) {
290 IVAL (data->fx_mode_p) = goom_irand (info->gRandom, (LAST_FX * 3));
291 data->fx_mode_p.change_listener (&data->fx_mode_p);
295 /* update particules */
296 for (i = 0; i < data->nbStars; ++i) {
297 updateStar (&data->stars[i]);
300 if (data->stars[i].age >= NCOL)
303 /* choose the color of the particule */
304 col = colval[(int) data->stars[i].age];
306 /* draws the particule */
307 info->methods.draw_line (dest, (int) data->stars[i].x,
308 (int) data->stars[i].y,
309 (int) (data->stars[i].x - data->stars[i].vx * 6),
310 (int) (data->stars[i].y - data->stars[i].vy * 6), col,
311 (int) info->screen.width, (int) info->screen.height);
312 info->methods.draw_line (dest, (int) data->stars[i].x,
313 (int) data->stars[i].y,
314 (int) (data->stars[i].x - data->stars[i].vx * 2),
315 (int) (data->stars[i].y - data->stars[i].vy * 2), col,
316 (int) info->screen.width, (int) info->screen.height);
319 /* look for dead particules */
320 for (i = 0; i < data->nbStars;) {
322 if ((data->stars[i].x > info->screen.width + 64)
323 || ((data->stars[i].vy >= 0)
324 && (data->stars[i].y - 16 * data->stars[i].vy >
325 info->screen.height))
326 || (data->stars[i].x < -64)
327 || (data->stars[i].age >= NCOL)) {
328 data->stars[i] = data->stars[data->nbStars - 1];
336 flying_star_create (void)