VisPointNode.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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/VisPointNode.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 3/26/01 2:46p $*
  29. * *
  30. * $Revision:: 11 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "vispointnode.h"
  37. #include "sceneeditor.h"
  38. #include "collisiongroups.h"
  39. #include "persistfactory.h"
  40. #include "editorchunkids.h"
  41. #include "preset.h"
  42. #include "chunkio.h"
  43. #include "visenum.h"
  44. #include "camera.h"
  45. #include "ccamera.h"
  46. #include "combat.h"
  47. #include "nodemgr.h"
  48. #include "modelutils.h"
  49. //////////////////////////////////////////////////////////////////////////////
  50. // Persist factory
  51. //////////////////////////////////////////////////////////////////////////////
  52. SimplePersistFactoryClass<VisPointNodeClass, CHUNKID_NODE_VIS_POINT> _VisPointodePersistFactory;
  53. enum
  54. {
  55. CHUNKID_VARIABLES = 0x11011130,
  56. CHUNKID_BASE_CLASS
  57. };
  58. enum
  59. {
  60. VARID_TILE_LOCATION = 0x01,
  61. VARID_NEAR_CLIP_DOUBLE,
  62. VARID_HFOV,
  63. VARID_VFOV,
  64. VARID_NEAR_CLIP
  65. };
  66. //////////////////////////////////////////////////////////////////////////////
  67. //
  68. // VisPointNodeClass
  69. //
  70. //////////////////////////////////////////////////////////////////////////////
  71. VisPointNodeClass::VisPointNodeClass (PresetClass *preset)
  72. : m_PhysObj (NULL),
  73. m_VisTileLocation (0, 0, 0),
  74. m_NearClipPlane (0),
  75. m_HFov (0),
  76. m_VFov (0),
  77. NodeClass (preset)
  78. {
  79. return ;
  80. }
  81. //////////////////////////////////////////////////////////////////////////////
  82. //
  83. // VisPointNodeClass
  84. //
  85. //////////////////////////////////////////////////////////////////////////////
  86. VisPointNodeClass::VisPointNodeClass (const VisPointNodeClass &src)
  87. : m_PhysObj (NULL),
  88. m_VisTileLocation (0, 0, 0),
  89. NodeClass (NULL)
  90. {
  91. *this = src;
  92. return ;
  93. }
  94. //////////////////////////////////////////////////////////////////////////////
  95. //
  96. // ~VisPointNodeClass
  97. //
  98. //////////////////////////////////////////////////////////////////////////////
  99. VisPointNodeClass::~VisPointNodeClass (void)
  100. {
  101. Remove_From_Scene ();
  102. MEMBER_RELEASE (m_PhysObj);
  103. return ;
  104. }
  105. //////////////////////////////////////////////////////////////////////////////
  106. //
  107. // Initialize
  108. //
  109. // Note: This may be called more than once. It is used as an 'initialize'
  110. // and a 're-initialize'.
  111. //
  112. //////////////////////////////////////////////////////////////////////////////
  113. void
  114. VisPointNodeClass::Initialize (void)
  115. {
  116. MEMBER_RELEASE (m_PhysObj);
  117. //
  118. // Create the camera render object
  119. //
  120. RenderObjClass *render_obj = ::Create_Render_Obj ("CAMERA");
  121. WWASSERT (render_obj != NULL);
  122. if (render_obj != NULL) {
  123. // Create the new physics object
  124. m_PhysObj = new DecorationPhysClass;
  125. //
  126. // Configure the physics object with information about
  127. // its new render object and collision data.
  128. //
  129. m_PhysObj->Set_Model (render_obj);
  130. m_PhysObj->Set_Transform (Matrix3D(1));
  131. m_PhysObj->Set_Collision_Group (EDITOR_COLLISION_GROUP);
  132. m_PhysObj->Peek_Model ()->Set_User_Data ((PVOID)&m_HitTestInfo, FALSE);
  133. m_PhysObj->Set_Transform (m_Transform);
  134. ::Set_Model_Collision_Type (m_PhysObj->Peek_Model (), COLLISION_TYPE_6);
  135. // Release our hold on the render object pointer
  136. MEMBER_RELEASE (render_obj);
  137. }
  138. return ;
  139. }
  140. ////////////////////////////////////////////////////////////////
  141. //
  142. // Get_Factory
  143. //
  144. ////////////////////////////////////////////////////////////////
  145. const PersistFactoryClass &
  146. VisPointNodeClass::Get_Factory (void) const
  147. {
  148. return _VisPointodePersistFactory;
  149. }
  150. /////////////////////////////////////////////////////////////////
  151. //
  152. // Save
  153. //
  154. /////////////////////////////////////////////////////////////////
  155. bool
  156. VisPointNodeClass::Save (ChunkSaveClass &csave)
  157. {
  158. csave.Begin_Chunk (CHUNKID_BASE_CLASS);
  159. NodeClass::Save (csave);
  160. csave.End_Chunk ();
  161. csave.Begin_Chunk (CHUNKID_VARIABLES);
  162. WRITE_MICRO_CHUNK (csave, VARID_TILE_LOCATION, m_VisTileLocation);
  163. WRITE_MICRO_CHUNK (csave, VARID_NEAR_CLIP, m_NearClipPlane);
  164. WRITE_MICRO_CHUNK (csave, VARID_HFOV, m_HFov);
  165. WRITE_MICRO_CHUNK (csave, VARID_VFOV, m_VFov);
  166. csave.End_Chunk ();
  167. return true;
  168. }
  169. /////////////////////////////////////////////////////////////////
  170. //
  171. // Load
  172. //
  173. /////////////////////////////////////////////////////////////////
  174. bool
  175. VisPointNodeClass::Load (ChunkLoadClass &cload)
  176. {
  177. while (cload.Open_Chunk ()) {
  178. switch (cload.Cur_Chunk_ID ()) {
  179. case CHUNKID_BASE_CLASS:
  180. NodeClass::Load (cload);
  181. break;
  182. case CHUNKID_VARIABLES:
  183. Load_Variables (cload);
  184. break;
  185. }
  186. cload.Close_Chunk ();
  187. }
  188. return true;
  189. }
  190. ///////////////////////////////////////////////////////////////////////
  191. //
  192. // Load_Variables
  193. //
  194. ///////////////////////////////////////////////////////////////////////
  195. bool
  196. VisPointNodeClass::Load_Variables (ChunkLoadClass &cload)
  197. {
  198. //
  199. // Loop through all the microchunks that define the variables
  200. //
  201. while (cload.Open_Micro_Chunk ()) {
  202. switch (cload.Cur_Micro_Chunk_ID ()) {
  203. READ_MICRO_CHUNK (cload, VARID_TILE_LOCATION, m_VisTileLocation);
  204. READ_MICRO_CHUNK (cload, VARID_NEAR_CLIP, m_NearClipPlane);
  205. READ_MICRO_CHUNK (cload, VARID_HFOV, m_HFov);
  206. READ_MICRO_CHUNK (cload, VARID_VFOV, m_VFov);
  207. case VARID_NEAR_CLIP_DOUBLE:
  208. {
  209. double double_value = 0;
  210. cload.Read (&double_value, sizeof (double_value));
  211. m_NearClipPlane = double_value;
  212. }
  213. break;
  214. }
  215. cload.Close_Micro_Chunk ();
  216. }
  217. //
  218. // Copy the game camera's settings if we hadn't saved the settings
  219. // the last time.
  220. //
  221. if (m_NearClipPlane == 0 || m_HFov == 0 || m_VFov == 0) {
  222. m_NearClipPlane = 0.5;
  223. m_HFov = 0.8726F;
  224. m_VFov = 0.6544F;
  225. }
  226. return true;
  227. }
  228. ///////////////////////////////////////////////////////////////////////
  229. //
  230. // Set_Transform
  231. //
  232. ///////////////////////////////////////////////////////////////////////
  233. void
  234. VisPointNodeClass::Set_Transform (const Matrix3D &tm)
  235. {
  236. NodeClass::Set_Transform (tm);
  237. m_VisTileLocation = m_Transform.Get_Translation ();
  238. return ;
  239. }
  240. /////////////////////////////////////////////////////////////////
  241. //
  242. // operator=
  243. //
  244. /////////////////////////////////////////////////////////////////
  245. const VisPointNodeClass &
  246. VisPointNodeClass::operator= (const VisPointNodeClass &src)
  247. {
  248. m_VisTileLocation = src.m_VisTileLocation;
  249. NodeClass::operator= (src);
  250. return *this;
  251. }
  252. /////////////////////////////////////////////////////////////////
  253. //
  254. // Save_Camera_Settings
  255. //
  256. /////////////////////////////////////////////////////////////////
  257. void
  258. VisPointNodeClass::Save_Camera_Settings (const CameraClass &camera)
  259. {
  260. float far_clip = 0;
  261. camera.Get_Clip_Planes (m_NearClipPlane, far_clip);
  262. m_HFov = camera.Get_Horizontal_FOV ();
  263. m_VFov = camera.Get_Vertical_FOV ();
  264. return ;
  265. }
  266. /////////////////////////////////////////////////////////////////
  267. //
  268. // Setup_Camera
  269. //
  270. /////////////////////////////////////////////////////////////////
  271. void
  272. VisPointNodeClass::Setup_Camera (CameraClass &camera)
  273. {
  274. camera.Set_View_Plane (m_HFov, m_VFov);
  275. camera.Set_Clip_Planes (m_NearClipPlane, VIS_FAR_CLIP);
  276. return ;
  277. }
  278. //////////////////////////////////////////////////////////////////////
  279. //
  280. // Pre_Export
  281. //
  282. //////////////////////////////////////////////////////////////////////
  283. void
  284. VisPointNodeClass::Pre_Export (void)
  285. {
  286. //
  287. // Remove ourselves from the 'system' so we don't get accidentally
  288. // saved during the export.
  289. //
  290. Add_Ref ();
  291. if (m_PhysObj != NULL && m_IsInScene) {
  292. ::Get_Scene_Editor ()->Remove_Object (m_PhysObj);
  293. }
  294. return ;
  295. }
  296. //////////////////////////////////////////////////////////////////////
  297. //
  298. // Post_Export
  299. //
  300. //////////////////////////////////////////////////////////////////////
  301. void
  302. VisPointNodeClass::Post_Export (void)
  303. {
  304. //
  305. // Put ourselves back into the system
  306. //
  307. if (m_PhysObj != NULL && m_IsInScene) {
  308. ::Get_Scene_Editor ()->Add_Dynamic_Object (m_PhysObj);
  309. }
  310. Release_Ref ();
  311. return ;
  312. }