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