home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Jeux / demos / crystalPPC.lha / lightmap.cpp < prev    next >
C/C++ Source or Header  |  1998-02-05  |  2KB  |  109 lines

  1. #include <math.h>
  2. #include <time.h>
  3. #include "system.h"
  4.  
  5. #ifndef DEF_H
  6. #include "def.h"
  7. #endif
  8.  
  9. #ifndef LIGHTMAP_H
  10. #include "lightmap.h"
  11. #endif
  12.  
  13. #ifndef TEXTURE_H
  14. #include "texture.h"
  15. #endif
  16.  
  17. #ifndef POLYGON_H
  18. #include "polygon.h"
  19. #endif
  20.  
  21. #ifndef SECTOR_H
  22. #include "sector.h"
  23. #endif
  24.  
  25. //---------------------------------------------------------------------------
  26.  
  27. int LightMap::setting = MIPMAP_SHADOW_ACCURATE;
  28.  
  29. LightMap::LightMap ()
  30. {
  31.   light_map = NULL;
  32.   red_light_map = NULL;
  33.   blue_light_map = NULL;
  34. }
  35.  
  36. LightMap::~LightMap ()
  37. {
  38.   if (light_map) delete [] light_map;
  39.   if (red_light_map) delete [] red_light_map;
  40.   if (blue_light_map) delete [] blue_light_map;
  41. }
  42.  
  43. void LightMap::alloc (int w, int h, Polygon3D* poly)
  44. {
  45.   size = w*h;
  46.   int i;
  47.   if (light_map)
  48.   {
  49.     delete [] light_map;
  50.     light_map = NULL;
  51.   }
  52.   if (red_light_map)
  53.   {
  54.     delete [] red_light_map;
  55.     red_light_map = NULL;
  56.   }
  57.   if (blue_light_map)
  58.   {
  59.     delete [] blue_light_map;
  60.     blue_light_map = NULL;
  61.   }
  62.  
  63.   if (size > 1000000) return;
  64.  
  65.   int lw = w/16+2;
  66.   int lh = h/16+2;
  67.   light_map = new unsigned char [lw*lh];
  68.   red_light_map = new unsigned char [lw*lh];
  69.   blue_light_map = new unsigned char [lw*lh];
  70.   if (poly)
  71.     for (i = 0 ; i < lw*lh ; i++)
  72.     {
  73.       light_map[i] = poly->get_sector ()->get_level1 ();
  74.       red_light_map[i] = poly->get_sector ()->get_level2 ();
  75.       blue_light_map[i] = poly->get_sector ()->get_level3 ();
  76.     }
  77. }
  78.  
  79. void LightMap::mipmap_lightmap (int w, int h, LightMap* source, int w2, int h2)
  80. {
  81.   alloc (w, h, NULL);
  82.  
  83.   if (size > 1000000 || source->size > 1000000) return;
  84.   int lw = w/16+2;
  85.   int lh = h/16+2;
  86.   int lw2 = w2/16+2;
  87.   int lh2 = h2/16+2;
  88.   int u, v, uv, uv2;
  89.  
  90.   for (v = 0 ; v < lh ; v++)
  91.     for (u = 0 ; u < lw ; u++)
  92.     {
  93.       uv = v*lw + u;
  94.  
  95.       if (u+u >= lw2 || v+v >= lh2)
  96.       {
  97.     if (u+u >= lw2) uv2 = (v+v)*lw2 + lw2-1;
  98.     else if (v+v >= lh2) uv2 = (lh2-1)*lw2 + u+u;
  99.       }
  100.       else uv2 = (v+v)*lw2 + u+u;
  101.  
  102.       light_map[uv] = source->light_map[uv2];
  103.       red_light_map[uv] = source->red_light_map[uv2];
  104.       blue_light_map[uv] = source->blue_light_map[uv2];
  105.     }
  106. }
  107.  
  108. //---------------------------------------------------------------------------
  109.