staticphys.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/staticphys.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 2/18/02 2:13p $*
  29. * *
  30. * $Revision:: 34 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef STATICPHYS_H
  39. #define STATICPHYS_H
  40. #include "phys.h"
  41. #include "pscene.h"
  42. #include "wwdebug.h"
  43. #include "physcoltest.h"
  44. #include "physinttest.h"
  45. #include "vector.h"
  46. class StaticPhysDefClass;
  47. /**
  48. ** StaticPhysClass
  49. ** This class implements an object meant to be placed in the static object
  50. ** culling system. Static objects are used to make up the bulk of the geometry for the
  51. ** static environment.
  52. **
  53. */
  54. class StaticPhysClass : public PhysClass
  55. {
  56. public:
  57. StaticPhysClass(void);
  58. ~StaticPhysClass(void);
  59. virtual StaticPhysClass * As_StaticPhysClass(void) { return this; }
  60. StaticPhysDefClass * Get_StaticPhysDef(void) { return (StaticPhysDefClass *)Definition; }
  61. void Init(const StaticPhysDefClass & def);
  62. virtual bool Needs_Timestep(void) { return false; }
  63. virtual void Timestep(float dt) { };
  64. virtual void Set_Model(RenderObjClass * model);
  65. virtual void Render_Vis_Meshes(RenderInfoClass & rinfo);
  66. /*
  67. ** Collision detection - all collideable objects provide the following collision detection
  68. ** functions so that other objects do not pass through them. These functions should test
  69. ** the given primitive against this object's geometric representation.
  70. */
  71. virtual bool Cast_Ray(PhysRayCollisionTestClass & raytest);
  72. virtual bool Cast_AABox(PhysAABoxCollisionTestClass & boxtest);
  73. virtual bool Cast_OBBox(PhysOBBoxCollisionTestClass & boxtest);
  74. virtual bool Intersection_Test(PhysAABoxIntersectionTestClass & test);
  75. virtual bool Intersection_Test(PhysOBBoxIntersectionTestClass & test);
  76. virtual bool Intersection_Test(PhysMeshIntersectionTestClass & test);
  77. bool Intersects(const OBBoxClass & obbox);
  78. virtual const AABoxClass & Get_Bounding_Box(void) const;
  79. virtual const Matrix3D & Get_Transform(void) const;
  80. virtual void Set_Transform(const Matrix3D & m);
  81. /*
  82. ** Classify this object for the visibility culling system. If the rendered
  83. ** representation of this object is translucent or if the object has multiple render
  84. ** states (e.g. an object that is destructible or can have its model be replaced)
  85. ** then the object cannot be treated as an occluder.
  86. */
  87. int Is_Occluder(void);
  88. /*
  89. ** Classify whether the model for this object is pre-lit. In this case, we don't
  90. ** apply static lights or static projectors to it since their effect should be cooked
  91. ** into the pre-processed lighting
  92. */
  93. bool Is_Model_Pre_Lit(void);
  94. bool Is_Model_User_Lit(void);
  95. /*
  96. ** Vis Data access. In addition to having a vis object id, static physics objects
  97. ** can define vis-sectors.
  98. */
  99. void Set_Vis_Sector_ID(int new_id);
  100. int Get_Vis_Sector_ID(void) const { return VisSectorID; }
  101. bool Is_Vis_Sector(RenderObjClass * model = NULL) const;
  102. /*
  103. ** Simulation and rendering toggles for all static physics objects
  104. */
  105. virtual bool Is_Simulation_Disabled(void) { return _DisableStaticPhysSimulation; }
  106. virtual bool Is_Rendering_Disabled(void) { return _DisableStaticPhysRendering; }
  107. static void Disable_All_Simulation(bool onoff) { _DisableStaticPhysSimulation = onoff; }
  108. static void Disable_All_Rendering(bool onoff) { _DisableStaticPhysRendering = onoff; }
  109. static bool Is_All_Simulation_Disabled(void) { return _DisableStaticPhysSimulation; }
  110. static bool Is_All_Rendering_Disabled(void) { return _DisableStaticPhysRendering; }
  111. /*
  112. ** Save-Load of state. This interface is used to restore the state of any static
  113. ** objects in the level. Static objects are not re-created when a save-game is created
  114. ** instead, their state is restored.
  115. */
  116. virtual bool Has_Dynamic_State(void) { return false; }
  117. virtual void Save_State(ChunkSaveClass & csave) { }
  118. virtual void Load_State(ChunkLoadClass & cload) { }
  119. /*
  120. ** Save-Load System
  121. */
  122. virtual const PersistFactoryClass & Get_Factory (void) const;
  123. virtual bool Save (ChunkSaveClass &csave);
  124. virtual bool Load (ChunkLoadClass &cload);
  125. virtual void On_Post_Load(void);
  126. float Compute_Vis_Mesh_Ram(RenderObjClass * model = NULL);
  127. protected:
  128. void Update_Cached_Model_Parameters(void);
  129. virtual void Update_Sun_Status(void);
  130. protected:
  131. int VisSectorID; // set if this static object contains a vis sector mesh (-1 if not)
  132. private:
  133. static bool _DisableStaticPhysSimulation;
  134. static bool _DisableStaticPhysRendering;
  135. StaticPhysClass(const StaticPhysClass &);
  136. StaticPhysClass & operator = (const StaticPhysClass &);
  137. };
  138. /**
  139. ** StaticPhysDefClass
  140. ** Definition data structure for StaticPhysClass
  141. */
  142. class StaticPhysDefClass : public PhysDefClass
  143. {
  144. public:
  145. StaticPhysDefClass(void);
  146. // From DefinitionClass
  147. virtual uint32 Get_Class_ID (void) const;
  148. virtual PersistClass * Create(void) const;
  149. // From PhysDefClass
  150. virtual const char * Get_Type_Name(void);
  151. virtual bool Is_Type(const char *);
  152. // From PersistClass
  153. virtual const PersistFactoryClass & Get_Factory (void) const;
  154. virtual bool Save(ChunkSaveClass &csave);
  155. virtual bool Load(ChunkLoadClass &cload);
  156. // Editable interface requirements
  157. DECLARE_EDITABLE(StaticPhysDefClass,PhysDefClass);
  158. protected:
  159. bool IsNonOccluder;
  160. friend class StaticPhysClass;
  161. };
  162. /*
  163. **
  164. ** Inline Functions
  165. **
  166. */
  167. inline bool StaticPhysClass::Cast_Ray(PhysRayCollisionTestClass & raytest)
  168. {
  169. WWASSERT(Model);
  170. if (Model->Cast_Ray(raytest)) {
  171. raytest.CollidedPhysObj = this;
  172. return true;
  173. } else {
  174. return false;
  175. }
  176. }
  177. inline bool StaticPhysClass::Cast_AABox(PhysAABoxCollisionTestClass & boxtest)
  178. {
  179. WWASSERT(Model);
  180. if (Model->Cast_AABox(boxtest)) {
  181. boxtest.CollidedPhysObj = this;
  182. return true;
  183. } else {
  184. return false;
  185. }
  186. }
  187. inline bool StaticPhysClass::Cast_OBBox(PhysOBBoxCollisionTestClass & boxtest)
  188. {
  189. WWASSERT(Model);
  190. if (Model->Cast_OBBox(boxtest)) {
  191. boxtest.CollidedPhysObj = this;
  192. return true;
  193. } else {
  194. return false;
  195. }
  196. }
  197. inline bool StaticPhysClass::Intersection_Test(PhysAABoxIntersectionTestClass & test)
  198. {
  199. if (Model->Intersect_AABox(test)) {
  200. test.Add_Intersected_Object(this);
  201. return true;
  202. }
  203. return false;
  204. }
  205. inline bool StaticPhysClass::Intersection_Test(PhysOBBoxIntersectionTestClass & test)
  206. {
  207. if (Model->Intersect_OBBox(test)) {
  208. test.Add_Intersected_Object(this);
  209. return true;
  210. }
  211. return false;
  212. }
  213. inline bool StaticPhysClass::Intersection_Test(PhysMeshIntersectionTestClass & test)
  214. {
  215. WWASSERT(0); // TODO: Mesh-Mesh intersection
  216. return false;
  217. }
  218. inline bool StaticPhysClass::Intersects(const OBBoxClass & obbox)
  219. {
  220. CastResultStruct result;
  221. PhysOBBoxCollisionTestClass boxtest( obbox,
  222. Vector3(0,0,0),
  223. &result,
  224. 0x0F,
  225. 1);
  226. Cast_OBBox(boxtest);
  227. return result.StartBad;
  228. }
  229. #endif