home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Jeux / demos / crystalPPC.lha / light.h < prev    next >
C/C++ Source or Header  |  1998-01-15  |  3KB  |  106 lines

  1. #ifndef LIGHT_H
  2. #define LIGHT_H
  3.  
  4. #ifndef MATH3D_H
  5. #include "math3d.h"
  6. #endif
  7.  
  8. class Sector;
  9. class Polygon3D;
  10.  
  11. #define DEFAULT_LIGHT_LEVEL 40        // Light level that is used when there is no light on the texture.
  12. #define NORMAL_LIGHT_LEVEL 200        // Light level that corresponds to a normally lit texture.
  13.  
  14. // Class for a static light. These lights cast shadows (against
  15. // sector boundaries and with things), they support three different
  16. // colors (default white, red, and blue). They cannot move and
  17. // they cannot vary in intensity.
  18.  
  19. class Light
  20. {
  21. private:
  22.   Sector* sector;
  23.   Vector3 center;
  24.   float dist, sqdist;
  25.   float strength;
  26.   float red_strength;
  27.   float blue_strength;
  28.  
  29. public:
  30.   Light (float x, float y, float z, float dist,
  31.        float strength, float red_strength, float blue_strength);
  32.   ~Light ();
  33.  
  34.   void set_sector (Sector* sector) { Light::sector = sector; }
  35.  
  36.   Vector3& get_center () { return center; }
  37.   float get_dist () { return dist; }
  38.   float get_sq_dist () { return sqdist; }
  39.   float get_strength () { return strength; }
  40.   float get_red_strength () { return red_strength; }
  41.   float get_blue_strength () { return blue_strength; }
  42.  
  43.   void save (FILE* fp, int indent);
  44.   void load (char** buf);
  45.  
  46.   void shine ();
  47.   int hit_beam (Vector3& start, Vector3& end, Polygon3D* poly);
  48. };
  49.  
  50. // Dynamic lights can light maximum 200 polygons.
  51. #define MAX_DYN_POLYGON 200
  52.  
  53. // Class for a dynamic light. These lights don't cast shadows (in contrast
  54. // with static lights) but they can move and vary in intensity.
  55.  
  56. class DynLight
  57. {
  58. private:
  59.   DynLight* next, * prev;
  60.  
  61.   Sector* sector;
  62.   Vector3 center;
  63.   float dist, sqdist;
  64.   float strength;
  65.   float red_strength;
  66.   float blue_strength;
  67.  
  68.   int num_polygon;
  69.   Polygon3D* polygons[MAX_DYN_POLYGON];
  70.  
  71. public:
  72.   DynLight (float x, float y, float z, float dist,
  73.        float strength, float red_strength, float blue_strength);
  74.   ~DynLight ();
  75.  
  76.   // Initial placement of the light. This routine computes all
  77.   // polygons that are theoretically reached by this light (by using
  78.   // the squared distance) and adjusts these polygons so that they
  79.   // know about this light.
  80.   void setup ();
  81.  
  82.   // Every polygon that is shined upon by this dynamic light
  83.   // should call 'add_polygon' to register itself.
  84.   void add_polygon (Polygon3D* p);
  85.  
  86.   // After running setup use this routine when the intensity or
  87.   // color of the light changes. This will update information in
  88.   // all the polygons reached by this light.
  89.   void shine ();
  90.  
  91.   void set_sector (Sector* sector) { DynLight::sector = sector; }
  92.   void set_next (DynLight* n) { next = n; }
  93.   void set_prev (DynLight* p) { prev = p; }
  94.   DynLight* get_next () { return next; }
  95.   DynLight* get_prev () { return prev; }
  96.  
  97.   Vector3& get_center () { return center; }
  98.   float get_dist () { return dist; }
  99.   float get_sq_dist () { return sqdist; }
  100.   float get_strength () { return strength; }
  101.   float get_red_strength () { return red_strength; }
  102.   float get_blue_strength () { return blue_strength; }
  103. };
  104.  
  105. #endif /*LIGHT_H*/
  106.