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

  1. /*
  2.  
  3. end_picture
  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_18.h"
  16. #include "syncs.h"
  17.  
  18. extern int sync_id;
  19.  
  20. int  efekt_18::init()
  21. {
  22.     cout << "Efekt 18 init ... ";
  23.     start=TRUE;
  24.     counter=ZACIATOK18*refresh;
  25. //->init
  26.     z=1.0;
  27.     color=1.0;
  28.     nxtcolor=1.0;
  29. //<-
  30.     cout << "ok" << endl;
  31.     return 1;
  32. }
  33.  
  34. int  efekt_18::load()
  35. {
  36.     cout << "Loading efekt18 ... ";
  37. // -> load
  38.     endtex=texture_library->GetOrCreate("END.JPG");
  39. // <-
  40.     cout << "ok!"<<endl;
  41.     return 1;
  42. }
  43.  
  44. int  efekt_18::free()  //vrati 3 ako ok, 0 ak doslo k chybe
  45. {
  46.     end=true;
  47.     cout << "Efekt 18 free ... ";
  48. // -> free
  49. // <-
  50.     cout << "ok!" << endl;
  51.     return 3;
  52. }
  53.  
  54. int  efekt_18::update()
  55. {
  56.     id=Sync[GetSyncNum(float(counter)/float(refresh))].id;
  57. // -> update
  58.     z-=0.0007;
  59.     if (counter/refresh>210)
  60.       {
  61.       if (color>0.0) color-=0.0026;
  62.                 else color=0.0;
  63.       nxtcolor=color-0.0026;
  64.       if (nxtcolor<0.0) nxtcolor=0.0;
  65.       }
  66. // <-
  67.     return 1;
  68. }  
  69.  
  70. int efekt_18::go(double t)
  71. {
  72. if (t<ZACIATOK18) return 1;
  73. if (end) return 3;
  74. if (counter>=KONIEC18*refresh) return free();
  75.  
  76. if (!start) if (!init()) return 0;
  77. int cur_frm=(int)(t*refresh);
  78. if (cur_frm>KONIEC18*refresh) cur_frm=int(KONIEC18*refresh);
  79. if (cur_frm>counter)
  80.   while (counter<cur_frm)
  81.     {
  82.     counter++;
  83.     if (counter<KONIEC18*refresh) update();
  84.     }
  85. if (counter>=KONIEC18*refresh) return free();
  86. //tu sa kresli->
  87.  
  88.   glClearColor(nxtcolor,nxtcolor,nxtcolor,1.0);
  89.   glMatrixMode(GL_PROJECTION);
  90.   glLoadIdentity();
  91.   glMatrixMode(GL_MODELVIEW);
  92.   glLoadIdentity();
  93.  
  94.   glEnable(GL_TEXTURE_2D);
  95.   glDisable(GL_LIGHTING);
  96.   glDisable(GL_CULL_FACE);
  97.   glDisable(GL_BLEND);
  98.   glDisable(GL_FOG);
  99.  
  100.   endtex->GL();
  101.  
  102.  
  103.   float zz=1.0/z;
  104.   glBegin(GL_QUADS);
  105.     glColor3f(color,color,color);
  106.  
  107.     glTexCoord2f(1,1);
  108.     glVertex2f(zz,zz);
  109.  
  110.     glTexCoord2f(0,1);
  111.     glVertex2f(-zz,zz);
  112.  
  113.     glTexCoord2f(0,0);
  114.     glVertex2f(-zz,-zz);
  115.  
  116.     glTexCoord2f(1,0);
  117.     glVertex2f(zz,-zz); 
  118.   glEnd();
  119.  
  120. //<-
  121. return 2;
  122. }