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

  1. /*
  2.  
  3. RAY TORUS KNOT 3ds viewer
  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_13.h"
  16.  
  17. extern int sync_num;
  18.  
  19. int efekt_13::init()
  20. {
  21.   start=TRUE;
  22.   counter=ZACIATOK13*refresh;
  23.   glClearColor (cl_r, cl_g, cl_b, 1.0);
  24.   x_pos=0.0;
  25.   inten=0.0;
  26.   l1=dynamic_cast<OmniLight3DS*>(sce->GetLight("Omni01"));
  27.   l2=dynamic_cast<OmniLight3DS*>(sce->GetLight("Omni02"));
  28. return 1;
  29. }
  30.  
  31. int efekt_13::load()
  32. {
  33.    cout << "Loading efekt13 ... ";
  34.    FILE *stream=fopen(CFGNAME13,"r");
  35.    if (stream==NULL) return 0;
  36.    fscanf(stream,"file name            %s\n",scene_name);
  37.    fscanf(stream,"camera name          %s\n",camera_name);
  38.    fscanf(stream,"begin                %f\n",&begin3d);
  39.    fscanf(stream,"end                  %f\n",&end3d);
  40.    fscanf(stream,"background color     %f,%f,%f\n",&cl_r,&cl_g,&cl_b);
  41.    fscanf(stream,"lightning            %i\n",&lgt);
  42.    fscanf(stream,"fog                  %i\n",&fog);
  43.    fscanf(stream,"fog color            %f,%f,%f\n",&fg_r,&fg_g,&fg_b);
  44.    fscanf(stream,"fog density          %f\n",&fgd);
  45.    fscanf(stream,"visibility           %f\n",&vis);
  46.    fscanf(stream,"minvisibility        %f\n",&minvis);
  47.    fscanf(stream,"hfov,vfov (PI/x)     %f,%f\n",&hfov,&vfov);
  48.    fscanf(stream,"render               %i\n",&render);
  49.    fscanf(stream,"rays                 %i\n",&rays);
  50.    fscanf(stream,"outline              %i\n",&obrysy);
  51.    fscanf(stream,"outline color        %f,%f,%f\n",&ob_r,&ob_g,&ob_b);
  52.    fscanf(stream,"outline width        %i\n",&ob_wdt);
  53.    fscanf(stream,"object name          %s\n",object_name);
  54.    fclose(stream);
  55.  
  56.    Loader3DS loader;
  57.    sce = loader.Load(scene_name,texture_library);
  58.    if (sce==NULL) return 0;
  59.    cout << "ok!"<<endl;
  60. return 1;
  61. }
  62.  
  63. int efekt_13::free()
  64. {
  65. return 1;
  66. }
  67.  
  68. int efekt_13::update()
  69. {
  70. if ((counter/refresh)>153.5)
  71.   {
  72.   x_pos-=0.00002;
  73.   }
  74.  else 
  75.   {
  76.   if (x_pos<1.0) x_pos+=0.005;
  77.   }
  78.  
  79. if ((counter/refresh)>157.5)
  80.   {
  81.   x_pos-=0.01;
  82.   Vector3f l1d=l1->Diffuse();
  83.   Vector3f l2d=l2->Diffuse();
  84.  
  85.   l1->Diffuse(l1d*0.95F);
  86.   l2->Diffuse(l2d*0.95F);
  87.  
  88.   if (inten>0.0) inten-=2;
  89.               else inten=0.0;
  90.   }
  91. else
  92.  {
  93.  if (inten<550) inten+=2.6;
  94.  }
  95. return 1;
  96. }
  97.  
  98. int efekt_13::go(double t)
  99. {
  100. if (t<ZACIATOK13) return 1;
  101. if (t<begin3d) return 1;
  102. if (end) return 3;
  103. if (counter>=KONIEC13*refresh) return free();
  104.  
  105. if (!start) if (!init()) return 0;
  106.  
  107. int cur_frm=(int)(t*refresh);
  108. if (cur_frm>KONIEC13*refresh) cur_frm=int(KONIEC13*refresh);
  109. if (cur_frm>counter)
  110.   while (counter<cur_frm)
  111.     {
  112.     counter++;
  113.     if (counter<KONIEC13*refresh) update();
  114.     }
  115.  
  116. if (counter>=KONIEC13*refresh) return free();
  117.  
  118.  
  119. //tu sa kresli->
  120.  
  121.   if (lgt) 
  122.     {
  123.     glEnable(GL_LIGHTING);    
  124.     glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  125.     }
  126.    else 
  127.     glDisable(GL_LIGHTING);    
  128.  
  129.   if (fog) 
  130.     {
  131.     GLfloat fc[4] = {fg_r,fg_g,fg_b, 1.0};
  132.     glEnable(GL_FOG);
  133.     glFogi(GL_FOG_MODE, GL_EXP2);
  134.     glFogfv(GL_FOG_COLOR, fc);
  135.     glFogf(GL_FOG_DENSITY, fgd);
  136.     }
  137.    else glDisable(GL_FOG);    
  138.  
  139.   float frejm=(t-begin3d)/(end3d-begin3d);
  140.   kam = sce->GetCamera(camera_name);
  141.   kam->FarClipplane(vis);
  142.   kam->NearClipplane(minvis);
  143.   kam->HorizontalFOV(PI/hfov);
  144.   kam->VerticalFOV(PI/vfov);
  145.   kam->GL(frejm);
  146.  
  147.   if (render)
  148.     {
  149.     GLfloat len=kam->Origin(frejm).Len();
  150.  
  151.     GLmatrix m, p;
  152.     glMatrixMode(GL_MODELVIEW);
  153.     glGetFloatv(GL_MODELVIEW_MATRIX, m());
  154.     p.Identity();
  155.     p.Translate(  (90*sin(x_pos*PI/2) - 150)*len/300, 0, 0);
  156.     m = p*m;
  157.     glLoadMatrixf(m());
  158.     sce->Render(frejm);
  159.  
  160.     }
  161.  
  162.   if (obrysy||rays)
  163.     {
  164.     Object3DS* object = dynamic_cast<Object3DS*>(sce->GetObject(object_name));
  165.     if(object)
  166.       {
  167.       Vector3f S( 0.0, 200.0, 0.0);
  168.       Vector3f C=kam->Origin(frejm);
  169.       if (rays)   object->Rays(C, S, inten, GL_ONE, GL_ONE);
  170.       if (obrysy) object->Outline (C, 8, 1.0,1.0,1.0);
  171.       }
  172.     }
  173. //<-
  174. return 2;
  175. }
  176.