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