00001 #include <stdlib.h>
00002
00003 #include "v3d.h"
00004 #include "surf3d.h"
00005 #include "goom_tools.h"
00006 #include "goomconfig.h"
00007
00008 #define D 256.0f
00009
00010 #define nbgrid 6
00011 #define definitionx 15
00012 #define definitionz 45
00013
00014 static float cycle = 0.0f;
00015 static grid3d *grille[nbgrid];
00016 static float *vals;
00017
00018 void tentacle_free (void) {
00019 int tmp;
00020 free (vals);
00021 for (tmp=0;tmp<nbgrid;tmp++) {
00022 grid3d_free(&(grille[tmp]));
00023 }
00024 }
00025
00026 void tentacle_new (void) {
00027 int tmp;
00028
00029 v3d center = {0,-17.0,0};
00030 vals = malloc ((definitionx+20)*sizeof(float));
00031
00032 for (tmp=0;tmp<nbgrid;tmp++) {
00033 int x,z;
00034 z = 45+rand()%30;
00035 x = 85+rand()%5;
00036 center.z = z;
00037 grille[tmp] = grid3d_new (x,definitionx,z,definitionz+rand()%10,center);
00038 center.y += 8;
00039 }
00040 }
00041
00042 static inline unsigned char
00043 lighten (unsigned char value, float power)
00044 {
00045 int val = value;
00046 float t = (float) val * log10(power) / 2.0;
00047
00048 if (t > 0) {
00049 val = (int) t;
00050 if (val > 255)
00051 val = 255;
00052 if (val < 0)
00053 val = 0;
00054 return val;
00055 }
00056 else {
00057 return 0;
00058 }
00059 }
00060
00061 static void
00062 lightencolor (int *col, float power)
00063 {
00064 unsigned char *color;
00065
00066 color = (unsigned char *) col;
00067 *color = lighten (*color, power);
00068 color++;
00069 *color = lighten (*color, power);
00070 color++;
00071 *color = lighten (*color, power);
00072 color++;
00073 *color = lighten (*color, power);
00074 }
00075
00076
00077 #define ShiftRight(_x,_s) ((_x<0) ? -(-_x>>_s) : (_x>>_s))
00078
00079 static
00080 int evolutecolor (unsigned int src,unsigned int dest, unsigned int mask, unsigned int incr) {
00081 int color = src & (~mask);
00082 src &= mask;
00083 dest &= mask;
00084
00085 if ((src!=mask)
00086 &&(src<dest))
00087 src += incr;
00088
00089 if (src>dest)
00090 src -= incr;
00091 return (src&mask)|color;
00092 }
00093
00094 static void pretty_move (float cycle, float *dist,float *dist2, float *rotangle) {
00095 static float distt = 10.0f;
00096 static float distt2 = 0.0f;
00097 static float rot = 0.0f;
00098 static int happens = 0;
00099 float tmp;
00100 static int rotation = 0;
00101 static int lock = 0;
00102
00103 if (happens)
00104 happens -= 1;
00105 else if (lock == 0) {
00106 happens = iRAND(200)?0:100+iRAND(60);
00107 lock = happens * 3 / 2;
00108 }
00109 else lock --;
00110
00111
00112 tmp = happens?8.0f:0;
00113 *dist2 = distt2 = (tmp + 15.0f*distt2)/16.0f;
00114
00115 tmp = 30+D-90.0f*(1.0f+sin(cycle*19/20));
00116 if (happens)
00117 tmp *= 0.6f;
00118
00119 *dist = distt = (tmp + 3.0f*distt)/4.0f;
00120
00121 if (!happens){
00122 tmp = M_PI*sin(cycle)/32+3*M_PI/2;
00123 }
00124 else {
00125 rotation = iRAND(500)?rotation:iRAND(2);
00126 if (rotation)
00127 cycle *= 2.0f*M_PI;
00128 else
00129 cycle *= -1.0f*M_PI;
00130 tmp = cycle - (M_PI*2.0) * floor(cycle/(M_PI*2.0));
00131 }
00132
00133 if (abs(tmp-rot) > abs(tmp-(rot+2.0*M_PI))) {
00134 rot = (tmp + 15.0f*(rot+2*M_PI)) / 16.0f;
00135 if (rot>2.0*M_PI)
00136 rot -= 2.0*M_PI;
00137 *rotangle = rot;
00138 }
00139 else if (abs(tmp-rot) > abs(tmp-(rot-2.0*M_PI))) {
00140 rot = (tmp + 15.0f*(rot-2.0*M_PI)) / 16.0f;
00141 if (rot<0.0f)
00142 rot += 2.0*M_PI;
00143 *rotangle = rot;
00144 }
00145 else
00146 *rotangle = rot = (tmp + 15.0f*rot) / 16.0f;
00147 }
00148
00149 void tentacle_update(int *buf, int *back, int W, int H, short data[2][512], float rapport, int drawit) {
00150 int tmp;
00151 int tmp2;
00152
00153 static int colors[] = {
00154 (0x18<<(ROUGE*8))|(0x4c<<(VERT*8))|(0x2f<<(BLEU*8)),
00155 (0x48<<(ROUGE*8))|(0x2c<<(VERT*8))|(0x6f<<(BLEU*8)),
00156 (0x58<<(ROUGE*8))|(0x3c<<(VERT*8))|(0x0f<<(BLEU*8))};
00157
00158 static int col = (0x28<<(ROUGE*8))|(0x2c<<(VERT*8))|(0x5f<<(BLEU*8));
00159 static int dstcol = 0;
00160 static float lig = 1.15f;
00161 static float ligs = 0.1f;
00162
00163 int color;
00164 int colorlow;
00165
00166 float dist,dist2,rotangle;
00167
00168 if ((!drawit) && (ligs>0.0f))
00169 ligs = -ligs;
00170
00171 lig += ligs;
00172
00173 if (lig > 1.01f) {
00174 if ((lig>10.0f) | (lig<1.1f)) ligs = -ligs;
00175
00176 if ((lig<6.3f)&&(iRAND(30)==0))
00177 dstcol=iRAND(3);
00178
00179 col = evolutecolor(col,colors[dstcol],0xff,0x01);
00180 col = evolutecolor(col,colors[dstcol],0xff00,0x0100);
00181 col = evolutecolor(col,colors[dstcol],0xff0000,0x010000);
00182 col = evolutecolor(col,colors[dstcol],0xff000000,0x01000000);
00183
00184 color = col;
00185 colorlow = col;
00186
00187 lightencolor(&color,lig * 2.0f + 2.0f);
00188 lightencolor(&colorlow,(lig/3.0f)+0.67f);
00189
00190 rapport = 1.0f + 2.0f * (rapport - 1.0f);
00191 rapport *= 1.2f;
00192 if (rapport > 1.12f)
00193 rapport = 1.12f;
00194
00195 pretty_move (cycle,&dist,&dist2,&rotangle);
00196
00197 for (tmp=0;tmp<nbgrid;tmp++) {
00198 for (tmp2=0;tmp2<definitionx;tmp2++) {
00199 float val = (float)(ShiftRight(data[0][iRAND(511)],10)) * rapport;
00200 vals[tmp2] = val;
00201 }
00202
00203 grid3d_update (grille[tmp],rotangle, vals, dist2);
00204 }
00205 cycle+=0.01f;
00206 for (tmp=0;tmp<nbgrid;tmp++)
00207 grid3d_draw (grille[tmp],color,colorlow,dist,buf,back,W,H);
00208 }
00209 else {
00210 lig = 1.05f;
00211 if (ligs < 0.0f)
00212 ligs = -ligs;
00213 pretty_move (cycle,&dist,&dist2,&rotangle);
00214 cycle+=0.1f;
00215 if (cycle > 1000)
00216 cycle = 0;
00217 }
00218 }