MythTV  master
tentacle3d.cpp
Go to the documentation of this file.
1 #include <cstdlib>
2 
3 #include "v3d.h"
4 #include "surf3d.h"
5 #include "goom_tools.h"
6 #include "goomconfig.h"
7 
8 #define D 256.0F
9 
10 #define nbgrid 6
11 #define definitionx 15
12 #define definitionz 45
13 
14 static float cycle = 0.0F;
15 static grid3d *grille[nbgrid];
16 static float *vals;
17 
18 /* Prototypes to keep gcc from spewing warnings */
19 void tentacle_free (void);
20 void tentacle_new (void);
21 void tentacle_update(int *buf, int *back, int W, int H, short data[2][512], float rapport, int drawit);
22 
23 void tentacle_free (void) {
24  free (vals);
25  for (auto & tmp : grille) {
26  grid3d_free(&tmp);
27  }
28 }
29 
30 void tentacle_new (void) {
31  v3d center = {0,-17.0,0};
32  vals = (float*)malloc ((definitionx+20)*sizeof(float));
33 
34  for (auto & tmp : grille) {
35  // Pseudo-random is good enough. Don't need a true random.
36  // NOLINTNEXTLINE(cert-msc30-c,cert-msc50-cpp)
37  int z = 45+rand()%30;
38  // NOLINTNEXTLINE(cert-msc30-c,cert-msc50-cpp)
39  int x = 85+rand()%5;
40  center.z = z;
41  // NOLINTNEXTLINE(cert-msc30-c,cert-msc50-cpp)
42  tmp = grid3d_new (x,definitionx,z,definitionz+rand()%10,center);
43  center.y += 8;
44  }
45 }
46 
47 static inline unsigned char
48 lighten (unsigned char value, float power)
49 {
50  int val = value;
51  float t = (float) val * log10f(power) / 2.0F;
52 
53  if (t > 0) {
54  val = (int) t; // (32.0F * log (t));
55  if (val > 255)
56  val = 255;
57  if (val < 0)
58  val = 0;
59  return val;
60  }
61  return 0;
62 }
63 
64 static void
65 lightencolor (int *col, float power)
66 {
67  auto *color = (unsigned char *) col;
68  *color = lighten (*color, power);
69  color++;
70  *color = lighten (*color, power);
71  color++;
72  *color = lighten (*color, power);
73  color++;
74  *color = lighten (*color, power);
75 }
76 
77 // retourne x>>s , en testant le signe de x
78 #define ShiftRight(_x,_s) (((_x)<0) ? -(-(_x)>>(_s)) : ((_x)>>(_s)))
79 
80 static
81 int evolutecolor (unsigned int src,unsigned int dest, unsigned int mask, unsigned int incr) {
82  int color = src & (~mask);
83  src &= mask;
84  dest &= mask;
85 
86  if ((src!=mask)
87  &&(src<dest))
88  src += incr;
89 
90  if (src>dest)
91  src -= incr;
92  return (src&mask)|color;
93 }
94 
95 static void pretty_move (float lcycle, float *dist,float *dist2, float *rotangle) {
96  static float s_distT = 10.0F;
97  static float s_distT2 = 0.0F;
98  static float s_rot = 0.0F; // entre 0 et 2 * M_PI
99  static int s_happens = 0;
100  static int s_rotation = 0;
101  static int s_lock = 0;
102 
103  if (s_happens)
104  s_happens -= 1;
105  else if (s_lock == 0) {
106  s_happens = iRAND(200)?0:100+iRAND(60);
107  s_lock = s_happens * 3 / 2;
108  }
109  else s_lock --;
110 // happens = 1;
111 
112  float tmp = s_happens?8.0F:0;
113  *dist2 = s_distT2 = (tmp + 15.0F*s_distT2)/16.0F;
114 
115  tmp = 30+D-90.0F*(1.0F+sinf(lcycle*19/20));
116  if (s_happens)
117  tmp *= 0.6F;
118 
119  *dist = s_distT = (tmp + 3.0F*s_distT)/4.0F;
120 
121  if (!s_happens){
122  tmp = M_PI_F*sinf(lcycle)/32+3*M_PI_F/2;
123  }
124  else {
125  s_rotation = iRAND(500)?s_rotation:iRAND(2);
126  if (s_rotation)
127  lcycle *= 2.0F*M_PI_F;
128  else
129  lcycle *= -1.0F*M_PI_F;
130  tmp = lcycle - (M_PI_F*2.0F) * floorf(lcycle/(M_PI_F*2.0F));
131  }
132 
133  if (fabsf(tmp-s_rot) > fabsf(tmp-(s_rot+2.0F*M_PI_F))) {
134  s_rot = (tmp + 15.0F*(s_rot+2*M_PI_F)) / 16.0F;
135  if (s_rot>2.0F*M_PI_F)
136  s_rot -= 2.0F*M_PI_F;
137  *rotangle = s_rot;
138  }
139  else if (fabsf(tmp-s_rot) > fabsf(tmp-(s_rot-2.0F*M_PI_F))) {
140  s_rot = (tmp + 15.0F*(s_rot-2.0F*M_PI_F)) / 16.0F;
141  if (s_rot<0.0F)
142  s_rot += 2.0F*M_PI_F;
143  *rotangle = s_rot;
144  }
145  else
146  *rotangle = s_rot = (tmp + 15.0F*s_rot) / 16.0F;
147 }
148 
149 void tentacle_update(int *buf, int *back, int W, int H, short data[2][512], float rapport, int drawit) {
150  static int s_colors[] = {
151  (0x18<<(ROUGE*8))|(0x4c<<(VERT*8))|(0x2f<<(BLEU*8)),
152  (0x48<<(ROUGE*8))|(0x2c<<(VERT*8))|(0x6f<<(BLEU*8)),
153  (0x58<<(ROUGE*8))|(0x3c<<(VERT*8))|(0x0f<<(BLEU*8))};
154 
155  static int s_col = (0x28<<(ROUGE*8))|(0x2c<<(VERT*8))|(0x5f<<(BLEU*8));
156  static int s_dstCol = 0;
157  static float s_lig = 1.15F;
158  static float s_ligs = 0.1F;
159 
160  float dist = NAN;
161  float dist2 = NAN;
162  float rotangle = NAN;
163 
164  if ((!drawit) && (s_ligs>0.0F))
165  s_ligs = -s_ligs;
166 
167  s_lig += s_ligs;
168 
169  if (s_lig > 1.01F) {
170  if ((s_lig>10.0F) || (s_lig<1.1F))
171  s_ligs = -s_ligs;
172 
173  if ((s_lig<6.3F)&&(iRAND(30)==0))
174  s_dstCol=iRAND(3);
175 
176  s_col = evolutecolor(s_col,s_colors[s_dstCol],0xff,0x01);
177  s_col = evolutecolor(s_col,s_colors[s_dstCol],0xff00,0x0100);
178  s_col = evolutecolor(s_col,s_colors[s_dstCol],0xff0000,0x010000);
179  s_col = evolutecolor(s_col,s_colors[s_dstCol],0xff000000,0x01000000);
180 
181  int color = s_col;
182  int colorlow = s_col;
183 
184  lightencolor(&color,s_lig * 2.0F + 2.0F);
185  lightencolor(&colorlow,(s_lig/3.0F)+0.67F);
186 
187  rapport = 1.0F + 2.0F * (rapport - 1.0F);
188  rapport *= 1.2F;
189  if (rapport > 1.12F)
190  rapport = 1.12F;
191 
192  pretty_move (cycle,&dist,&dist2,&rotangle);
193 
194  for (auto & tmp : grille) {
195  for (int tmp2=0;tmp2<definitionx;tmp2++) {
196  float val = (float)(ShiftRight(data[0][iRAND(511)],10)) * rapport;
197  vals[tmp2] = val;
198  }
199 
200  grid3d_update (tmp,rotangle, vals, dist2);
201  }
202  cycle+=0.01F;
203  for (auto & tmp : grille)
204  grid3d_draw (tmp,color,colorlow,dist,buf,back,W,H);
205  }
206  else {
207  s_lig = 1.05F;
208  if (s_ligs < 0.0F)
209  s_ligs = -s_ligs;
210  pretty_move (cycle,&dist,&dist2,&rotangle);
211  cycle+=0.1F;
212  if (cycle > 1000)
213  cycle = 0;
214  }
215 }
grid3d_free
void grid3d_free(grid3d **grid)
Definition: surf3d.cpp:7
build_compdb.dest
dest
Definition: build_compdb.py:9
v3d::z
float z
Definition: v3d.h:11
v3d
Definition: v3d.h:10
back
static guint32 * back
Definition: goom_core.cpp:29
definitionz
#define definitionz
Definition: tentacle3d.cpp:12
definitionx
#define definitionx
Definition: tentacle3d.cpp:11
D
#define D
Definition: tentacle3d.cpp:8
grille
static grid3d * grille[nbgrid]
Definition: tentacle3d.cpp:15
v3d.h
lightencolor
static void lightencolor(int *col, float power)
Definition: tentacle3d.cpp:65
goomconfig.h
grid3d_new
grid3d * grid3d_new(int sizex, int defx, int sizez, int defz, v3d center)
Definition: surf3d.cpp:15
grid3d_update
void grid3d_update(grid3d *g, float angle, const float *vals, float dist)
Definition: surf3d.cpp:99
vals
static float * vals
Definition: tentacle3d.cpp:16
nbgrid
#define nbgrid
Definition: tentacle3d.cpp:10
tmp
static guint32 * tmp
Definition: goom_core.cpp:30
iRAND
#define iRAND(i)
Definition: goom_tools.h:33
M_PI_F
#define M_PI_F
Definition: goom_tools.h:7
tentacle_free
void tentacle_free(void)
Definition: tentacle3d.cpp:23
tentacle_new
void tentacle_new(void)
Definition: tentacle3d.cpp:30
grid3d_draw
void grid3d_draw(grid3d *g, int color, int colorlow, int dist, int *buf, int *back, int W, int H)
Definition: surf3d.cpp:63
hardwareprofile.i18n.t
t
Definition: i18n.py:36
cycle
static float cycle
Definition: tentacle3d.cpp:14
lighten
static unsigned char lighten(unsigned char value, float power)
Definition: tentacle3d.cpp:48
surf3d.h
tentacle_update
void tentacle_update(int *buf, int *back, int W, int H, short data[2][512], float rapport, int drawit)
Definition: tentacle3d.cpp:149
BLEU
#define BLEU
Definition: goomconfig.h:11
goom_tools.h
ROUGE
#define ROUGE
position des composantes
Definition: goomconfig.h:10
VERT
#define VERT
Definition: goomconfig.h:12
v3d::y
float y
Definition: v3d.h:11
pretty_move
static void pretty_move(float lcycle, float *dist, float *dist2, float *rotangle)
Definition: tentacle3d.cpp:95
ShiftRight
#define ShiftRight(_x, _s)
Definition: tentacle3d.cpp:78
evolutecolor
static int evolutecolor(unsigned int src, unsigned int dest, unsigned int mask, unsigned int incr)
Definition: tentacle3d.cpp:81
grid3d
Definition: surf3d.h:14