home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Jeux / demos / crystalPPC.lha / light.cpp < prev    next >
C/C++ Source or Header  |  1998-02-05  |  3KB  |  122 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 LIGHT_H
  10. #include "light.h"
  11. #endif
  12.  
  13. #ifndef TOKEN_H
  14. #include "token.h"
  15. #endif
  16.  
  17. #ifndef SECTOR_H
  18. #include "sector.h"
  19. #endif
  20.  
  21. //---------------------------------------------------------------------------
  22.  
  23. Light::Light (float x, float y, float z, float dist,
  24.           float strength, float red_strength, float blue_strength)
  25. {
  26.   center.x = x;
  27.   center.y = y;
  28.   center.z = z;
  29.   Light::dist = dist;
  30.   Light::sqdist = dist*dist;
  31.   Light::strength = strength;
  32.   Light::red_strength = red_strength;
  33.   Light::blue_strength = blue_strength;
  34. }
  35.  
  36. Light::~Light ()
  37. {
  38. }
  39.  
  40. void Light::save (FILE* fp, int indent)
  41. {
  42.   char sp[100]; strcpy (sp, spaces); sp[indent] = 0;
  43.   fprintf (fp, "%sLIGHT (%f,%f,%f),%f,%f,%f,%f\n", sp,
  44.       center.x, center.y, center.z, dist,
  45.     strength, red_strength, blue_strength);
  46. }
  47.  
  48. void Light::load (char** buf)
  49. {
  50.   skip_token (buf, "LIGHT");
  51.   skip_token (buf, "(", "Expected '%s' instead of '%s' after LIGHT statement!\n");
  52.   center.x = get_token_float (buf);
  53.   skip_token (buf, ",", "Expected '%s' instead of '%s' for LIGHT statement!\n");
  54.   center.y = get_token_float (buf);
  55.   skip_token (buf, ",", "Expected '%s' instead of '%s' for LIGHT statement!\n");
  56.   center.z = get_token_float (buf);
  57.   skip_token (buf, ")", "Expected '%s' instead of '%s' for LIGHT statement!\n");
  58.   skip_token (buf, ",", "Expected '%s' instead of '%s' for LIGHT statement!\n");
  59.   dist = get_token_float (buf);
  60.   sqdist = dist*dist;
  61.   skip_token (buf, ",", "Expected '%s' instead of '%s' for LIGHT statement!\n");
  62.   strength = get_token_float (buf);
  63.   skip_token (buf, ",", "Expected '%s' instead of '%s' for LIGHT statement!\n");
  64.   red_strength = get_token_float (buf);
  65.   skip_token (buf, ",", "Expected '%s' instead of '%s' for LIGHT statement!\n");
  66.   blue_strength = get_token_float (buf);
  67. }
  68.  
  69. void Light::shine ()
  70. {
  71.   sector->clear_shine_done ();
  72.   sector->shine (this);
  73. }
  74.  
  75. int Light::hit_beam (Vector3& start, Vector3& end, Polygon3D* poly)
  76. {
  77.   return sector->hit_beam (start, end, poly);
  78. }
  79.  
  80. //---------------------------------------------------------------------------
  81.  
  82. DynLight::DynLight (float x, float y, float z, float dist,
  83.           float strength, float red_strength, float blue_strength)
  84. {
  85.   center.x = x;
  86.   center.y = y;
  87.   center.z = z;
  88.   DynLight::dist = dist;
  89.   DynLight::sqdist = dist*dist;
  90.   DynLight::strength = strength;
  91.   DynLight::red_strength = red_strength;
  92.   DynLight::blue_strength = blue_strength;
  93.  
  94.   num_polygon = 0;
  95. }
  96.  
  97. DynLight::~DynLight ()
  98. {
  99. }
  100.  
  101. void DynLight::setup ()
  102. {
  103.   sector->clear_shine_done ();
  104.   sector->setup_dyn_light (this);
  105. }
  106.  
  107. void DynLight::add_polygon (Polygon3D* p)
  108. {
  109.   polygons[num_polygon++] = p;
  110. }
  111.  
  112. void DynLight::shine ()
  113. {
  114.   int i;
  115.   for (i = 0 ; i < num_polygon ; i++)
  116.   {
  117.     //@@@
  118.   }
  119. }
  120.  
  121. //---------------------------------------------------------------------------
  122.