home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 February / Chip_2001-02_cd1.bin / bonus / demos / CS / exp / SOURCES / DEMO / EFEKT_12.CPP < prev    next >
C/C++ Source or Header  |  2000-08-20  |  6KB  |  237 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_12.h"
  16. #include "syncs.h"
  17.  
  18. extern int sync_id;
  19. extern BOOL usefog;
  20. extern bool showlogo;
  21.  
  22. int  efekt_12::init()
  23. {
  24.   cout << "Efekt 12 init ... ";
  25.   start=TRUE;
  26.   counter=ZACIATOK12*refresh;
  27.  
  28.   tex_x_counter1=0;
  29.   tex_y_counter1=0.0;
  30.   uhol_counter1=0.0;
  31.   real_in1=0.0;
  32.  
  33.   tex_x_counter2=0;
  34.   tex_y_counter2=0.0;
  35.   uhol_counter2=0.0;
  36.   real_in2=0.0;
  37.  
  38.   int nas=500;
  39.  
  40.   tex_x_counter1=nas*txadd1;
  41.   tex_y_counter1=nas*tyadd1;
  42.   uhol_counter1 =nas*roll_speed1;
  43.  
  44.   tex_x_counter2=nas*txadd2;
  45.   tex_y_counter2=nas*tyadd2;
  46.   uhol_counter2 =nas*roll_speed2;
  47.  
  48.  
  49.   intens1=0.0;
  50.   intens2=0.0;
  51.   rolovanie=0.0;
  52.  
  53.   cout << "ok!" << endl;
  54.   return 1;
  55. }
  56.  
  57. int  efekt_12::load()
  58. {
  59.     cout << "Loading efekt12 ... ";
  60.     FILE *stream;
  61.  
  62.     stream=fopen(CFGNAME12,"r");
  63.     if (stream==NULL) return 0;
  64.  
  65.     fscanf(stream,"pocet ploch          %i\n",&plochy1);
  66.     fscanf(stream,"intenzita            %f\n",&intens1);
  67.     fscanf(stream,"x-krok               %f\n",&txadd1);
  68.     fscanf(stream,"y-krok               %f\n",&tyadd1);
  69.     fscanf(stream,"roll speed           %f\n",&roll_speed1);
  70.     fscanf(stream,"podstava valca       %i\n",&podstava1);
  71.     fscanf(stream,"vyska valca          %i\n",&vyska1);
  72.     float cl_r,cl_g,cl_b;
  73.     fscanf(stream,"background color     %f,%f,%f\n",&cl_r,&cl_g,&cl_b);
  74.     fscanf(stream,"visibility           %f\n",&vis);
  75.     fscanf(stream,"minvisibility        %f\n",&minvis);
  76.     fscanf(stream,"Descent origin       (%f,%f,%f)\n",&o1.x,&o1.y,&o1.z);
  77.     fscanf(stream,"Descent right        (%f,%f,%f)\n",&i1.x,&i1.y,&i1.z);
  78.     fscanf(stream,"Descent up           (%f,%f,%f)\n",&j1.x,&j1.y,&j1.z);
  79.     fscanf(stream,"Descent forward      (%f,%f,%f)\n",&k1.x,&k1.y,&k1.z);
  80.  
  81.     fscanf(stream,"pocet ploch          %i\n",&plochy2);
  82.     fscanf(stream,"intenzita            %f\n",&intens2);
  83.     fscanf(stream,"x-krok               %f\n",&txadd2);
  84.     fscanf(stream,"y-krok               %f\n",&tyadd2);
  85.     fscanf(stream,"roll speed           %f\n",&roll_speed2);
  86.     fscanf(stream,"podstava valca       %i\n",&podstava2);
  87.     fscanf(stream,"vyska valca          %i\n",&vyska2);
  88.     fscanf(stream,"Descent origin       (%f,%f,%f)\n",&o2.x,&o2.y,&o2.z);
  89.     fscanf(stream,"Descent right        (%f,%f,%f)\n",&i2.x,&i2.y,&i2.z);
  90.     fscanf(stream,"Descent up           (%f,%f,%f)\n",&j2.x,&j2.y,&j2.z);
  91.     fscanf(stream,"Descent forward      (%f,%f,%f)\n",&k2.x,&k2.y,&k2.z);
  92.     fclose(stream);
  93.  
  94.     camera1.SetAll(o1,i1,j1,k1);
  95.     camera1.FarClipplane(vis);
  96.     camera1.NearClipplane(minvis);
  97.     camera1.HorizontalFOV(PI/3);
  98.     camera1.VerticalFOV(PI/4);
  99.  
  100.     camera2.SetAll(o2,i2,j2,k2);
  101.     camera2.FarClipplane(vis);
  102.     camera2.NearClipplane(minvis);
  103.     camera2.HorizontalFOV(0.63);
  104.     camera2.VerticalFOV(0.47);
  105.  
  106.     texla=texture_library->GetOrCreate("NICETEXT.JPG");
  107.  
  108.     cout << "ok!"<<endl;
  109. }
  110.  
  111. int  efekt_12::free()  //vrati 3 ako ok, 0 ak doslo k chybe
  112. {
  113. showlogo=false;
  114. end=true;
  115. return 3;
  116. }
  117.  
  118. int  efekt_12::update()
  119. {
  120. id=Sync[GetSyncNum(float(counter)/float(refresh))].id;
  121.  
  122. rolovanie-=0.002;
  123.  
  124. tex_x_counter1+=txadd1;
  125. tex_y_counter1+=tyadd1;
  126. uhol_counter1+=roll_speed1;
  127.  
  128. tex_x_counter2+=txadd2;
  129. tex_y_counter2+=tyadd2;
  130. uhol_counter2+=roll_speed2;
  131.  
  132. if (counter/refresh>16.9) 
  133.   {
  134.   if (intens1>0.0) intens1-=0.02; else intens1=0.0;
  135.   if (intens2>0.0) intens2-=0.02; else intens2=0.0;
  136.   }
  137.  else
  138.   {
  139.   if (intens1<1.0) intens1+=0.01; else intens1=1.0;
  140.   if (intens2<1.0) intens2+=0.01; else intens2=1.0;
  141.   }
  142.  
  143. return 1;
  144. }
  145.  
  146. int efekt_12::go(double t)
  147. {
  148. if (t<ZACIATOK12) return 1;
  149. if (end) return 3;
  150. if (counter>=KONIEC12*refresh) return free();
  151.  
  152. if (!start) if (!init()) return 0;
  153. int cur_frm=(int)(t*refresh);
  154. if (cur_frm>KONIEC12*refresh) cur_frm=int(KONIEC12*refresh);
  155. if (cur_frm>counter)
  156.   while (counter<cur_frm)
  157.     {
  158.     counter++;
  159.     if (counter<KONIEC12*refresh) update();
  160.     }
  161. if (counter>=KONIEC12*refresh) return free();
  162.  
  163. //tu sa kresli->
  164.   
  165.   glEnable(GL_TEXTURE_2D);
  166.   glDisable(GL_LIGHTING);
  167.   glDisable(GL_DEPTH_TEST);
  168.   glDisable(GL_CULL_FACE);
  169.   glEnable(GL_BLEND);
  170.   glBlendFunc(GL_ONE, GL_ONE);
  171.   glDisable(GL_FOG);
  172.  
  173.   texla->GL();
  174.   glBlendFunc(GL_ONE,GL_ONE);
  175.  
  176.   camera1.SetAll(o1,i1,j1,k1);
  177.   camera1.NRoll(rolovanie);
  178.   camera1.GL();
  179.   if (showlogo)
  180.     {
  181.     if (intens1||intens2) showlogo=false;
  182.     }
  183.  
  184.    glBegin(GL_QUADS);
  185.    if (intens1>0.0)
  186.      for (int i=plochy1;i;i--)
  187.        {
  188.        float y=podstava1*cos(uhol_counter1+i*2*PI/plochy1);
  189.        float z=podstava1*sin(uhol_counter1+i*2*PI/plochy1);
  190.  
  191.        glColor3f(0.0,0.0,0.0);
  192.        glTexCoord2f( tex_x_counter1, tex_y_counter1);
  193.        glVertex3f(-vyska2, y, z);
  194.  
  195.        glColor3f(intens1,intens1,intens1*0.3);
  196.        glTexCoord2f( tex_x_counter1, tex_y_counter1+1.0);
  197.        glVertex3f(-vyska2, 0, 0);
  198.  
  199.        glTexCoord2f( tex_x_counter1+1.0, tex_y_counter1+1.0);
  200.        glVertex3f( vyska2, 0, 0);
  201.  
  202.        glColor3f(0.0,0.0,0.0);
  203.        glTexCoord2f( tex_x_counter1+1.0, tex_y_counter1);
  204.        glVertex3f( vyska2, y, z);
  205.        }
  206.    glEnd();
  207.  
  208.  
  209.   glBlendFunc(GL_ZERO,GL_ONE_MINUS_SRC_COLOR);
  210.    camera2.GL();
  211.    glBegin(GL_QUADS);
  212.    if (intens2>0.0)
  213.      for (int i=plochy2;i;i--)
  214.        {
  215.        float y=podstava2*cos(uhol_counter2+i*2*PI/plochy2);
  216.        float z=podstava2*sin(uhol_counter2+i*2*PI/plochy2);
  217.  
  218.        glColor3f(0.0,0.0,0.0);
  219.        glTexCoord2f( tex_x_counter2, tex_y_counter2);
  220.        glVertex3f(-vyska2, y, z);
  221.  
  222.        glColor3f(intens2,intens2,intens2);
  223.        glTexCoord2f( tex_x_counter2, tex_y_counter2+1.0);
  224.        glVertex3f(-vyska2, 0, 0);
  225.                         
  226.        glTexCoord2f( tex_x_counter2+1.0, tex_y_counter2+1.0);
  227.        glVertex3f( vyska2, 0, 0);
  228.  
  229.        glColor3f(0.0,0.0,0.0);
  230.        glTexCoord2f( tex_x_counter2+1.0, tex_y_counter2);
  231.        glVertex3f( vyska2, y, z);
  232.        }
  233.    glEnd();
  234.  
  235. //<-
  236. return 2;
  237. }