Skip to content

Commit 6bc5365

Browse files
committed
visual synced with offset time
1 parent 2bc1eb4 commit 6bc5365

File tree

3 files changed

+149
-81
lines changed

3 files changed

+149
-81
lines changed

effects.cpp

Lines changed: 89 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include "headers.h"
22

33
using namespace std;
4-
54
vector< array<double,60> > avgarr(0); //for average value
65

76
/******************* BARS **********************/
87
void bars()
98
{
10-
glTranslatef(0,-10,-50.0);
9+
glTranslatef(0,-13,-50.0);
1110
//Translation motion along(x,y,z) axis
1211
d=0.7;
1312
glPointSize(10.0);
@@ -39,7 +38,7 @@ void bars()
3938
/******************* CIRCLE3D **********************/
4039
void circle3d()
4140
{
42-
glTranslatef(0,-10,-50.0);
41+
glTranslatef(0,-5,-50.0);
4342
//Translation motion along(x,y,z) axis
4443
//rotation after translation (order matters)
4544
glRotatef(deg,1,0,0); //(degree, x,y,z);
@@ -49,13 +48,14 @@ void circle3d()
4948
float deg=0.0;
5049
float r1=38/255.0,g1=87/255.0,b1=235/255.0;
5150
float r2=countr/255.0,g2=countg/255.0,b2=countb/255.0;
51+
5252
for(int i=0; i<60; i++)
5353
{
54-
55-
if((int)avgarr.size()<=j)
54+
if((int)avgarr.size()-2 <=j)
5655
exit(0);
5756
float x=r*cos(deg*(3.14/180)),y=avgarr[j][i],z=r*sin(deg*(3.14/180));
5857
//end of music data
58+
{
5959
glBegin(GL_QUADS);
6060
//top
6161
glColor3f(r2,g2,b2);
@@ -114,9 +114,12 @@ void circle3d()
114114
glColor3f(r1,g1,b1);
115115
glVertex3f(x-d,0,z-d); //-x,y=0,z
116116
glEnd();
117+
}
118+
119+
{
117120

118121
glBegin(GL_LINE_LOOP);
119-
glColor3f(0,0,0);
122+
glColor3f(1,1,1);
120123
//left
121124
glVertex3f(x-d,0,z+d); //-x,y=0,z
122125
glVertex3f(x-d,0,z-d); //-x,y=0,-z
@@ -149,22 +152,39 @@ void circle3d()
149152

150153
glEnd();
151154

155+
}
152156
deg+=6;
153157
//deg+=5.625;
154158
}
155-
j++;
156-
Sleep(97);
159+
160+
// sync3
161+
if( curtime > (j*100+100))
162+
{
163+
j++;
164+
//cout<<"arr_sz: "<<(int)avgarr.size()<<" j:"<<j<<" cur time:"<<curtime<<endl;
165+
//sync++;
166+
}
167+
168+
// sync1
169+
// while((int)sound.getPlayingOffset().asSeconds()<(i*100+100)){
170+
// Sleep(1);
171+
// }
172+
173+
// sync2
174+
// Sleep(97);
175+
// j++;
176+
// cout<<"arr_sz: "<<(int)avgarr.size()<<" j:"<<j<<endl;
157177
}
158178
/******************* PENTAGON **********************/
159179
void pentagon()
160180
{
161-
glTranslatef(0,-10,-50.0);
181+
glTranslatef(0,0,-50.0);
162182
//Translation motion along(x,y,z) axis
163183
d=0.7;
164184
glPointSize(2.0);
165185
for(int i=0; i<60; i++)
166186
{
167-
if((int)avgarr.size()<=j)
187+
if((int)avgarr.size()-2<=j)
168188
exit(0);
169189
float x=0,r=avgarr[j][i],y=0,z=-4,deg=0;
170190
//end of music data
@@ -179,12 +199,19 @@ void pentagon()
179199
}
180200
glEnd();
181201
}
182-
j++;
183-
Sleep(97);
202+
if( curtime > (j*100+100))
203+
{
204+
j++;
205+
//cout<<"arr_sz: "<<(int)avgarr.size()<<" j:"<<j<<" cur time:"<<curtime<<endl;
206+
//sync++;
207+
}
208+
// j++;
209+
// Sleep(97);
184210
}
185211

186212

