2 * Copyright (C) <2003> iOS-Software
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include "goom_tools.h"
24 #include "goom_config.h"
25 #include "goom_plugin_info.h"
26 #include "tentacle3d.h"
31 #define definitionx 15
32 #define definitionz 45
34 typedef struct _TENTACLE_FX_DATA
36 PluginParam enabled_bp;
37 PluginParameters params;
40 grid3d *grille[nbgrid];
43 #define NB_TENTACLE_COLORS 4
44 int colors[NB_TENTACLE_COLORS];
51 /* statics from pretty_move */
54 float rot; /* entre 0 et 2 * G_PI */
60 static void tentacle_new (TentacleFXData * data);
61 static void tentacle_update (PluginInfo * goomInfo, Pixel * buf, Pixel * back,
62 int W, int H, short[2][512], float, int drawit, TentacleFXData * data);
63 static void tentacle_free (TentacleFXData * data);
66 * VisualFX wrapper for the tentacles
70 tentacle_fx_init (VisualFX * _this, PluginInfo * info)
73 TentacleFXData *data = (TentacleFXData *) malloc (sizeof (TentacleFXData));
75 secure_b_param (&data->enabled_bp, "Enabled", 1);
76 plugin_parameters (&data->params, "3D Tentacles", 1);
77 data->params.params[0] = &data->enabled_bp;
81 (0x28 << (ROUGE * 8)) | (0x2c << (VERT * 8)) | (0x5f << (BLEU * 8));
88 data->rot = 0.0f; /* entre 0 et 2 * G_PI */
94 (0x18 << (ROUGE * 8)) | (0x4c << (VERT * 8)) | (0x2f << (BLEU * 8));
96 (0x48 << (ROUGE * 8)) | (0x2c << (VERT * 8)) | (0x6f << (BLEU * 8));
98 (0x58 << (ROUGE * 8)) | (0x3c << (VERT * 8)) | (0x0f << (BLEU * 8));
100 (0x87 << (ROUGE * 8)) | (0x55 << (VERT * 8)) | (0x74 << (BLEU * 8));
103 _this->params = &data->params;
104 _this->fx_data = (void *) data;
108 tentacle_fx_apply (VisualFX * _this, Pixel * src, Pixel * dest,
109 PluginInfo * goomInfo)
111 TentacleFXData *data = (TentacleFXData *) _this->fx_data;
113 if (BVAL (data->enabled_bp)) {
114 tentacle_update (goomInfo, dest, src, goomInfo->screen.width,
115 goomInfo->screen.height, goomInfo->sound.samples,
116 (float) goomInfo->sound.accelvar,
117 goomInfo->curGState->drawTentacle, data);
122 tentacle_fx_free (VisualFX * _this)
124 tentacle_free ((TentacleFXData *) _this->fx_data);
125 free (_this->fx_data);
129 tentacle_fx_create (VisualFX * fx)
131 fx->init = tentacle_fx_init;
132 fx->apply = tentacle_fx_apply;
133 fx->free = tentacle_fx_free;
141 tentacle_free (TentacleFXData * data)
146 for (tmp = 0; tmp < nbgrid; tmp++)
147 grid3d_free (data->grille[tmp]);
150 goom_plugin_parameters_free (&data->params);
154 tentacle_new (TentacleFXData * data)
158 v3d center = { 0, -17.0, 0 };
159 data->vals = (float *) malloc ((definitionx + 20) * sizeof (float));
161 for (tmp = 0; tmp < nbgrid; tmp++) {
164 z = 45 + rand () % 30;
165 x = 85 + rand () % 5;
168 grid3d_new (x, definitionx, z, definitionz + rand () % 10, center);
173 static inline unsigned char
174 lighten (unsigned char value, float power)
177 float t = (float) val * log10 (power) / 2.0;
180 val = (int) t; /* (32.0f * log (t)); */
192 lightencolor (int *col, float power)
194 unsigned char *color;
196 color = (unsigned char *) col;
197 *color = lighten (*color, power);
199 *color = lighten (*color, power);
201 *color = lighten (*color, power);
203 *color = lighten (*color, power);
206 /* retourne x>>s , en testant le signe de x */
207 #define ShiftRight(_x,_s) ((_x<0) ? -(-_x>>_s) : (_x>>_s))
210 evolutecolor (unsigned int src, unsigned int dest,
211 unsigned int mask, unsigned int incr)
214 int color = src & (~mask);
225 return (src & mask) | color;
229 pretty_move (PluginInfo * goomInfo, float cycle, float *dist, float *dist2,
230 float *rotangle, TentacleFXData * fx_data)
235 /* many magic numbers here... I don't really like that. */
236 if (fx_data->happens)
237 fx_data->happens -= 1;
238 else if (fx_data->lock == 0) {
240 goom_irand (goomInfo->gRandom,
241 200) ? 0 : 100 + goom_irand (goomInfo->gRandom, 60);
242 fx_data->lock = fx_data->happens * 3 / 2;
246 tmp = fx_data->happens ? 8.0f : 0;
247 *dist2 = fx_data->distt2 = (tmp + 15.0f * fx_data->distt2) / 16.0f;
249 tmp = 30 + D - 90.0f * (1.0f + sin (cycle * 19 / 20));
250 if (fx_data->happens)
253 *dist = fx_data->distt = (tmp + 3.0f * fx_data->distt) / 4.0f;
255 if (!fx_data->happens) {
256 tmp = G_PI * sin (cycle) / 32 + 3 * G_PI / 2;
259 goom_irand (goomInfo->gRandom,
260 500) ? fx_data->rotation : goom_irand (goomInfo->gRandom, 2);
261 if (fx_data->rotation)
262 cycle *= 2.0f * G_PI;
264 cycle *= -1.0f * G_PI;
265 tmp = cycle - (G_PI * 2.0) * floor (cycle / (G_PI * 2.0));
268 if (fabs (tmp - fx_data->rot) > fabs (tmp - (fx_data->rot + 2.0 * G_PI))) {
269 fx_data->rot = (tmp + 15.0f * (fx_data->rot + 2 * G_PI)) / 16.0f;
270 if (fx_data->rot > 2.0 * G_PI)
271 fx_data->rot -= 2.0 * G_PI;
272 *rotangle = fx_data->rot;
273 } else if (fabs (tmp - fx_data->rot) >
274 fabs (tmp - (fx_data->rot - 2.0 * G_PI))) {
275 fx_data->rot = (tmp + 15.0f * (fx_data->rot - 2.0 * G_PI)) / 16.0f;
276 if (fx_data->rot < 0.0f)
277 fx_data->rot += 2.0 * G_PI;
278 *rotangle = fx_data->rot;
280 *rotangle = fx_data->rot = (tmp + 15.0f * fx_data->rot) / 16.0f;
284 tentacle_update (PluginInfo * goomInfo, Pixel * buf, Pixel * back, int W, int H,
285 short data[2][512], float rapport, int drawit, TentacleFXData * fx_data)
294 float dist, dist2, rotangle;
296 if ((!drawit) && (fx_data->ligs > 0.0f))
297 fx_data->ligs = -fx_data->ligs;
299 fx_data->lig += fx_data->ligs;
301 if (fx_data->lig > 1.01f) {
302 if ((fx_data->lig > 10.0f) | (fx_data->lig < 1.1f))
303 fx_data->ligs = -fx_data->ligs;
305 if ((fx_data->lig < 6.3f) && (goom_irand (goomInfo->gRandom, 30) == 0))
306 fx_data->dstcol = goom_irand (goomInfo->gRandom, NB_TENTACLE_COLORS);
309 evolutecolor (fx_data->col, fx_data->colors[fx_data->dstcol], 0xff,
312 evolutecolor (fx_data->col, fx_data->colors[fx_data->dstcol], 0xff00,
315 evolutecolor (fx_data->col, fx_data->colors[fx_data->dstcol], 0xff0000,
318 evolutecolor (fx_data->col, fx_data->colors[fx_data->dstcol],
319 0xff000000, 0x01000000);
321 color = fx_data->col;
322 colorlow = fx_data->col;
324 lightencolor (&color, fx_data->lig * 2.0f + 2.0f);
325 lightencolor (&colorlow, (fx_data->lig / 3.0f) + 0.67f);
327 rapport = 1.0f + 2.0f * (rapport - 1.0f);
332 pretty_move (goomInfo, fx_data->cycle, &dist, &dist2, &rotangle, fx_data);
334 for (tmp = 0; tmp < nbgrid; tmp++) {
335 for (tmp2 = 0; tmp2 < definitionx; tmp2++) {
337 (float) (ShiftRight (data[0][goom_irand (goomInfo->gRandom, 511)],
340 fx_data->vals[tmp2] = val;
343 grid3d_update (fx_data->grille[tmp], rotangle, fx_data->vals, dist2);
345 fx_data->cycle += 0.01f;
346 for (tmp = 0; tmp < nbgrid; tmp++)
347 grid3d_draw (goomInfo, fx_data->grille[tmp], color, colorlow, dist, buf,
350 fx_data->lig = 1.05f;
351 if (fx_data->ligs < 0.0f)
352 fx_data->ligs = -fx_data->ligs;
353 pretty_move (goomInfo, fx_data->cycle, &dist, &dist2, &rotangle, fx_data);
354 fx_data->cycle += 0.1f;
355 if (fx_data->cycle > 1000)