home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / plugin / gamelib / fao_mesh.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-10  |  2.0 KB  |  121 lines

  1. #include "..\..\lib\Fly3D.h"
  2. #include "gamelib.h"
  3.  
  4. void fao_mesh::init()
  5. {
  6.     if (o)
  7.         pos=o->pivotpos;
  8. }
  9.  
  10. void fao_mesh::draw()
  11. {
  12.     if (o)
  13.     {
  14.     if (node)
  15.         {
  16.         o->color=node->color+dynlight;
  17.         dynlight.null();
  18.         }
  19.     glPushMatrix();
  20.     glTranslatef(pos.x,pos.y,pos.z);
  21.     glMultMatrixf((float *)&mat);
  22.     o->draw();
  23.     glPopMatrix();
  24.     }
  25. }
  26.  
  27. mesh *fao_mesh::ray_intersect(vector& ro,vector& rd,vector& ip,float& dist,int &facenum,float rad)
  28. {
  29.     if (o)
  30.     {
  31.     facenum=o->ray_intersect((ro-pos)*mat_t,rd*mat_t,ip,dist);
  32.     if (facenum!=-1)
  33.         {
  34.         if (flyengine->moving && timeactivate==0)
  35.             timeactivate=flyengine->cur_time;
  36.         ip=ip*mat+pos;
  37.         return o;
  38.         }
  39.     }
  40.     return 0;
  41. }
  42.  
  43. int fao_mesh::step(int dt)    
  44. {
  45.     if (o==0) 
  46.         return 0;
  47.     if (mode==0)
  48.         if (time)
  49.         {
  50.             rotate(rot*(float)dt);
  51.             o->set_key((float)((flyengine->cur_time-timeactivate)%time)/time);
  52.         }
  53.         else ;
  54.     else
  55.     if (timeactivate)
  56.     {
  57.         int t=flyengine->cur_time-timeactivate;
  58.         if (t>delay+time*2+wait)
  59.             {
  60.             o->set_key(0);
  61.             timeactivate=0;
  62.             }
  63.         else
  64.         if (t>delay+time+wait)
  65.             o->set_key(0.5f+(float)(t-(delay+time+wait))/time*0.5f);
  66.         else
  67.         if (t>delay+time)
  68.             ;
  69.         else 
  70.         if (t>delay)
  71.             o->set_key((float)(t-delay)/time*0.5f);
  72.     }
  73.     return 0;
  74. }
  75.  
  76. int fao_mesh::get_custom_param_desc(int i,param_desc *pd)
  77. {
  78.     if (pd!=0)
  79.     switch(i)
  80.     {
  81.         case 0:
  82.             pd->type='m';
  83.             pd->data=&o;
  84.             strcpy(pd->name,"animobj");
  85.             break;
  86.         case 1:
  87.             pd->type='i';
  88.             pd->data=&mode;
  89.             strcpy(pd->name,"mode");
  90.             break;
  91.         case 2:
  92.             pd->type='i';
  93.             pd->data=&time;
  94.             strcpy(pd->name,"time");
  95.             break;
  96.         case 3:
  97.             pd->type='i';
  98.             pd->data=&delay;
  99.             strcpy(pd->name,"delay");
  100.             break;
  101.         case 4:
  102.             pd->type='i';
  103.             pd->data=&wait;
  104.             strcpy(pd->name,"wait");
  105.             break;
  106.     }
  107.     return 5;
  108. }
  109.  
  110. int fao_mesh::message(vector& p,float rad,int msg,int param,void *data)
  111. {
  112.     if (msg==FLYOBJM_ILLUM)
  113.     {
  114.         float fac=(p-pos).length()/rad;
  115.         if (fac<1.0f)
  116.             dynlight+=*((vector *)data)*(1.0f-fac);
  117.     }
  118.  
  119.     return 1;
  120. }
  121.