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