AttenuationSphere.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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/AttenuationSphere.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 5/04/00 9:58a $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "StdAfx.h"
  36. #include "AttenuationSphere.h"
  37. #include "SphereObj.h"
  38. #include "Utils.h"
  39. #include "Node.h"
  40. #include "SceneEditor.h"
  41. ///////////////////////////////////////////////////////////////////////////////
  42. //
  43. // AttenuationSphereClass
  44. //
  45. ///////////////////////////////////////////////////////////////////////////////
  46. AttenuationSphereClass::AttenuationSphereClass (void)
  47. : m_IsInScene (false),
  48. m_Color (1, 1, 1),
  49. m_Radius (1.0F),
  50. m_Opacity (1.0F)
  51. {
  52. return ;
  53. }
  54. ///////////////////////////////////////////////////////////////////////////////
  55. //
  56. // ~AttenuationSphereClass
  57. //
  58. ///////////////////////////////////////////////////////////////////////////////
  59. AttenuationSphereClass::~AttenuationSphereClass (void)
  60. {
  61. Remove_From_Scene ();
  62. return ;
  63. }
  64. ///////////////////////////////////////////////////////////////////////////////
  65. //
  66. // Display_Around_Node
  67. //
  68. ///////////////////////////////////////////////////////////////////////////////
  69. void
  70. AttenuationSphereClass::Display_Around_Node (const NodeClass &node)
  71. {
  72. RenderObjClass *render_obj = node.Peek_Render_Obj ();
  73. if (render_obj != NULL) {
  74. Display_Around_Node (*render_obj);
  75. }
  76. return ;
  77. }
  78. ///////////////////////////////////////////////////////////////////////////////
  79. //
  80. // Display_Around_Node
  81. //
  82. ///////////////////////////////////////////////////////////////////////////////
  83. void
  84. AttenuationSphereClass::Display_Around_Node (const RenderObjClass &render_obj)
  85. {
  86. //
  87. // Make sure we have a sphere object
  88. //
  89. SphereRenderObjClass *sphere = (SphereRenderObjClass *)Peek_Model ();
  90. if (sphere == NULL) {
  91. sphere = new SphereRenderObjClass;
  92. sphere->Set_Flag (SphereRenderObjClass::USE_ALPHA_VECTOR, false);
  93. Set_Model (sphere);
  94. Set_Color (m_Color);
  95. Set_Radius (m_Radius);
  96. Set_Opacity (m_Opacity);
  97. MEMBER_RELEASE (sphere);
  98. }
  99. //
  100. // Update the sphere's position
  101. //
  102. Set_Transform (render_obj.Get_Transform ());
  103. //
  104. // Put the sphere into the scene
  105. //
  106. if (m_IsInScene == false) {
  107. ::Get_Scene_Editor ()->Add_Dynamic_Object (this);
  108. m_IsInScene = true;
  109. }
  110. return ;
  111. }
  112. ///////////////////////////////////////////////////////////////////////////////
  113. //
  114. // Remove_From_Scene
  115. //
  116. ///////////////////////////////////////////////////////////////////////////////
  117. void
  118. AttenuationSphereClass::Remove_From_Scene (void)
  119. {
  120. //
  121. // Remove the sphere from the scene
  122. //
  123. if (m_IsInScene) {
  124. ::Get_Scene_Editor ()->Remove_Object (this);
  125. m_IsInScene = false;
  126. }
  127. return ;
  128. }
  129. ///////////////////////////////////////////////////////////////////////////////
  130. //
  131. // Set_Color
  132. //
  133. ///////////////////////////////////////////////////////////////////////////////
  134. void
  135. AttenuationSphereClass::Set_Color (const Vector3 &color)
  136. {
  137. SphereRenderObjClass *sphere = (SphereRenderObjClass *)Peek_Model ();
  138. SANITY_CHECK (sphere != NULL) {
  139. return ;
  140. }
  141. m_Color = color;
  142. sphere->Set_Color (m_Color);
  143. return ;
  144. }
  145. ///////////////////////////////////////////////////////////////////////////////
  146. //
  147. // Set_Radius
  148. //
  149. ///////////////////////////////////////////////////////////////////////////////
  150. void
  151. AttenuationSphereClass::Set_Radius (float radius)
  152. {
  153. SphereRenderObjClass *sphere = (SphereRenderObjClass *)Peek_Model ();
  154. SANITY_CHECK (sphere != NULL) {
  155. return ;
  156. }
  157. m_Radius = radius;
  158. sphere->Set_Extent (Vector3 (m_Radius, m_Radius, m_Radius));
  159. sphere->Set_Transform (sphere->Get_Transform ());
  160. Update_Cull_Box ();
  161. return ;
  162. }
  163. ///////////////////////////////////////////////////////////////////////////////
  164. //
  165. // Set_Opacity
  166. //
  167. ///////////////////////////////////////////////////////////////////////////////
  168. void
  169. AttenuationSphereClass::Set_Opacity (float opacity)
  170. {
  171. SphereRenderObjClass *sphere = (SphereRenderObjClass *)Peek_Model ();
  172. SANITY_CHECK (sphere != NULL) {
  173. return ;
  174. }
  175. m_Opacity = opacity;
  176. sphere->Set_Alpha (m_Opacity);
  177. return ;
  178. }