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 / ship / container.cpp next >
Encoding:
C/C++ Source or Header  |  2000-01-29  |  2.5 KB  |  132 lines

  1. #include "game.h"
  2.  
  3. void container::init()
  4. {
  5.     if (objmesh)
  6.         pos=objmesh->pivotpos;
  7. }
  8.  
  9. void container::draw()
  10. {
  11.     if (objmesh)
  12.     {
  13.     if (node)
  14.         {
  15.         objmesh->color=node->color+dynlight;
  16.         if (objmesh->color.x>1.0f) objmesh->color.x=1.0f;
  17.         if (objmesh->color.y>1.0f) objmesh->color.y=1.0f;
  18.         if (objmesh->color.z>1.0f) objmesh->color.z=1.0f;
  19.         objmesh->color.w=1;
  20.         dynlight.null();
  21.         }
  22.     glPushMatrix();
  23.     glTranslatef(pos.x,pos.y,pos.z);
  24.     glMultMatrixf((float *)&mat);
  25.     objmesh->draw();
  26.     glPopMatrix();
  27.     }
  28. }
  29.  
  30. int container::step(int dt)
  31. {
  32.     if (shield<0)
  33.     {
  34.         life=-1;
  35.         if (exp)
  36.             exp->do_explode(pos,Z,-1);
  37.         if (p)
  38.         {
  39.             powerup *tmp=(powerup *)p->clone();
  40.             tmp->pos=pos;
  41.             flyengine->activate(tmp);
  42.         }
  43.     }
  44.     return 0;
  45. }
  46.  
  47. int container::get_custom_param_desc(int i,param_desc *pd)
  48. {
  49.     if (pd==0)
  50.         return 4;
  51.     else 
  52.     switch(i)
  53.     {
  54.         case 0:
  55.             pd->type='3';
  56.             pd->data=&objmesh;
  57.             strcpy(pd->name,"objmesh");
  58.             break;
  59.         case 1:
  60.             pd->type=TYPE_EXPLODE;
  61.             pd->data=&exp;
  62.             strcpy(pd->name,"explode");
  63.             break;
  64.         case 2:
  65.             pd->type=TYPE_POWERUP;
  66.             pd->data=&p;
  67.             strcpy(pd->name,"powerup");
  68.             break;
  69.         case 3:
  70.             pd->type='f';
  71.             pd->data=&shield;
  72.             strcpy(pd->name,"shield");
  73.             break;
  74.     }
  75.     return 0;
  76. }
  77.  
  78. int container::message(vector& p,float rad,int msg,int param,void *data)
  79. {
  80.     if (msg==FLYOBJM_DAMAGE)
  81.     {
  82.         vector v=pos-p;
  83.         float len=v.length();
  84.         if (len>rad || len<SMALL)
  85.             return 0;
  86.  
  87.         flyengine->excludecollision=this;
  88.         if(flyengine->collision_test(flyengine->bsp, p, pos))
  89.         {
  90.             flyengine->excludecollision=0;
  91.             return 0;
  92.         }
  93.         flyengine->excludecollision=0;
  94.  
  95.         shield-=*((float *)data)*(1.0f-len/rad);
  96.     }
  97.     else
  98.     if (msg==FLYOBJM_ILLUM)
  99.     {
  100.         float fac=(p-pos).length()/rad;
  101.         if (fac<1.0f)
  102.             dynlight+=*((vector *)data)*(1.0f-fac);
  103.     }
  104.  
  105.     return 0;
  106. }
  107.  
  108. mesh *container::ray_intersect(vector& ro,vector& rd,vector& ip,float& dist,int &facenum,float rad)
  109. {
  110.     if (objmesh)
  111.     {
  112.         static float d1,d2;
  113.         vector 
  114.             ro_local=(ro-pos)*mat_t,
  115.             rd_local=rd*mat_t;
  116.         if (objmesh->bbox.ray_intersect(ro_local,rd_local,d1,d2))
  117.         {
  118.         facenum=objmesh->ray_intersect(ro_local,rd_local,ip,dist,rad);
  119.         if (facenum>-1)
  120.             {
  121.             if (flyengine->stepobj && 
  122.                 (flyengine->stepobj->type==TYPE_LASER || flyengine->stepobj->type==TYPE_MISSILE) 
  123.                 && dist<1.0f && ((gun_projectile *)flyengine->stepobj)->damage>0.0f)
  124.                 shield-=((gun_projectile *)flyengine->stepobj)->damage;
  125.             ip=ip*mat+pos;
  126.             return objmesh;
  127.             }
  128.         }
  129.     }
  130.     return 0;
  131. }
  132.