Morph-SynRJ

view efx_screen4.cxx @ 0:22de913c2d84

morph-synrj intro
author "Cedric Pinson <cedric.pinson@alcove.fr> <mornifle@plopbyte.net>"
date Tue Nov 27 15:23:52 2007 +0100 (2007-11-27)
parents
children
line source
1 #include "efx_screen4.h"
2 #include "sys_assert.h"
3 #include "mth_vector3.h"
4 #include "gl_header.h"
5 #include "cmn_intro.h"
6 #include "cmn_design.h"
8 static const char* OriginalScrollText1[]=
9 {
11 "",
12 "",
13 "",
14 "",
15 "",
16 "",
17 "",
18 "",
19 "",
20 "",
21 "",
22 "",
23 "",
24 "",
25 "",
26 "",
27 "",
28 "",
29 " you have experienced",
30 " . morph / syn[rj] .",
31 " presented at",
32 " . st(art) 2004 .",
33 "",
34 "this prod was made in 2.5",
35 "weeks and finished some",
36 "minutes before the",
37 "deadline.",
38 "most effects are fastly",
39 "coded, and can be really",
40 "slow on 'medium' class",
41 "computer.",
42 "",
43 "credits",
44 " code",
45 " Stv",
46 " psc80",
47 " mRyOuNg",
48 " design",
49 " kohai",
50 " music",
51 " Evil",
52 "",
53 "greetings fly to ...",
54 " Ziggy stardust",
55 " Zann / grumly&compagny",
56 " Keops / Equinox",
57 " rahow / apex",
58 " scalpos / apex",
59 " codac / apex",
60 " cyborg / deathless",
61 " MrHoward / ambre",
62 " debug / defence force",
63 " Squaley",
64 " impulse",
65 " st(art) team",
66 " CodeFr (ircnet)",
67 " ...",
68 " st(art) 2k4 audience",
69 "",
70 " thanks for watching",
71 "",
72 0
74 };
79 static const char* OriginalScrollText2[]=
80 {
81 "",
82 "",
83 "",
84 "",
85 "",
86 "",
87 "",
88 "Credits:",
89 "",
90 "Code:",
91 "stv",
92 "psc80",
93 "mryoung",
94 "",
95 "design:",
96 "kohai",
97 "",
98 "sound:",
99 "evil",
100 "",
101 "contrib:",
102 "zann",
103 "squaley",
104 "",
105 0
107 };
111 const int ScrollText2ResolutionX=96;
112 const int ScrollText2ResolutionY=96;
115 // sync
116 extern fxSync * sync;
118 efxScreen4_t::efxScreen4_t()
119 {
120 cameraLookAt.Init();
121 cameraPosition.Init(0,50,100);
122 scrollText2map=0;
123 linesScroll1=linesScroll2=-8;
124 ScrollText2=0;
125 ScrollText1=0;
127 indexInSample=0;
128 for (int i=0;i<NbSampleSoundLevel;i++)
129 sampleLevelSound[i]=0;
130 }
133 void efxScreen4_t::InitTextchar(char**& _dst,const char** _src,int& _nbLines)
134 {
135 _nbLines=0;
136 while (_src[_nbLines]!=0)
137 _nbLines++;
139 typedef char* CharPtr_t;
140 _dst=new CharPtr_t[_nbLines+1];
141 for (int i=0;i<_nbLines;i++)
142 _dst[_nbLines-i-1]=strdup(_src[i]);
144 }
146 void efxScreen4_t::Init()
147 {
148 const float Radius=0.95;
149 const float Height=1.0;
151 #ifdef HIGHRES
152 const int Sections=24;
153 #else
154 #ifdef MIDDLERES
155 const int Sections=14;
156 #endif
157 #endif
159 equa.Init(ScrollText2ResolutionX,ScrollText2ResolutionY);
160 scrollText2map=new uchar[ScrollText2ResolutionX*ScrollText2ResolutionY*4];
163 InitTextchar(ScrollText2,OriginalScrollText2,nbLinesScroll2);
164 InitTextchar(ScrollText1,OriginalScrollText1,nbLinesScroll1);
165 linesScroll1=nbLinesScroll1/2;
166 linesScroll2=-nbLinesScroll2/2+3;
168 GLuint id=glGenLists(1);
169 SYS_ASSERT(id);
170 glNewList(id,GL_COMPILE);
172 glBegin(GL_TRIANGLE_FAN);
173 glNormal3f(0,1,0);
174 glVertex3f(0,Height,0);
176 double one_on_section=mth::TWOPI*1.0/Sections;
177 for (int s=0;s<Sections+1;s++) {
178 glNormal3f(0,1,0);
179 glVertex3f(Radius * mth::Sin( -s * one_on_section),Height,Radius * mth::Cos(-s * one_on_section));
180 }
181 glEnd();
184 // make core of cylinder
185 glBegin(GL_QUAD_STRIP);
186 for (s=0; s < Sections; s++)
187 for (int i=0;i<2;i++) {
188 glNormal3f( mth::Sin(s * one_on_section), 0, mth::Cos(s * one_on_section));
189 glVertex3f(Radius* mth::Sin(s * one_on_section),Height*(i%2?1:-1),Radius* mth::Cos(s * one_on_section));
190 }
191 glEnd();
192 glEndList();
194 equa.SetGeometry(id);
197 int size=256;
198 float div=2.0/size;
199 background=txtCreatePerlin2d(size,size,div,div,0.6,6);
205 const int NbKeys=4096;
206 const float TimeStep=10.0;
208 cameraPath=new mth::Hermite_t(NbKeys*2);
209 cameraKeyData=new mth::HermiteKey_t[NbKeys];
211 mth::Vector3_t tmpPos;
212 for (int i=0;i<NbKeys;i++) {
213 tmpPos.InitRandomVectorInBox(ScrollText2ResolutionX);
214 tmpPos[1]=20+mth::Abs(3*tmpPos[1]);
215 tmpPos[2]=mth::Abs(tmpPos[2]);
216 cameraKeyData[i].Init(TimeStep*i,tmpPos);
217 cameraPath->AddKey(&cameraKeyData[i]);
218 }
220 }
224 float Mod(float _x,float _mod) {
225 int n=(int)(_x/_mod);
226 float x2=_x-n*_mod;
227 if (x2<0)
228 x2+=_mod;
229 return x2;}
232 void efxScreen4_t::UpdateScrollText1()
233 {
234 const float LinesPerSecond=1;
235 linesScroll1-=LinesPerSecond*Timer->GetFrameTime();
236 linesScroll1=Mod(linesScroll1,nbLinesScroll1);
237 }
241 void efxScreen4_t::UpdateScrollText2()
242 {
243 const float LinesPerSecond=1;
244 linesScroll2-=LinesPerSecond*Timer->GetFrameTime();
245 linesScroll2=Mod(linesScroll2,nbLinesScroll2);
246 }
249 void efxScreen4_t::Update()
250 {
251 internalTime+=Timer->GetFrameTime();
253 cameraPath->GetData(internalTime,cameraPosition);
255 UpdateScrollText1();
256 UpdateScrollText2();
258 sampleLevelSound[indexInSample]=(sync->GetDetection()->GetSampleData(INST_BIGBD).playing==true?5:0);
259 indexInSample=(indexInSample+1)%NbSampleSoundLevel;
260 levelSound=0;
261 for (int i=0;i<NbSampleSoundLevel;i++)
262 levelSound+=sampleLevelSound[i];
263 levelSound/=NbSampleSoundLevel;
265 cameraPosition[1]+=levelSound*10;
266 /*
267 INST_BASS = 0,
268 INST_HHAT = 1,
269 INST_BDRUM = 2,
270 INST_SNARE = 3,
271 INST_SBDRUM = 4,
272 INST_NAP1 = 5,
273 INST_NAP2 = 6,
274 INST_BIGBD = 7
275 */
276 }
279 void efxScreen4_t::DrawScrollText1()
280 {
281 const int StartPositionY=0;
282 const int StartPositionX=32;
283 const int FilterY=(1-0.34)*2*RY;
284 const int FilterX=300;
285 font->SetScaleX(0.75);
286 const int NbLinesToDisplay=2+RY/font->SizeOfCharY();
290 //glDisable(GL_BLEND);
291 glBlendFunc(GL_ONE,GL_ONE);
294 font->SetScaleY(1);
295 glColor4f(1,1,1,1);
296 float starty=StartPositionY-mth::Frac(linesScroll1)*font->SizeOfCharY();
297 int indexLine=mth::Floor(linesScroll1);
298 int nb=mth::Min(indexLine,RY/font->SizeOfCharY());
299 for (int i=0;i<NbLinesToDisplay;i++)
300 font->Print(StartPositionX,starty+(i)*font->SizeOfCharY(),ScrollText1[(indexLine+i+2*nbLinesScroll1)%nbLinesScroll1]);
302 //cmnPopMatrix();
303 font->SetScale(1);
304 }
306 void efxScreen4_t::DrawScrollText2()
307 {
308 cmnPushMatrix();
309 cmnClearScreen(0,0,0,1);
310 glFlush();
311 glDisable(GL_BLEND);
312 cmnSetPlanarView();
313 font->SetScaleX(0.75);
314 font->SetScaleY(1);
316 const int StartPositionInMapY=32;
317 const int StartPositionInMapX=16;
318 const float OffsetFactor=0.02;
320 int nb=ScrollText2ResolutionY/font->SizeOfCharY();
321 int indexLine=mth::Floor(linesScroll2);
322 float frac=mth::Frac(linesScroll2);
323 for (int i=0;i<nb+1;i++) {
324 font->Print(StartPositionInMapX,StartPositionInMapY-frac*font->SizeOfCharY()+i*font->SizeOfCharY(),ScrollText2[(indexLine+i+2*nbLinesScroll2)%nbLinesScroll2]);
325 }
327 glFlush();
329 txtGetTextureFromBackBuffer(
330 scrollText2map,
331 StartPositionInMapX,
332 StartPositionInMapY,
333 ScrollText2ResolutionX,
334 ScrollText2ResolutionY);
336 float pixel;
337 for (i=0;i<ScrollText2ResolutionX;i++)
338 for (int j=0;j<ScrollText2ResolutionY;j++) {
339 int index=(i+(ScrollText2ResolutionY-1-j)*ScrollText2ResolutionY)*4;
340 pixel=scrollText2map[index+0]+scrollText2map[index+1]+scrollText2map[index+2];
341 pixel/=3;
342 pixel*=OffsetFactor;
343 if (pixel>1)
344 pixel+=levelSound;
345 equa.SetDepthLevel(i+(/*ScrollText2ResolutionY-*/j)*equa.ResX(),pixel);
346 }
348 cmnPopMatrix();
349 cmnClearScreen(0,0,0,1);
350 }
353 #if 1
356 void efxScreen4_t::DrawBackScrollLine(const float* _pnts,int _nbPts,float _offsetY,float _offsetX)
357 {
358 glBegin(GL_LINE_STRIP);
359 for (int i=0;i<_nbPts*2;i+=2) {
360 glVertex2f(_pnts[i]+_offsetX,_pnts[i+1]+_offsetY);
361 }
362 glEnd();
363 }
365 void efxScreen4_t::DrawBackScrollBg(const float* _pntsTop,int _nbPts, float _OffsetTop,float _OffsetBottomY,float _offsetX)
366 {
368 int nbQuads=_nbPts/2;
370 glBegin(GL_QUADS);
371 for (int i=0;i<nbQuads*4;i+=4) {
372 glVertex2f(_pntsTop[i]+_offsetX,_pntsTop[i+1]+_OffsetTop);
373 glVertex2f(_pntsTop[i+2]+_offsetX,_pntsTop[i+3]+_OffsetTop);
375 glVertex2f(_pntsTop[i+2]+_offsetX,_pntsTop[i+3]+_OffsetBottomY);
376 glVertex2f(_pntsTop[i]+_offsetX,_pntsTop[i+1]+_OffsetBottomY);
377 }
378 glEnd();
380 }
382 void efxScreen4_t::DrawBackScroll()
383 {
384 const int NbPoints=16;
385 const float OffsetY2=400;
386 const float OffsetY1=-50;
387 const float OffsetX=30;
388 const float CoordLines[]={
389 1,123,
390 55,123,
391 55,108,
392 102,108,
393 102,123,
394 140,123,
395 140,94,
396 194,94,
397 194,123,
398 213,123,
399 213,114,
400 235,114,
401 235,123,
402 256,123,
403 256,98,
404 303,98,
405 // 303,98,
406 403,98,
407 // 303,98,
408 };
411 glLineWidth(2);
412 glBlendFunc(GL_ONE, GL_SRC_ALPHA);
413 glColor4ub(0, 0, 0, 100);
416 DrawBackScrollBg(CoordLines,NbPoints,OffsetY2,OffsetY1,OffsetX);
417 glDisable(GL_BLEND);
418 glColor4f(1,1,1,1);
419 DrawBackScrollLine(CoordLines,NbPoints,OffsetY1,OffsetX);
420 DrawBackScrollLine(CoordLines,NbPoints,OffsetY2,OffsetX);
422 glBegin(GL_LINES);
423 glVertex2f(CoordLines[0]+OffsetX,CoordLines[1]+OffsetY1);
424 glVertex2f(CoordLines[0]+OffsetX,CoordLines[1]+OffsetY2);
425 glVertex2f(CoordLines[(NbPoints-1)*2]+OffsetX,CoordLines[(NbPoints-1)*2+1]+OffsetY1);
426 glVertex2f(CoordLines[(NbPoints-1)*2]+OffsetX,CoordLines[(NbPoints-1)*2+1]+OffsetY2);
427 glEnd();
429 }
431 #endif
433 void efxScreen4_t::Draw()
434 {
435 cmnSetFrustrum(90);
436 cmnSetCamera(cameraPosition,cameraLookAt);
437 DrawScrollText2();
440 glEnable(GL_BLEND);
441 glBlendFunc(GL_ONE,GL_ONE);
442 cmnDisplayBackground(background,33,137,255,255,2,1);
446 cmnPushGLState();
447 glEnable(GL_LIGHTING);
448 glEnable(GL_LIGHT0);
449 equa.SetElementSize(2,2);
450 glScalef(1,2,1);
451 equa.Draw();
452 cmnPopGLState();
456 cmnSetPlanarView();
458 //#define TRY_STENCIL
459 #ifdef TRY_STENCIL
460 glDisable(GL_DEPTH_TEST);
461 glEnable(GL_STENCIL_TEST);
462 glClearStencil(0);
463 glClear(GL_STENCIL_BUFFER_BIT);
464 glStencilFunc(GL_ALWAYS,1,1);
465 glStencilOp(GL_REPLACE,GL_REPLACE,GL_REPLACE);
466 #else
468 glEnable(GL_DEPTH_TEST);
469 glDepthFunc(GL_ALWAYS);
470 #endif
471 DrawBackScroll();
473 #ifdef TRY_STENCIL
474 glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
475 glStencilFunc(GL_EQUAL,1,1);
476 #else
477 glDepthFunc(GL_EQUAL);
478 #endif
479 font->SetZ(0);
480 glEnable(GL_BLEND);
481 DrawScrollText1();
484 // cmnPopGLState();
485 // cmnPopMatrix();
487 #ifndef FINALE_RELEASE
488 cmnSetPlanarView();
489 font->Print("Camera %f %f %f\n",cameraPosition[0],cameraPosition[1],cameraPosition[2]);
490 #endif
492 }