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