187213
/******************* CUBICAL_MESH **********************/
214+
/*
188215
void CubicalMesh()
189216
{
190217
glTranslatef(-80,0,-50.0);
@@ -200,7 +227,7 @@ void CubicalMesh()
200227
for(int i=0; i<60; i++)
201228
{
202229
203-
if((int)avgarr.size()<=j)
230+
if((int)avgarr.size()-2<=j)
204231
exit(0);
205232
float y=avgarr[j][i];
206233
if(i%10==0){
@@ -275,21 +302,25 @@ void CubicalMesh()
275302
//deg+=6;
276303
//deg+=5.625;
277304
}
278-
j++;
279-
Sleep(97);
305+
if( curtime > (j*100+100))
306+
{
307+
j++;
308+
//cout<<"arr_sz: "<<(int)avgarr.size()<<" j:"<<j<<" cur time:"<<curtime<<endl;
309+
//sync++;
310+
}
280311
}
281-
312+
*/
282313
/******************* DUST **********************/
283314
void dust()
284315
{
285-
glTranslatef(0,-10,-50.0);
316+
glTranslatef(0,0,-50.0);
286317
//Translation motion along(x,y,z) axis
287318
d=0.7;
288319
glPointSize(2.0);
289-
glColor3f(1,0,1);
320+
glColor3ub(0x43,0xA0,0x47);
290321
for(int i=0; i<60; i++)
291322
{
292-
if((int)avgarr.size()<=j)
323+
if((int)avgarr.size()-2<=j)
293324
exit(0);
294325
float x=0,r=avgarr[j][i],y=0,z=-4,deg=0;
295326
//end of music data
@@ -303,21 +334,21 @@ void dust()
303334
deg+=6;
304335
}
305336
}
306-
j++;
307-
Sleep(97);
337+
if( curtime > (j*100+100))
338+
j++;
308339
}
309340

310341
/******************* WAVES **********************/
311342
void waves()
312343
{
313-
glTranslatef(0,-10,-50.0);
344+
glTranslatef(0,0,-50.0);
314345
//Translation motion along(x,y,z) axis
315346
d=2;
316347
glPointSize(10.0);
317-
glColor3f(1,0,1);
348+
glColor3ub(0xf9,0x26,0x72);
318349
for(int i=0; i<60; i++)
319350
{
320-
if((int)avgarr.size()<=j)
351+
if((int)avgarr.size()-2<=j)
321352
exit(0);
322353
float x=-60+(i*d),y=avgarr[j][i],z=-4;
323354
//end of music data
@@ -331,11 +362,18 @@ void waves()
331362
glVertex3f(x+(d/2),0,z);
332363
glEnd();
333364
}
334-
j++;
335-
Sleep(97);
365+
if( curtime > (j*100+100))
366+
{
367+
j++;
368+
//cout<<"arr_sz: "<<(int)avgarr.size()<<" j:"<<j<<" cur time:"<<curtime<<endl;
369+
//sync++;
370+
}
371+
// j++;
372+
// Sleep(97);
336373
}
337374

338375
/******************* DWaves **********************/
376+
/*
339377
void DWaves()
340378
{
341379
glTranslatef(-155,-40,-50.0);
@@ -351,7 +389,7 @@ void DWaves()
351389
for(int i=0; i<60; i++)
352390
{
353391
354-
if((int)avgarr.size()<=j)
392+
if((int)avgarr.size()-2<=j)
355393
exit(0);
356394
float y=avgarr[j][i];
357395
if(i%10==0){
@@ -368,26 +406,33 @@ void DWaves()
368406
//deg+=6;
369407
//deg+=5.625;
370408
}
371-
j++;
372-
Sleep(97);
409+
if( curtime > (j*100+100))
410+
{
411+
j++;
412+
//cout<<"arr_sz: "<<(int)avgarr.size()<<" j:"<<j<<" cur time:"<<curtime<<endl;
413+
//sync++;
414+
}
415+
// j++;
416+
// Sleep(97);
373417
}
418+
*/
374419
/****************** 3D MESH **********************/
375420

376-
void mesh3D()
377-
{
378-
glTranslatef(0.0,0.0,-4.5);
379-
glPointSize(2.0);
380-
for(int i=-200; i<=200; i+=5)
381-
for(int j=-100; j<=300; j+=10)
382-
{
383-
384-
glBegin(GL_POINTS);
385-
glColor3f(0.0f,1.0f,0.0f);
386-
glVertex3f( i/100.0,-1.0f, j/100.0);
387-
glEnd();
388-
}
389-
glFlush();
390-
}
421+
//void mesh3D()
422+
//{
423+
// glTranslatef(0.0,0.0,-4.5);
424+
// glPointSize(2.0);
425+
// for(int i=-200; i<=200; i+=5)
426+
// for(int j=-100; j<=300; j+=10)
427+
// {
428+
//
429+
// glBegin(GL_POINTS);
430+
// glColor3f(0.0f,1.0f,0.0f);
431+
// glVertex3f( i/100.0,-1.0f, j/100.0);
432+
// glEnd();
433+
// }
434+
// glFlush();
435+
//}
391436

392437
/***************** PAUSE BUTTON *******************/
393438
void pausebutton()

headers.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ extern float deg;
3434
extern vector< array<double,60> > avgarr; //for average value
3535
extern double SAMPLE_COUNT;
3636
extern double SAMPLE_RATE;
37-
37+
extern float curtime;
38+
extern int sync;
3839
extern kiss_fft_cpx in[N], out[N];
3940

4041
void circle3d();
4142
void bars();
4243
void dust();
4344
void pentagon();
44-
void CubicalMesh();
45+
//void CubicalMesh();
4546
void waves();
46-
void mesh3D();
47+
//void mesh3D();
48+
//void DWaves();
4749
void pausebutton();
4850
void nav();
49-
void DWaves();

0 commit comments

Comments
 (0)