-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholdBrisa.cpp
364 lines (294 loc) · 8.66 KB
/
oldBrisa.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
void Brisa::setup() {
switch (tipoBrisa) {
case 0 : // video
setupVideo("claricefalcao.mp4");
break;
case 1 : // contorno
break;
case 2 : // gifFull
loadGif("fullscreen/blackboca");
break;
case 3 : // poligonos
{
int indCor = fmodf( prevTime/8, 4); // [0..4]
//cor1 = coresRole[indCor];
cor1.set(0,255,0);
cor2.set(cor1);
cor2.setHue( (int(prevTime*5)+200) %360);
}
break;
case 4 : // illu
case 5 : // girassol
whiteTotalSlow = 0;
baricentro.set(0,0);
girassol.load("../data/img/girassol.png");
olho.load("../data/img/olhoillu.png");
orbita.load("../data/img/orbitaillu.png");
break;
}
ativa = true;
}
void Brisa::update(float dt) {
switch (tipoBrisa) {
case 0 : // video
if( video.isLoaded() ) {
video.update();
if(kinectLigado) {
// alloca um fbo com o tamanho original do video
// pra poder mesclar no shader
if( !fboKinect.isAllocated() || fboKinect.getWidth() != wOriginal ) {
fboKinect.clear();
fboKinect.allocate(wOriginal,hOriginal);
}
updateKinect(kinectDepth);
}
}
break;
case 1 : // contorno
// Encontra contornos
contourFinder.findContours(kinectDepth, 10, (kinectDepth.width*kinectDepth.height)/2, 20, false);
break;
case 2 : // gifFull
break;
case 3 : // poligonos
{
int indCor = fmodf( prevTime/8, 4); // [0..4]
//cor1 = coresRole[indCor];
cor1.set(0,255,0);
cor2.set(cor1);
cor2.setHue( (int(prevTime*5)+200) %360);
}
break;
case 4 : // illu
case 5 : // girassol
if(kinectLigado) {
if(kinectDepth.bAllocated) {
kinectDepthBlur = blurImage(kinectDepth);
}
}
lookAt = olhaPraMim();
break;
}
}
void Brisa::draw() {
switch (tipoBrisa) {
case 0 : // video
if( video.isLoaded() ) {
/*shaderBrisaInteracao = retornaShader(iShader);
shaderBrisaInteracao.begin();
if(fboKinect.isAllocated()) {
shaderBrisaInteracao.setUniformTexture( "texture1", fboKinect.getTextureReference(), 1 );
}
*/
video.draw(-(wVideo-1024)/2, -(hVideo-768)/2, wVideo, hVideo);
// shaderBrisaInteracao.end();
}
break;
case 1 : // contorno
contourFinder.draw(0,0, 1024,768);
break;
case 2 : // gifFull
if(urlpasta !="" && listaImg.size() > 0) {
float i = fmodf( prevTime/10, listaImg.size() ); // [0..duration]
int ngif = listaImg.size();
float duration = ngif / 12.0; //25fps
float pos = fmodf( prevTime, duration ); // [0..duration]
//5. Convert pos in the frame number
int j = int( pos / duration * ngif );
listaImg[j].setAnchorPercent( 0.5, 0.5 );
// Encontra proporção para redimensionar p fullscreen
int imgOldH = listaImg[j].getHeight();
int imgOldW = listaImg[j].getWidth();
float imgProp = imgOldW/imgOldH;
int imgNewWidth = vw;
int imgNewHeight = vh;
if( imgProp < (4.0/3.0) ) {
imgNewHeight = (vw*imgOldH)/imgOldW;
} else {
imgNewWidth = (vh*imgOldW)/imgOldH;
}
listaImg[j].draw( vw/2 , vh/2, imgNewWidth, imgNewHeight);
}
break;
case 3: // poligonos
// Desenha poligono
ofSetColor(cor1);
desenhaPoligono( int(abs(sin(prevTime*0.1)*4)) + 4, abs(sin(prevTime*0.7-.3))*100 + 800 ,true,true);
ofSetColor(cor2);
desenhaPoligono( int(abs(sin(prevTime*0.1)*4)) + 4, abs(sin(prevTime*0.7-.2))*100 + 700 ,true,true);
ofSetColor(cor1);
desenhaPoligono( int(abs(sin(prevTime*0.1)*4)) + 4, abs(sin(prevTime*0.7-.1))*100 + 600 ,true,true);
ofSetColor(cor2);
desenhaPoligono( int(abs(sin(prevTime*0.1)*4)) + 4, abs(sin(prevTime*0.7))*100 + 500 ,true,true);
ofSetColor(cor1);
desenhaPoligono( int(abs(sin(prevTime*0.1)*4)) + 4, abs(sin(prevTime*0.7+.1))*100 + 400 ,true,true);
ofSetColor(cor2);
desenhaPoligono( int(abs(sin(prevTime*0.1)*4)) + 4, abs(sin(prevTime*0.7+.2))*100 + 300 ,true,true);
ofSetColor(cor1);
desenhaPoligono( int(abs(sin(prevTime*0.1)*4)) + 4, abs(sin(prevTime*0.7+.3))*100 + 200 ,true,true);
ofSetColor(cor2);
desenhaPoligono( int(abs(sin(prevTime*0.1)*4)) + 4, abs(sin(prevTime*0.7)+.4)*100 + 100 ,true,true);
break;
case 4: // illu
{
glPushMatrix();
glTranslatef(vw/2,vh/2, 0);
ofPoint moveOlho;
moveOlho.x = ofMap(lookAt.x,0,vw,-25,25);
moveOlho.y = ofMap(lookAt.y,0,vh,-15,15);
olho.setAnchorPercent(0.5, 0.5);
orbita.setAnchorPercent(0.5, 0.5);
olho.draw(moveOlho);
orbita.draw(0,0);
glPopMatrix();
}
break;
case 5: // gira
{
glPushMatrix();
glTranslatef(vw/2,vh/2 + 10, 0);
float anguloX = ofMap(lookAt.x,0,vw,-50,50);
glRotatef(anguloX, 0, 1, 0);
float anguloY = ofMap(lookAt.y,0,vh,-50,50);
glRotatef(anguloY, -1, 0, 0);
glRotatef(anguloY+anguloX, 0, 0, 0.2);
ofSetColor(255, 255, 255);
girassol.setAnchorPercent(0.5, 0.5);
girassol.draw(0,0);
glPopMatrix();
}
break;
}
}
void Brisa::setupVideo(string videoPath) {
urlpath = "videos/" + videoPath;
cout << "Video load: " << urlpath;
if(urlpath != "") {
video.load(urlpath);
video.play();
video.setPosition(prevTime-(long)prevTime);
video.setVolume(0);
hOriginal = video.getHeight();
wOriginal = video.getWidth();
// background-size: cover;
float videoProp = (float)wOriginal/hOriginal;
if( videoProp > 4./3. ) {
hVideo = 768;
wVideo = wOriginal * (hVideo/hOriginal);
} else {
wVideo = 1024;
hVideo = hOriginal * (wVideo/wOriginal);
}
cout << "\nredimensionado: " << wOriginal << "x" << hOriginal << " => " << wVideo << "x" << hVideo;
}
}
void Brisa::updateKinect(ofxCvGrayscaleImage imgKinect) {
fboKinect.begin();
ofSetColor( 255, 255, 255 );
// acertar a proporção (cover do kinect com o tam do video argh)
imgKinect.draw(-wOriginal/10,-hOriginal/10,wOriginal*1.1,hOriginal*1.1);
fboKinect.end();
}
void Brisa::loadGif(string gifPath) {
// Carrega numero de img da sequencia
ofDirectory dirgif;
urlpasta = "gifs/"+gifPath;
int nimg = dirgif.listDir(urlpasta);
cout << urlpasta << ": ";
// Set array img size
listaImg.resize( nimg );
// Load images
for (int j=0; j<nimg; j++) {
//Getting i-th file name
string fileName = dirgif.getPath( j );
//Load i-th image
ofLoadImage( listaImg[j], fileName );
cout << "|";
}
cout << nimg <<" imgs loaded"<< endl;
}
// Desenha poligono
void Brisa::desenhaPoligono(int vertices, int radius, bool rotate, bool fill) {
if(vertices < 3)
vertices = 3;
//corrigindo tamanho aparente
radius = radius - vertices*8;
if(fill) {
ofFill();
}else {
ofNoFill();
}
glPushMatrix();
//Gambizinha pra caso seja o triangulo com beat
if(vertices == 3 && !rotate){
glTranslatef(vw/2,vh/2+70, 0);
} else {
// o que aocntecia normalmente antes da gambi
glTranslatef(vw/2,vh/2, 0);
}
if (rotate) {
glRotatef( sin(prevTime*0.5)*50 + (360/vertices-1)-(360/vertices) + 100, 0, 0, 1);
} else {
glRotatef( 180, 0, 0, 1);
}
ofBeginShape();
for(int i = 0; i < vertices+1; i++) {
float theta = (TWO_PI/vertices) * i;
ofVertex( sin(theta)*radius , cos(theta)*radius ,0);
}
ofEndShape();
glPopMatrix();
}
ofxCvGrayscaleImage Brisa::blurImage(ofxCvGrayscaleImage imgOriginal) {
imgOriginal.blur(11);
imgOriginal.erode();
imgOriginal.dilate();
imgOriginal.blur(101);
imgOriginal.erode();
imgOriginal.dilate();
imgOriginal.blur(101);
imgOriginal.flagImageChanged();
return imgOriginal;
}
ofPoint Brisa::olhaPraMim() {
ofPoint lookAt;
if(kinectLigado) {
ofPixels & pix = kinectDepthBlur.getPixels();
int blurWidth = kinectDepthBlur.width;
int whiteTotal = 0; // quantidade de coisa na frente da tela
ofPoint centro( blurWidth/2, kinectDepthBlur.height/2 );
ofPoint baricentro0 = baricentro;
baricentro.set(0, 0);
for(int j = 0; j < 10; j++) {
ofVec2f vecDirecao(15 + j*30,0);
for(int i = 0; i < 8; i++) {
ofPoint pontoRef = centro+vecDirecao;
// Caso o ponto esteja dentro da imagem
if (pontoRef.x >= 0 && pontoRef.y >= 0 &&
pontoRef.x < blurWidth && pontoRef.y < kinectDepthBlur.height)
{
int white = pix[int(pontoRef.y)*blurWidth + int(pontoRef.x)];
whiteTotal += white;
baricentro += pontoRef*white;
}
vecDirecao.rotate(45);
}
}
if(whiteTotal>0) {
baricentro /= whiteTotal;
} else {
baricentro.set( kinectDepthBlur.width/2, kinectDepthBlur.height/2 );
}
baricentro = baricentro*0.04 + baricentro0*0.96;
lookAt.x = ofMap(baricentro.x, 0, kinectDepthBlur.width, 0, vw);
lookAt.y = ofMap(baricentro.y, 0, kinectDepthBlur.height, 0, vh);
whiteTotalSlow = whiteTotalSlow*0.9 + whiteTotal*0.1;
}
ofPoint perlinPoint;
perlinPoint.x = vw * ofNoise( prevTime * 0.15 );
perlinPoint.y = vh * ofNoise( prevTime * 0.2 );
if( whiteTotalSlow < 1000 || whiteTotalSlow > 7000) {
lookAt = perlinPoint;
}
return lookAt;
}