home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 February / Chip_2001-02_cd1.bin / bonus / demos / CS / exp / SOURCES / DEMO / EFEKT_02.CPP < prev    next >
C/C++ Source or Header  |  2000-08-16  |  5KB  |  185 lines

  1. /*
  2.  
  3. tesla efekt
  4.  
  5. return:
  6.   0 - doslo k chybe
  7.   1 - este nezacal
  8.   2 - prebehol v poriadku
  9.   3 - uz skoncil
  10. */
  11.  
  12. #include <iostream>
  13. #include "api3ds.h"
  14. #include "efekt.h"
  15. #include "efekt_02.h"
  16. #include "syncs.h"
  17.  
  18. extern int sync_id;
  19. extern bool showlogo;
  20. extern BOOL usefog;
  21.  
  22. int  efekt_02::init()
  23. {
  24.   cout << "Efekt 2 init ... ";
  25.   start=TRUE;
  26.   counter=ZACIATOK02*refresh;
  27.   glClearColor (cl_r, cl_g, cl_b, 1.0);
  28.   l_r=l_g=l_b=1.0;
  29.   tex_x_counter=0;
  30.   tex_y_counter=0.0;
  31.   real_in=0.0;
  32.   cout << "ok!" << endl;
  33.   return 1;
  34. }
  35.  
  36. int  efekt_02::load()
  37. {
  38.     cout << "Loading efekt02 ... ";
  39.     Vector3f o,i,j,k;
  40.     FILE *stream;
  41.  
  42.     stream=fopen(CFGNAME02,"r");
  43.     if (stream==NULL) return 0;
  44.  
  45.     fscanf(stream,"pocet ploch          %i\n",&plochy);
  46.     fscanf(stream,"intenzita            %f\n",&intens);
  47.     fscanf(stream,"x-krok               %f\n",&txadd);
  48.     fscanf(stream,"y-krok               %f\n",&tyadd);
  49.     fscanf(stream,"podstava valca       %i\n",&podstava);
  50.     fscanf(stream,"vyska valca          %i\n",&vyska);
  51.     fscanf(stream,"background color     %f,%f,%f\n",&cl_r,&cl_g,&cl_b);
  52.     fscanf(stream,"visibility           %f\n",&vis);
  53.     fscanf(stream,"minvisibility        %f\n",&minvis);
  54.     fscanf(stream,"Descent origin       (%f,%f,%f)\n",&o.x,&o.y,&o.z);
  55.     fscanf(stream,"Descent right        (%f,%f,%f)\n",&i.x,&i.y,&i.z);
  56.     fscanf(stream,"Descent up           (%f,%f,%f)\n",&j.x,&j.y,&j.z);
  57.     fscanf(stream,"Descent forward      (%f,%f,%f)\n",&k.x,&k.y,&k.z);
  58.     fclose(stream);
  59.  
  60.     cam.SetAll(o,i,j,k);
  61.     cam.FarClipplane(vis);
  62.     cam.NearClipplane(minvis);
  63.     cam.HorizontalFOV(0.63);
  64.     cam.VerticalFOV(0.47);
  65.     texla=texture_library->GetOrCreate("TESLA1.JPG");
  66.     loading=texture_library->GetOrCreate("LOADING.JPG");
  67.  
  68.     cout << "ok!"<<endl;
  69. }
  70.  
  71. int  efekt_02::free()  //vrati 3 ako ok, 0 ak doslo k chybe
  72. {
  73. end=true;
  74. glClearColor(0.0,0.0,0.0,1.0);
  75. return 3;
  76. }
  77.  
  78. int  efekt_02::update()
  79. {
  80. id=Sync[GetSyncNum(float(counter)/float(refresh))].id;
  81.  
  82. tex_x_counter+=txadd;
  83. tex_y_counter+=tyadd;
  84. uhol_counter+=0.01;
  85. if (id==SYNC_START_TESLA1)
  86.   {
  87.   if (real_in<intens) real_in+=0.002;
  88.                 else  real_in=intens;
  89.   if (l_r>0.0) l_r-=0.01;
  90.           else l_r=0.0;
  91.   if (l_g>0.0) l_g-=0.01;
  92.           else l_g=0.0;
  93.   if (l_b>0.0) l_b-=0.01;
  94.           else l_b=0.0;
  95.   }
  96. if (id==SYNC_GO_IN_BLACK)
  97.   {
  98.   if (cl_r>0.0) cl_r-=0.04;
  99.            else cl_r=0.0;
  100.   if (cl_g>0.0) cl_g-=0.04;
  101.            else cl_g=0.0;
  102.   if (cl_b>0.0) cl_b-=0.04;
  103.            else cl_b=0.0;
  104. //  cout << "clr=" << cl_r << endl;
  105.   glClearColor(cl_r,cl_g,cl_b,1.0);
  106.   }
  107. return 1;
  108. }
  109.  
  110. int efekt_02::go(double t)
  111. {
  112. if (t<ZACIATOK02) return 1;
  113. if (end) return 3;
  114. if (counter>=KONIEC02*refresh) return free();
  115.  
  116. if (!start) if (!init()) return 0;
  117. int cur_frm=(int)(t*refresh);
  118. if (cur_frm>KONIEC02*refresh) cur_frm=int(KONIEC02*refresh);
  119. if (cur_frm>counter)
  120.   while (counter<cur_frm)
  121.     {
  122.     counter++;
  123.     if (counter<KONIEC02*refresh) update();
  124.     }
  125. if (counter>=KONIEC02*refresh) return free();
  126.  
  127. //tu sa kresli->
  128.   loading->GL();
  129.   glMatrixMode(GL_PROJECTION);
  130.   glLoadIdentity();
  131.   glMatrixMode(GL_MODELVIEW);
  132.   glLoadIdentity();
  133.   glEnable(GL_TEXTURE_2D);
  134.   glDisable(GL_FOG);
  135.   glDisable(GL_LIGHTING);
  136.   glDisable(GL_DEPTH_TEST);
  137.   glDisable(GL_CULL_FACE);
  138.   glEnable(GL_BLEND);
  139.   glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
  140.  
  141.   if (l_r<1.0) showlogo=false;
  142.   glBegin(GL_QUADS);
  143.     glColor3f(l_r,l_g,l_b);
  144.     glTexCoord2f( 1.0, 1.0);
  145.     glVertex2f  (-0.5,-0.8);
  146.     glTexCoord2f( 1.0, 0.0);
  147.     glVertex2f  (-0.5,-1.0); 
  148.     glTexCoord2f( 0.0, 0.0);
  149.     glVertex2f  (-0.9,-1.0);
  150.     glTexCoord2f( 0.0, 1.0);
  151.     glVertex2f  (-0.9,-0.8);
  152.   glEnd();
  153.  
  154.  
  155.    glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
  156.    texla->GL();
  157.    cam.GL();
  158.  
  159.    glBegin(GL_QUADS);
  160.      for (int i=plochy;i;i--)
  161.        {
  162.        float y=podstava*cos(uhol_counter+i*2*PI/plochy);
  163.        float z=podstava*sin(uhol_counter+i*2*PI/plochy);
  164.  
  165.        glColor3f(0.0,0.0,0.0);
  166.        glTexCoord2f( tex_x_counter, tex_y_counter);
  167.        glVertex3f(-vyska, y, z);
  168.  
  169.        glColor3f(real_in,real_in,real_in);
  170.        glTexCoord2f( tex_x_counter, tex_y_counter+1.0);
  171.        glVertex3f(-vyska, 0, 0);
  172.  
  173.        glTexCoord2f( tex_x_counter+1.0, tex_y_counter+1.0);
  174.        glVertex3f( vyska, 0, 0);
  175.  
  176.        glColor3f(0.0,0.0,0.0);
  177.        glTexCoord2f( tex_x_counter+1.0, tex_y_counter);
  178.        glVertex3f( vyska, y, z);
  179.  
  180.        }
  181.    glEnd();
  182.  
  183. //<-
  184. return 2;
  185. }