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

  1. /*
  2.  
  3. tesla 2 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_08.h"
  16. #include "syncs.h"
  17.  
  18. extern int sync_id;
  19. extern BOOL usefog;
  20.  
  21. int  efekt_08::init()
  22. {
  23.   cout << "Efekt 08 init ... ";
  24.   start=TRUE;
  25.   counter=ZACIATOK08*refresh;
  26.   tex_x_counter=0;
  27.   tex_y_counter=0.0;
  28.   real_in=0.0;
  29.   intens=0.0;
  30.   cout << "ok!" << endl;
  31.   return 1;
  32. }
  33.  
  34. int  efekt_08::load()
  35. {
  36.     cout << "Loading efekt08 ... ";
  37.     Vector3f o,i,j,k;
  38.     FILE *stream;
  39.  
  40.     stream=fopen(CFGNAME08,"r");
  41.     if (stream==NULL) return 0;
  42.  
  43.     fscanf(stream,"pocet ploch          %i\n",&plochy);
  44.     fscanf(stream,"intenzita            %f\n",&intensr);
  45.     fscanf(stream,"x-krok               %f\n",&txadd);
  46.     fscanf(stream,"y-krok               %f\n",&tyadd);
  47.     fscanf(stream,"roll speed           %f\n",&roll_speed);
  48.     fscanf(stream,"podstava valca       %i\n",&podstava);
  49.     fscanf(stream,"vyska valca          %i\n",&vyska);
  50.     float cl_r,cl_g,cl_b;
  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.     camera.SetAll(o,i,j,k);
  61.     camera.FarClipplane(vis);
  62.     camera.NearClipplane(minvis);
  63.     camera.HorizontalFOV(0.63);
  64.     camera.VerticalFOV(0.47);
  65.     texla=texture_library->GetOrCreate("NICETEXT.JPG");
  66.  
  67.     cout << "ok!"<<endl;
  68. }
  69.  
  70. int  efekt_08::free()  //vrati 3 ako ok, 0 ak doslo k chybe
  71. {
  72. end=true;
  73. return 3;
  74. }
  75.  
  76. int  efekt_08::update()
  77. {
  78. id=Sync[GetSyncNum(float(counter)/float(refresh))].id;
  79.  
  80. tex_x_counter+=txadd;
  81. tex_y_counter+=tyadd;
  82. uhol_counter+=roll_speed;
  83. if ((counter/refresh)<142)
  84.   {
  85.   if (intens<intensr) intens+=0.002;
  86.              else intens=intensr;
  87.   }
  88.   else
  89.   {
  90.   if (intens>0.0) intens-=0.001;
  91.              else intens=0.0;
  92.   if (intens>0.5) intens-=0.003;   
  93.   }
  94.  
  95. return 1;
  96. }
  97.  
  98. int efekt_08::go(double t)
  99. {
  100. if (t<ZACIATOK08) return 1;
  101. if (end) return 3;
  102. if (counter>=KONIEC08*refresh) return free();
  103.  
  104. if (!start) if (!init()) return 0;
  105. int cur_frm=(int)(t*refresh);
  106. if (cur_frm>KONIEC08*refresh) cur_frm=int(KONIEC08*refresh);
  107. if (cur_frm>counter)
  108.   while (counter<cur_frm)
  109.     {
  110.     counter++;
  111.     if (counter<KONIEC08*refresh) update();
  112.     }
  113. if (counter>=KONIEC08*refresh) return free();
  114.  
  115. //tu sa kresli->
  116.   
  117.   glEnable(GL_TEXTURE_2D);
  118.   glDisable(GL_LIGHTING);
  119.   glDisable(GL_DEPTH_TEST);
  120.   glDisable(GL_CULL_FACE);
  121.   glEnable(GL_BLEND);
  122.   glBlendFunc(GL_ONE, GL_ONE);
  123.   glDisable(GL_FOG);
  124.  
  125.   texla->GL();
  126.   camera.GL();
  127.  
  128.   if (intens>0.0)
  129.    glBegin(GL_QUADS);
  130.  
  131.      for (int i=plochy;i;i--)
  132.        {
  133.        float y=podstava*cos(uhol_counter+i*2*PI/plochy);
  134.        float z=podstava*sin(uhol_counter+i*2*PI/plochy);
  135.  
  136.        glColor3f(0.0,0.0,0.0);
  137.        glTexCoord2f( tex_x_counter, tex_y_counter);
  138.        glVertex3f(-vyska, y, z);
  139.  
  140.        glColor3f(intens,intens,intens);
  141.        glTexCoord2f( tex_x_counter, tex_y_counter+1.0);
  142.        glVertex3f(-vyska, 0, 0);
  143.  
  144.        glTexCoord2f( tex_x_counter+1.0, tex_y_counter+1.0);
  145.        glVertex3f( vyska, 0, 0);
  146.  
  147.        glColor3f(0.0,0.0,0.0);
  148.        glTexCoord2f( tex_x_counter+1.0, tex_y_counter);
  149.        glVertex3f( vyska, y, z);
  150.  
  151.        }
  152.    glEnd();
  153. //<-
  154. return 2;
  155. }