LightNode.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. ** Command & Conquer Renegade(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 : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/LightNode.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/14/02 5:15p $*
  29. * *
  30. * $Revision:: 11 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __LIGHT_NODE_H
  39. #define __LIGHT_NODE_H
  40. #include "node.h"
  41. #include "vector.h"
  42. #include "icons.h"
  43. #include "lightphys.h"
  44. #include "lightdefinition.h"
  45. #include "attenuationsphere.h"
  46. #include "sceneeditor.h"
  47. // Forward declarations
  48. class PresetClass;
  49. ////////////////////////////////////////////////////////////////////////////
  50. //
  51. // LightNodeClass
  52. //
  53. ////////////////////////////////////////////////////////////////////////////
  54. class LightNodeClass : public NodeClass
  55. {
  56. public:
  57. //////////////////////////////////////////////////////////////////
  58. // Public constructors/destructors
  59. //////////////////////////////////////////////////////////////////
  60. LightNodeClass (PresetClass *preset = NULL);
  61. LightNodeClass (const LightNodeClass &src);
  62. ~LightNodeClass (void);
  63. //////////////////////////////////////////////////////////////
  64. // Public operators
  65. //////////////////////////////////////////////////////////////
  66. const LightNodeClass &operator= (const LightNodeClass &src);
  67. //////////////////////////////////////////////////////////////////
  68. // Public methods
  69. //////////////////////////////////////////////////////////////////
  70. //
  71. // From PersistClass
  72. //
  73. virtual const PersistFactoryClass & Get_Factory (void) const;
  74. virtual bool Save (ChunkSaveClass &csave);
  75. virtual bool Load (ChunkLoadClass &cload);
  76. //
  77. // RTTI
  78. //
  79. LightNodeClass *As_LightNodeClass (void) { return this; }
  80. //
  81. // From NodeClass
  82. //
  83. void Initialize (void);
  84. NodeClass * Clone (void) { return new LightNodeClass (*this); }
  85. NODE_TYPE Get_Type (void) const { return NODE_TYPE_LIGHT; }
  86. int Get_Icon_Index (void) const { return LIGHT_ICON; }
  87. PhysClass * Peek_Physics_Obj (void) const { return m_DisplayObj; }
  88. bool Is_Static (void) const { return false; }
  89. bool Show_Settings_Dialog (void);
  90. bool Can_Be_Rotated_Freely (void) const { return true; }
  91. bool Is_Attenuation_Sphere_Shown (void) { return (m_Sphere != NULL); }
  92. void Show_Attenuation_Spheres (bool onoff);
  93. float Get_Attenuation_Radius (void);
  94. void Set_Attenuation_Radius (float radius);
  95. void Update_Cached_Vis_IDs (void);
  96. //
  97. // Notifications
  98. //
  99. void On_Rotate (void);
  100. void On_Translate (void);
  101. void On_Transform (void);
  102. //
  103. // Export methods
  104. //
  105. void Pre_Export (void);
  106. void Post_Export (void);
  107. //
  108. // Scene methods
  109. //
  110. void Add_To_Scene (void);
  111. void Remove_From_Scene (void);
  112. //
  113. // Light specific
  114. //
  115. void Initialize_From_Light (LightClass *light);
  116. LightClass *Peek_Light (void);
  117. LightPhysClass * Peek_Light_Phys (void) { return m_LightPhysObj; }
  118. void Set_Group_ID (int group_id);
  119. int Get_Group_ID (void) const;
  120. uint32 Get_Vis_Sector_ID (void) const { return m_VisSectorID; }
  121. void Set_Vis_Sector_ID (uint32 vis_id);
  122. protected:
  123. //////////////////////////////////////////////////////////////////
  124. // Protected methods
  125. //////////////////////////////////////////////////////////////////
  126. void Update_Light (void);
  127. bool Save_Variables (ChunkSaveClass &csave);
  128. bool Load_Variables (ChunkLoadClass &cload);
  129. //////////////////////////////////////////////////////////////////
  130. // Protected member data
  131. //////////////////////////////////////////////////////////////////
  132. LightDefinitionClass m_InstanceSettings;
  133. LightPhysClass * m_LightPhysObj;
  134. PhysClass * m_DisplayObj;
  135. AttenuationSphereClass * m_Sphere;
  136. bool m_UsePreset;
  137. uint32 m_VisSectorID;
  138. };
  139. //////////////////////////////////////////////////////////////////
  140. // On_Rotate
  141. //////////////////////////////////////////////////////////////////
  142. inline void
  143. LightNodeClass::On_Rotate (void)
  144. {
  145. if (m_LightPhysObj != NULL) {
  146. m_LightPhysObj->Set_Transform (m_Transform);
  147. ::Get_Scene_Editor ()->Update_Lighting ();
  148. }
  149. if (m_Sphere != NULL) {
  150. m_Sphere->Set_Transform (m_Transform);
  151. }
  152. NodeClass::On_Rotate ();
  153. return ;
  154. }
  155. //////////////////////////////////////////////////////////////////
  156. // On_Translate
  157. //////////////////////////////////////////////////////////////////
  158. inline void
  159. LightNodeClass::On_Translate (void)
  160. {
  161. if (m_LightPhysObj != NULL) {
  162. m_LightPhysObj->Set_Transform (m_Transform);
  163. ::Get_Scene_Editor ()->Update_Lighting ();
  164. }
  165. if (m_Sphere != NULL) {
  166. m_Sphere->Set_Transform (m_Transform);
  167. }
  168. NodeClass::On_Translate ();
  169. return ;
  170. }
  171. //////////////////////////////////////////////////////////////////
  172. // On_Transform
  173. //////////////////////////////////////////////////////////////////
  174. inline void
  175. LightNodeClass::On_Transform (void)
  176. {
  177. if (m_LightPhysObj != NULL) {
  178. m_LightPhysObj->Set_Transform (m_Transform);
  179. ::Get_Scene_Editor ()->Update_Lighting ();
  180. }
  181. if (m_Sphere != NULL) {
  182. m_Sphere->Set_Transform (m_Transform);
  183. }
  184. NodeClass::On_Transform ();
  185. return ;
  186. }
  187. //////////////////////////////////////////////////////////////////
  188. // Get_Attenuation_Radius
  189. //////////////////////////////////////////////////////////////////
  190. inline float
  191. LightNodeClass::Get_Attenuation_Radius (void)
  192. {
  193. return m_InstanceSettings.Get_Outer_Radius ();
  194. }
  195. //////////////////////////////////////////////////////////////////
  196. // Set_Attenuation_Radius
  197. //////////////////////////////////////////////////////////////////
  198. inline void
  199. LightNodeClass::Set_Attenuation_Radius (float radius)
  200. {
  201. if (radius > 0) {
  202. //
  203. // Change the settings
  204. //
  205. m_UsePreset = false;
  206. m_InstanceSettings.Set_Outer_Radius (radius);
  207. //
  208. // Update the light model
  209. //
  210. Update_Light ();
  211. //
  212. // Update the sphere (if necessary)
  213. //
  214. if (m_Sphere != NULL) {
  215. m_Sphere->Set_Radius (radius);
  216. }
  217. }
  218. return ;
  219. }
  220. //////////////////////////////////////////////////////////////////
  221. // Set_Group_ID
  222. //////////////////////////////////////////////////////////////////
  223. inline void
  224. LightNodeClass::Set_Group_ID (int group_id)
  225. {
  226. if (m_LightPhysObj != NULL) {
  227. m_LightPhysObj->Set_Group_ID (group_id);
  228. }
  229. return ;
  230. }
  231. //////////////////////////////////////////////////////////////////
  232. // Get_Group_ID
  233. //////////////////////////////////////////////////////////////////
  234. inline int
  235. LightNodeClass::Get_Group_ID (void) const
  236. {
  237. int group_id = 0;
  238. if (m_LightPhysObj != NULL) {
  239. group_id = m_LightPhysObj->Get_Group_ID ();
  240. }
  241. return group_id;
  242. }
  243. #endif //__LIGHT_NODE_H