5 #include "goom_tools.h"
6 #include "goom_config.h"
7 #include "goom_plugin_info.h"
8 #include "tentacle3d.h"
13 #define definitionx 15
14 #define definitionz 45
16 typedef struct _TENTACLE_FX_DATA
18 PluginParam enabled_bp;
19 PluginParameters params;
22 grid3d *grille[nbgrid];
25 #define NB_TENTACLE_COLORS 4
26 int colors[NB_TENTACLE_COLORS];
33 /* statics from pretty_move */
36 float rot; /* entre 0 et 2 * M_PI */
42 static void tentacle_new (TentacleFXData * data);
43 static void tentacle_update (PluginInfo * goomInfo, Pixel * buf, Pixel * back,
44 int W, int H, short[2][512], float, int drawit, TentacleFXData * data);
45 static void tentacle_free (TentacleFXData * data);
48 * VisualFX wrapper for the tentacles
52 tentacle_fx_init (VisualFX * _this, PluginInfo * info)
55 TentacleFXData *data = (TentacleFXData *) malloc (sizeof (TentacleFXData));
57 data->enabled_bp = secure_b_param ("Enabled", 1);
58 data->params = plugin_parameters ("3D Tentacles", 1);
59 data->params.params[0] = &data->enabled_bp;
63 (0x28 << (ROUGE * 8)) | (0x2c << (VERT * 8)) | (0x5f << (BLEU * 8));
70 data->rot = 0.0f; /* entre 0 et 2 * M_PI */
76 (0x18 << (ROUGE * 8)) | (0x4c << (VERT * 8)) | (0x2f << (BLEU * 8));
78 (0x48 << (ROUGE * 8)) | (0x2c << (VERT * 8)) | (0x6f << (BLEU * 8));
80 (0x58 << (ROUGE * 8)) | (0x3c << (VERT * 8)) | (0x0f << (BLEU * 8));
82 (0x87 << (ROUGE * 8)) | (0x55 << (VERT * 8)) | (0x74 << (BLEU * 8));
85 _this->params = &data->params;
86 _this->fx_data = (void *) data;
90 tentacle_fx_apply (VisualFX * _this, Pixel * src, Pixel * dest,
91 PluginInfo * goomInfo)
93 TentacleFXData *data = (TentacleFXData *) _this->fx_data;
95 if (BVAL (data->enabled_bp)) {
96 tentacle_update (goomInfo, dest, src, goomInfo->screen.width,
97 goomInfo->screen.height, goomInfo->sound.samples,
98 (float) goomInfo->sound.accelvar,
99 goomInfo->curGState->drawTentacle, data);
104 tentacle_fx_free (VisualFX * _this)
106 tentacle_free ((TentacleFXData *) _this->fx_data);
107 free (_this->fx_data);
111 tentacle_fx_create (void)
115 fx.init = tentacle_fx_init;
116 fx.apply = tentacle_fx_apply;
117 fx.free = tentacle_fx_free;
124 tentacle_free (TentacleFXData * data)
126 /* TODO : un vrai FREE GRID!! */
131 tentacle_new (TentacleFXData * data)
135 v3d center = { 0, -17.0, 0 };
136 data->vals = (float *) malloc ((definitionx + 20) * sizeof (float));
138 for (tmp = 0; tmp < nbgrid; tmp++) {
141 z = 45 + rand () % 30;
142 x = 85 + rand () % 5;
145 grid3d_new (x, definitionx, z, definitionz + rand () % 10, center);
150 static inline unsigned char
151 lighten (unsigned char value, float power)
154 float t = (float) val * log10 (power) / 2.0;
157 val = (int) t; /* (32.0f * log (t)); */
169 lightencolor (int *col, float power)
171 unsigned char *color;
173 color = (unsigned char *) col;
174 *color = lighten (*color, power);
176 *color = lighten (*color, power);
178 *color = lighten (*color, power);
180 *color = lighten (*color, power);
183 /* retourne x>>s , en testant le signe de x */
184 #define ShiftRight(_x,_s) ((_x<0) ? -(-_x>>_s) : (_x>>_s))
187 evolutecolor (unsigned int src, unsigned int dest,
188 unsigned int mask, unsigned int incr)
191 int color = src & (~mask);
202 return (src & mask) | color;
206 pretty_move (PluginInfo * goomInfo, float cycle, float *dist, float *dist2,
207 float *rotangle, TentacleFXData * fx_data)
212 /* many magic numbers here... I don't really like that. */
213 if (fx_data->happens)
214 fx_data->happens -= 1;
215 else if (fx_data->lock == 0) {
217 goom_irand (goomInfo->gRandom,
218 200) ? 0 : 100 + goom_irand (goomInfo->gRandom, 60);
219 fx_data->lock = fx_data->happens * 3 / 2;
223 tmp = fx_data->happens ? 8.0f : 0;
224 *dist2 = fx_data->distt2 = (tmp + 15.0f * fx_data->distt2) / 16.0f;
226 tmp = 30 + D - 90.0f * (1.0f + sin (cycle * 19 / 20));
227 if (fx_data->happens)
230 *dist = fx_data->distt = (tmp + 3.0f * fx_data->distt) / 4.0f;
232 if (!fx_data->happens) {
233 tmp = M_PI * sin (cycle) / 32 + 3 * M_PI / 2;
236 goom_irand (goomInfo->gRandom,
237 500) ? fx_data->rotation : goom_irand (goomInfo->gRandom, 2);
238 if (fx_data->rotation)
239 cycle *= 2.0f * M_PI;
241 cycle *= -1.0f * M_PI;
242 tmp = cycle - (M_PI * 2.0) * floor (cycle / (M_PI * 2.0));
245 if (abs (tmp - fx_data->rot) > abs (tmp - (fx_data->rot + 2.0 * M_PI))) {
246 fx_data->rot = (tmp + 15.0f * (fx_data->rot + 2 * M_PI)) / 16.0f;
247 if (fx_data->rot > 2.0 * M_PI)
248 fx_data->rot -= 2.0 * M_PI;
249 *rotangle = fx_data->rot;
250 } else if (abs (tmp - fx_data->rot) > abs (tmp - (fx_data->rot - 2.0 * M_PI))) {
251 fx_data->rot = (tmp + 15.0f * (fx_data->rot - 2.0 * M_PI)) / 16.0f;
252 if (fx_data->rot < 0.0f)
253 fx_data->rot += 2.0 * M_PI;
254 *rotangle = fx_data->rot;
256 *rotangle = fx_data->rot = (tmp + 15.0f * fx_data->rot) / 16.0f;
260 tentacle_update (PluginInfo * goomInfo, Pixel * buf, Pixel * back, int W, int H,
261 short data[2][512], float rapport, int drawit, TentacleFXData * fx_data)
270 float dist, dist2, rotangle;
272 if ((!drawit) && (fx_data->ligs > 0.0f))
273 fx_data->ligs = -fx_data->ligs;
275 fx_data->lig += fx_data->ligs;
277 if (fx_data->lig > 1.01f) {
278 if ((fx_data->lig > 10.0f) | (fx_data->lig < 1.1f))
279 fx_data->ligs = -fx_data->ligs;
281 if ((fx_data->lig < 6.3f) && (goom_irand (goomInfo->gRandom, 30) == 0))
282 fx_data->dstcol = goom_irand (goomInfo->gRandom, NB_TENTACLE_COLORS);
285 evolutecolor (fx_data->col, fx_data->colors[fx_data->dstcol], 0xff,
288 evolutecolor (fx_data->col, fx_data->colors[fx_data->dstcol], 0xff00,
291 evolutecolor (fx_data->col, fx_data->colors[fx_data->dstcol], 0xff0000,
294 evolutecolor (fx_data->col, fx_data->colors[fx_data->dstcol],
295 0xff000000, 0x01000000);
297 color = fx_data->col;
298 colorlow = fx_data->col;
300 lightencolor (&color, fx_data->lig * 2.0f + 2.0f);
301 lightencolor (&colorlow, (fx_data->lig / 3.0f) + 0.67f);
303 rapport = 1.0f + 2.0f * (rapport - 1.0f);
308 pretty_move (goomInfo, fx_data->cycle, &dist, &dist2, &rotangle, fx_data);
310 for (tmp = 0; tmp < nbgrid; tmp++) {
311 for (tmp2 = 0; tmp2 < definitionx; tmp2++) {
313 (float) (ShiftRight (data[0][goom_irand (goomInfo->gRandom, 511)],
315 fx_data->vals[tmp2] = val;
318 grid3d_update (fx_data->grille[tmp], rotangle, fx_data->vals, dist2);
320 fx_data->cycle += 0.01f;
321 for (tmp = 0; tmp < nbgrid; tmp++)
322 grid3d_draw (goomInfo, fx_data->grille[tmp], color, colorlow, dist, buf,
325 fx_data->lig = 1.05f;
326 if (fx_data->ligs < 0.0f)
327 fx_data->ligs = -fx_data->ligs;
328 pretty_move (goomInfo, fx_data->cycle, &dist, &dist2, &rotangle, fx_data);
329 fx_data->cycle += 0.1f;
330 if (fx_data->cycle > 1000)