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

  1. /*
  2.  
  3. chodby,reaktor - 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_05.h"
  16.  
  17. extern int sync_num;
  18. extern BOOL usefog;
  19.  
  20. int efekt_05::init()
  21. {
  22.   cout << "Efekt 5 init ... ";
  23.   start=TRUE;
  24.   counter=ZACIATOK05*refresh;
  25.   glClearColor (cl_r, cl_g, cl_b, 1.0);
  26.   uhol_counter=0.003*58;
  27.   uhol=0.3*58;
  28.  
  29.   angel_counter=-0.001*58;
  30.   angel=-0.3*58;
  31.  
  32.   dmat2=new DmatrixOrientation<GLmatrix,GLfloat>;
  33.   dmat1=new DmatrixOrientation<GLmatrix,GLfloat>;
  34.  
  35.  
  36.   dmat1->Pivot(-116.071,25276.918,57.4357);
  37.   dmat2->Pivot(-116.071,25276.918,57.4357);
  38. //  Material3DS* ma = sce->GetMaterial("Material #23");
  39. //  ma->Diffuse(0.5F, 0.5F, 0.5F);
  40.   cout << "ok!" << endl;
  41. return 1;
  42. }
  43.  
  44. int efekt_05::load()
  45. {
  46.    cout << "Loading efekt05 ... ";
  47.    FILE *stream=fopen(CFGNAME05,"r");
  48.    if (stream==NULL) return 0;
  49.    fscanf(stream,"file name            %s\n",scene_name);
  50.    fscanf(stream,"camera name          %s\n",camera_name);
  51.    fscanf(stream,"begin                %f\n",&begin3d);
  52.    fscanf(stream,"end                  %f\n",&end3d);
  53.    fscanf(stream,"background color     %f,%f,%f\n",&cl_r,&cl_g,&cl_b);
  54.    fscanf(stream,"lightning            %i\n",&lgt);
  55.    fscanf(stream,"fog                  %i\n",&fog);
  56.    fscanf(stream,"fog color            %f,%f,%f\n",&fg_r,&fg_g,&fg_b);
  57.    fscanf(stream,"fog density          %f\n",&fgd);
  58.    fscanf(stream,"visibility           %f\n",&vis);
  59.    fscanf(stream,"minvisibility        %f\n",&minvis);
  60.    fscanf(stream,"hfov,vfov (PI/x)     %f,%f\n",&hfov,&vfov);
  61.    fscanf(stream,"render               %i\n",&render);
  62.    fscanf(stream,"rays                 %i\n",&rays);
  63.    fscanf(stream,"outline              %i\n",&obrysy);
  64.    fscanf(stream,"outline color        %f,%f,%f\n",&ob_r,&ob_g,&ob_b);
  65.    fscanf(stream,"outline width        %i\n",&ob_wdt);
  66.    fscanf(stream,"object name          %s\n",object_name);
  67.    fclose(stream);
  68.    fog&=usefog;
  69.    Loader3DS loader;
  70.    sce = loader.Load(scene_name,texture_library);
  71.    if (sce==NULL) return 0;
  72.    gula1=dynamic_cast<Object3DS*>(sce->GetObject("Sphere01"));
  73.    gula2=dynamic_cast<Object3DS*>(sce->GetObject("Sphere02"));
  74.    cout << "ok!"<<endl;
  75. return 1;
  76. }
  77.  
  78. int efekt_05::free() //vrati 3 ak ok, 0 ak doslo k chybe
  79. {
  80. end=true;
  81. return 1;
  82. }
  83.  
  84. int efekt_05::update()
  85. {
  86. uhol+=0.3;
  87. uhol_counter+=0.003;
  88.  
  89. angel-=0.3;
  90. angel_counter-=0.001;
  91.  
  92. return 1;
  93. }
  94.  
  95. int efekt_05::go(double t)
  96. {
  97. if (t<ZACIATOK05) return 1;
  98. if (t<begin3d) return 1;
  99. if (end) return 3;
  100. if (counter>=KONIEC05*refresh) return free();
  101.  
  102. if (!start) if (!init()) return 0;
  103.  
  104. int cur_frm=(int)(t*refresh);
  105. if (cur_frm>KONIEC05*refresh) cur_frm=int(KONIEC05*refresh);
  106. if (cur_frm>counter)
  107.   while (counter<cur_frm)
  108.     {
  109.     counter++;
  110.     if (counter<KONIEC05*refresh) update();
  111.     }
  112. if (counter>=KONIEC05*refresh) return free();
  113.  
  114. //tu sa kresli->
  115.   if (lgt) 
  116.     {
  117.     glEnable(GL_LIGHTING);    
  118.     glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  119.     }
  120.    else 
  121.     glDisable(GL_LIGHTING);    
  122.  
  123.   if (fog) 
  124.     {
  125.     GLfloat fc[4] = {fg_r,fg_g,fg_b, 1.0};
  126.     glEnable(GL_FOG);
  127.     glFogi(GL_FOG_MODE, GL_EXP2);
  128.     glFogfv(GL_FOG_COLOR, fc);
  129.     glFogf(GL_FOG_DENSITY, fgd);
  130.     }
  131.    else glDisable(GL_FOG);    
  132.  
  133.   float frejm=(t-begin3d)/(end3d-begin3d);
  134.   kam = sce->GetCamera(camera_name);
  135.   kam->FarClipplane(vis);
  136.   kam->NearClipplane(minvis);
  137.   kam->HorizontalFOV(PI/hfov);
  138.   kam->VerticalFOV(PI/vfov);
  139.   kam->GL(frejm);
  140.  
  141. //vyrata os, okolo ktorej sa otaca
  142.    float alfa=PI*sin(uhol_counter);
  143.    float beta=PI*cos(uhol_counter);
  144.    float gama=PI*sin(PI*cos(uhol_counter));
  145.    float sa=sin(alfa),sb=sin(beta),sg=sin(gama);
  146.    float ca=cos(alfa),cb=cos(beta),cg=cos(gama);
  147.    Vector3f os(ca*cg+sa*sb*sg , ca*cb , cb*cg);
  148.    float osl = (1.0/sqrt(os.x*os.x + os.y*os.y + os.z*os.z));
  149.    os*=osl;
  150.  
  151.    dmat1->Orientation(uhol*PI/180, os.x,os.y,os.z);
  152.    gula1->CoordinateSystem(dmat1);
  153.  
  154.    alfa=PI*sin(angel_counter);
  155.    beta=PI*cos(angel_counter);
  156.    gama=PI*sin(PI*cos(angel_counter));
  157.    sa=sin(alfa),sb=sin(beta),sg=sin(gama);
  158.    ca=cos(alfa),cb=cos(beta),cg=cos(gama);
  159.    os(ca*cg+sa*sb*sg , ca*cb , cb*cg);
  160.    osl = (1.0/sqrt(os.x*os.x + os.y*os.y + os.z*os.z));
  161.    os*=osl;
  162.  
  163.    dmat2->Orientation(angel*PI/180, os.x,os.y,os.z);
  164.    gula2->CoordinateSystem(dmat2);
  165.  
  166.  
  167.   if (render) sce->Render(frejm);
  168.  
  169.   if (obrysy||rays)
  170.     {
  171.     Object3DS* object = dynamic_cast<Object3DS*>(sce->GetObject(object_name));
  172.     if(object)
  173.       {
  174.       Vector3f S( 0.0, 200.0, 0.0);
  175.       Vector3f C=kam->Origin(frejm);
  176.       if (rays)   object->Rays(C, S, 420, GL_ONE, GL_ONE);
  177.       if (obrysy) object->Outline (C, 8, 1.0,1.0,1.0);
  178.       }
  179.     }
  180. //<-
  181. return 2;
  182. }
  183.