light.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/light.h $*
  25. * *
  26. * $Author:: Jani_p $*
  27. * *
  28. * $Modtime:: 5/05/01 6:10p $*
  29. * *
  30. * $Revision:: 7 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef LIGHT_H
  39. #define LIGHT_H
  40. #include "always.h"
  41. #include "rendobj.h"
  42. #include "w3derr.h"
  43. class ChunkLoadClass;
  44. class ChunkSaveClass;
  45. /**
  46. ** LightClass
  47. ** This "render object" is a light source.
  48. */
  49. class LightClass : public RenderObjClass
  50. {
  51. public:
  52. enum LightType
  53. {
  54. POINT = 0,
  55. DIRECTIONAL,
  56. SPOT
  57. };
  58. enum FlagsType
  59. {
  60. NEAR_ATTENUATION = 0,
  61. FAR_ATTENUATION,
  62. };
  63. LightClass(LightType type = POINT);
  64. LightClass(const LightClass & src);
  65. LightClass & operator = (const LightClass &);
  66. virtual ~LightClass(void);
  67. RenderObjClass * Clone(void) const;
  68. virtual int Class_ID(void) const { return CLASSID_LIGHT; }
  69. /////////////////////////////////////////////////////////////////////////////
  70. // Render Object Interface - Rendering
  71. // Lights do not "Render" but they are vertex processors.
  72. /////////////////////////////////////////////////////////////////////////////
  73. virtual void Render(RenderInfoClass & rinfo) { }
  74. virtual bool Is_Vertex_Processor(void) { return true; }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Render Object Interface - "Scene Graph"
  77. // Lights register themselves with the scene as VertexProcessors.
  78. /////////////////////////////////////////////////////////////////////////////
  79. virtual void Notify_Added(SceneClass * scene);
  80. virtual void Notify_Removed(SceneClass * scene);
  81. /////////////////////////////////////////////////////////////////////////////
  82. // Render Object Interface - Bounding Volumes
  83. // Bounding volume of a light extends to its attenuation radius
  84. /////////////////////////////////////////////////////////////////////////////
  85. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  86. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & box) const;
  87. /////////////////////////////////////////////////////////////////////////////
  88. // LightClass Interface
  89. /////////////////////////////////////////////////////////////////////////////
  90. LightType Get_Type() {return (Type);}
  91. void Set_Intensity(float inten) { Intensity = inten; }
  92. float Get_Intensity(void) const { return Intensity; }
  93. void Set_Ambient(const Vector3 & color) { Ambient = color; }
  94. void Get_Ambient(Vector3 * set_c) const { if (set_c) { *set_c = Ambient; } }
  95. void Set_Diffuse(const Vector3 & color) { Diffuse = color; }
  96. void Get_Diffuse(Vector3 * set_c) const { if (set_c) { *set_c = Diffuse; } }
  97. void Set_Specular(const Vector3 & color) { Specular = color; }
  98. void Get_Specular(Vector3 * set_c) const { if (set_c) { *set_c = Specular; } }
  99. void Set_Far_Attenuation_Range(double fStart, double fEnd) { FarAttenStart = fStart; FarAttenEnd = fEnd; }
  100. void Get_Far_Attenuation_Range(double& fStart, double& fEnd) const { fStart = FarAttenStart; fEnd = FarAttenEnd; }
  101. void Get_Far_Attenuation_Range(float & fStart, float & fEnd) const { fStart = FarAttenStart; fEnd = FarAttenEnd; }
  102. void Set_Near_Attenuation_Range(double nStart, double nEnd) { NearAttenStart = nStart; NearAttenEnd = nEnd; }
  103. void Get_Near_Attenuation_Range(double& nStart, double& nEnd) const { nStart = NearAttenStart; nEnd = NearAttenEnd; }
  104. float Get_Attenuation_Range(void) const { return FarAttenEnd; }
  105. /////////////////////////////////////////////////////////////////////////////
  106. // Control over the light flags
  107. /////////////////////////////////////////////////////////////////////////////
  108. void Set_Flag(FlagsType flag,bool onoff) { if (onoff) { Flags |= flag; } else { Flags &= ~flag; } }
  109. int Get_Flag(FlagsType flag) const { return ((Flags & flag) != 0); }
  110. void Enable_Shadows(bool onoff) { CastShadows = onoff; }
  111. bool Are_Shadows_Enabled(void) const { return CastShadows; }
  112. LightType Get_Type (void) const { return Type; }
  113. /////////////////////////////////////////////////////////////////////////////
  114. // Spotlight controls:
  115. /////////////////////////////////////////////////////////////////////////////
  116. void Set_Spot_Angle(float a) { SpotAngle = a; SpotAngleCos = WWMath::Fast_Cos(a); }
  117. float Get_Spot_Angle(void) const { return SpotAngle; }
  118. float Get_Spot_Angle_Cos(void) const { return SpotAngleCos; }
  119. void Set_Spot_Direction(const Vector3 & dir) { SpotDirection = dir; }
  120. void Get_Spot_Direction(Vector3 & dir) const { dir = SpotDirection; }
  121. void Set_Spot_Exponent(float k) { SpotExponent = k; }
  122. float Get_Spot_Exponent(void) const { return SpotExponent; }
  123. /////////////////////////////////////////////////////////////////////////////
  124. // Save/Load
  125. /////////////////////////////////////////////////////////////////////////////
  126. WW3DErrorType Load_W3D(ChunkLoadClass & cload);
  127. WW3DErrorType Save_W3D(ChunkSaveClass & csave);
  128. /////////////////////////////////////////////////////////////////////////////
  129. // Persistant object save-load interface
  130. /////////////////////////////////////////////////////////////////////////////
  131. virtual const PersistFactoryClass & Get_Factory (void) const;
  132. virtual bool Save (ChunkSaveClass &csave);
  133. virtual bool Load (ChunkLoadClass &cload);
  134. //bool isDonut(void) {return Donut; };
  135. //void setDonut(bool donut) { Donut = donut; };
  136. protected:
  137. LightType Type;
  138. unsigned int Flags;
  139. bool CastShadows;
  140. float Intensity;
  141. Vector3 Ambient;
  142. Vector3 Diffuse;
  143. Vector3 Specular;
  144. float NearAttenStart;
  145. float NearAttenEnd;
  146. float FarAttenStart;
  147. float FarAttenEnd;
  148. float SpotAngle;
  149. float SpotAngleCos;
  150. float SpotExponent;
  151. Vector3 SpotDirection;
  152. //bool Donut; ///does this light only apply at edges
  153. };
  154. #endif