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

  1. /*
  2.  
  3. stena - 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_04.h"
  16.  
  17. extern int sync_num;
  18. extern BOOL usefog;
  19.  
  20. int efekt_04::init()
  21. {
  22.   cout << "Efekt 4 init ... ";
  23.   start=TRUE;
  24.   counter=ZACIATOK04*refresh;
  25.   glClearColor (cl_r, cl_g, cl_b, 1.0);
  26.   cout << "ok!" << endl;
  27. return 1;
  28. }
  29.  
  30. int efekt_04::load()
  31. {
  32.    cout << "Loading efekt04 ... ";
  33.    FILE *stream=fopen(CFGNAME04,"r");
  34.    if (stream==NULL) return 0;
  35.    fscanf(stream,"file name            %s\n",scene_name);
  36.    fscanf(stream,"camera name          %s\n",camera_name);
  37.    fscanf(stream,"begin                %f\n",&begin3d);
  38.    fscanf(stream,"end                  %f\n",&end3d);
  39.    fscanf(stream,"background color     %f,%f,%f\n",&cl_r,&cl_g,&cl_b);
  40.    fscanf(stream,"lightning            %i\n",&lgt);
  41.    fscanf(stream,"fog                  %i\n",&fog);
  42.    fscanf(stream,"fog color            %f,%f,%f\n",&fg_r,&fg_g,&fg_b);
  43.    fscanf(stream,"fog density          %f\n",&fgd);
  44.    fscanf(stream,"visibility           %f\n",&vis);
  45.    fscanf(stream,"minvisibility        %f\n",&minvis);
  46.    fscanf(stream,"hfov,vfov (PI/x)     %f,%f\n",&hfov,&vfov);
  47.    fscanf(stream,"render               %i\n",&render);
  48.    fscanf(stream,"rays                 %i\n",&rays);
  49.    fscanf(stream,"outline              %i\n",&obrysy);
  50.    fscanf(stream,"outline color        %f,%f,%f\n",&ob_r,&ob_g,&ob_b);
  51.    fscanf(stream,"outline width        %i\n",&ob_wdt);
  52.    fscanf(stream,"object name          %s\n",object_name);
  53.    fclose(stream);
  54.    fog&=usefog;
  55.    Loader3DS loader;
  56.    sce = loader.Load(scene_name,texture_library);
  57.    if (sce==NULL) return 0;
  58.    cout << "ok!"<<endl;
  59. return 1;
  60. }
  61.  
  62. int efekt_04::free() //vrati 3 ak ok, 0 ak doslo k chybe
  63. {
  64. end=true;
  65. return 1;
  66. }
  67.  
  68. int efekt_04::update()
  69. {
  70. return 1;
  71. }
  72.  
  73. int efekt_04::go(double t)
  74. {
  75. if (t<ZACIATOK04) return 1;
  76. if (t<begin3d) return 1;
  77. if (end) return 3;
  78. if (t>=KONIEC04) return free();
  79.  
  80. if (!start) if (!init()) return 0;
  81. /*
  82. int cur_frm=(int)(t*refresh);
  83. if (cur_frm>KONIEC04*refresh) cur_frm=int(KONIEC04*refresh);
  84. if (cur_frm>counter)
  85.   while (counter<cur_frm)
  86.     {
  87.     counter++;
  88.     if (counter<KONIEC04*refresh) update();
  89.     }
  90. if (counter>=KONIEC04*refresh) return free();
  91. */
  92. //tu sa kresli->
  93.   if (lgt) 
  94.     {
  95.     glEnable(GL_LIGHTING);    
  96.     glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  97.     }
  98.    else 
  99.     glDisable(GL_LIGHTING);    
  100.  
  101.   if (fog) 
  102.     {
  103.     GLfloat fc[4] = {fg_r,fg_g,fg_b, 1.0};
  104.     glEnable(GL_FOG);
  105.     glFogi(GL_FOG_MODE, GL_EXP2);
  106.     glFogfv(GL_FOG_COLOR, fc);
  107.     glFogf(GL_FOG_DENSITY, fgd);
  108.     }
  109.    else glDisable(GL_FOG);    
  110.  
  111.   float frejm=(t-begin3d)/(end3d-begin3d);
  112.   kam = sce->GetCamera(camera_name);
  113.   kam->FarClipplane(vis);
  114.   kam->NearClipplane(minvis);
  115.   kam->HorizontalFOV(PI/hfov);
  116.   kam->VerticalFOV(PI/vfov);
  117.   kam->GL(frejm);
  118.   if (render) sce->Render(frejm);
  119.  
  120.   if (obrysy||rays)
  121.     {
  122.     Object3DS* object = dynamic_cast<Object3DS*>(sce->GetObject(object_name));
  123.     if(object)
  124.       {
  125.       Vector3f S( 0.0, 200.0, 0.0);
  126.       Vector3f C=kam->Origin(frejm);
  127.       if (rays)   object->Rays(C, S, 420, GL_ONE, GL_ONE);
  128.       if (obrysy) object->Outline (C, 8, 1.0,1.0,1.0);
  129.       }
  130.     }
  131. //<-
  132. return 2;
  133. }
  134.