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 / walk / gib.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-27  |  2.2 KB  |  119 lines

  1. #include "walk.h"
  2.  
  3. int gib::step(int dt)
  4. {
  5.     if (numbounces==0)
  6.     {
  7.         life-=dt;
  8.         return 0;
  9.     }
  10.     else
  11.     {
  12.         force.z-=gravity*dt;
  13.         particle::step(dt);
  14.         force.null();
  15.         if (hm)
  16.         {
  17.             if (flyengine->hitobj && flyengine->hitmesh->localfaces==0)
  18.             {
  19.                 hitmark *tmp=(hitmark *)hm->clone();
  20.                 tmp->mode=0;
  21.                 tmp->pos=flyengine->hitip+flyengine->hitmesh->faces[flyengine->hitface]->normal;
  22.                 tmp->align_z(flyengine->hitmesh->faces[flyengine->hitface]->normal);
  23.                 if (flyengine->hitmesh->faces[flyengine->hitface]->normal.z>0.7)
  24.                     if (--numbounces==0)
  25.                     {
  26.                     pos=tmp->pos;
  27.                     vel.null();
  28.                     gravity=0.0f;
  29.                     }
  30.                 flyengine->activate(tmp);
  31.             }
  32.             
  33.             if (flyengine->cur_time-lasttrail>traildelay)
  34.             {
  35.                 lasttrail=flyengine->cur_time;
  36.                 hitmark *tmp=(hitmark *)hm->clone();
  37.                 tmp->mode=1;
  38.                 tmp->pos=pos;
  39.                 tmp->life>>=2;
  40.                 tmp->size*=0.5f;
  41.                 flyengine->activate(tmp);
  42.             }
  43.             
  44.         }
  45.         return 1;
  46.     }
  47. }
  48.  
  49. int gib::get_custom_param_desc(int i,param_desc *pd)
  50. {
  51.     if (pd!=0)
  52.     switch(i)
  53.     {
  54.         case 0:
  55.             pd->type='3';
  56.             pd->data=&objmesh;
  57.             strcpy(pd->name,"mesh");
  58.             break;
  59.         case 1:
  60.             pd->type=TYPE_HITMARK;
  61.             pd->data=&hm;
  62.             strcpy(pd->name,"hitmark");
  63.             break;
  64.         case 2:
  65.             pd->type='f';
  66.             pd->data=&gravity;
  67.             strcpy(pd->name,"gravity");
  68.             break;
  69.         case 3:
  70.             pd->type='i';
  71.             pd->data=&fadetime;
  72.             strcpy(pd->name,"fadetime");
  73.             break;
  74.         case 4:
  75.             pd->type='i';
  76.             pd->data=&numbounces;
  77.             strcpy(pd->name,"numbounces");
  78.             break;
  79.         case 5:
  80.             pd->type='i';
  81.             pd->data=&traildelay;
  82.             strcpy(pd->name,"traildelay");
  83.             break;
  84.     }
  85.     return 6;
  86. }
  87.  
  88. void gib::draw()
  89. {
  90.     if (life<0 || objmesh==0) return;
  91.     
  92.     if (node)
  93.         {
  94.         objmesh->color=node->color+dynlight;
  95.         dynlight.null();
  96.         }
  97.     if (life<fadetime)
  98.         objmesh->color.w=(float)life/fadetime;
  99.     else objmesh->color.w=1.0f;
  100.  
  101.     glPushMatrix();
  102.     glTranslatef(pos.x,pos.y,pos.z);
  103.     glMultMatrixf((float *)&mat);
  104.     objmesh->draw();
  105.     glPopMatrix();
  106. }
  107.  
  108. int gib::message(vector& p,float rad,int msg,int param,void *data)
  109. {
  110.     if (msg==FLYOBJM_ILLUM)
  111.     {
  112.         float fac=(p-pos).length()/rad;
  113.         if (fac<1.0f)
  114.             dynlight+=*((vector *)data)*(1.0f-fac);
  115.     }
  116.  
  117.     return 1;
  118. }
  119.