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 / cartoon_mesh.cpp next >
Encoding:
C/C++ Source or Header  |  2000-11-21  |  1.4 KB  |  79 lines

  1. #include "..\..\lib\Fly3D.h"
  2. #include "gamelib.h"
  3.  
  4. void cartoon_mesh::init()
  5. {
  6.     if (objmesh)
  7.     {
  8.         pos=objmesh->pivotpos;
  9.         if (objmesh->edges==0)
  10.             objmesh->compute_normals(MESH_EDGES);
  11.     }
  12. }
  13.  
  14. void cartoon_mesh::draw()
  15. {
  16.     if (objmesh)
  17.     {
  18.     // position the object
  19.     glPushMatrix();
  20.     glTranslatef(pos.x,pos.y,pos.z);
  21.     glMultMatrixf((float *)&mat);
  22.  
  23.     // compute ambient light
  24.     vector ambient;
  25.     if (node)
  26.         ambient=node->color;
  27.     else ambient.null();
  28.  
  29.     vector v=flyengine->cam->pos-pos;
  30.     float f=v.length()/flyengine->viewmaxdist;
  31.     if (f<1.0f)
  32.         f=(1.0f-f)*flyengine->cartoonwidth;
  33.     else f=0.0f;
  34.     
  35.     // make light positions local to object
  36.     for( int i=0;i<lights.nlights;i++ )
  37.         lights.pos[i]-=pos;
  38.     // draw object as cartoon
  39.     objmesh->draw_cartoon(v,ambient,lights,f);
  40.     //clear lights
  41.     lights.nlights=0;
  42.  
  43.     glPopMatrix();
  44.     }
  45. }
  46.  
  47. bsp_object *cartoon_mesh::clone()
  48. {
  49.     cartoon_mesh *tmp=new cartoon_mesh;
  50.     *tmp=*this;
  51.     tmp->source=this;
  52.     return tmp;
  53. }
  54.  
  55. int cartoon_mesh::get_custom_param_desc(int i,param_desc *pd)
  56. {
  57.     if (pd!=0)
  58.     switch(i)
  59.     {
  60.     case 0:
  61.         pd->type='3';
  62.         pd->data=&objmesh;
  63.         strcpy(pd->name,"objmesh");
  64.         break;
  65.     }
  66.     return 1;
  67. }
  68.  
  69. int cartoon_mesh::message(vector& p,float rad,int msg,int param,void *data)
  70. {
  71.     if (msg==FLYOBJM_CHANGEPARAM && param>=0)
  72.         init();
  73.     else
  74.     if (msg==FLYOBJM_ILLUM || msg==FLYOBJM_DYNILLUM)
  75.         lights.add_light(p,*((vector *)data),rad);
  76.  
  77.     return 0;
  78. }
  79.