movephys.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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/movephys.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 12/05/01 6:28p $*
  29. * *
  30. * $Revision:: 40 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef MOVEPHYS_H
  39. #define MOVEPHYS_H
  40. #include "always.h"
  41. #include "dynamicphys.h"
  42. #include "matrix3.h"
  43. #include "dynamicshadowmanager.h"
  44. class PhysControllerClass;
  45. class MoveablePhysDefClass;
  46. class DynTexProjectClass;
  47. /**
  48. ** MoveablePhysClass
  49. ** All objects that can be moved around in the world in some way will support this interface.
  50. ** This interface defines basic mass and gravity settings and gives access to the object's
  51. ** velocities.
  52. */
  53. class MoveablePhysClass : public DynamicPhysClass
  54. {
  55. public:
  56. MoveablePhysClass(void);
  57. virtual ~MoveablePhysClass(void);
  58. void Init(const MoveablePhysDefClass & definition );
  59. virtual MoveablePhysClass * As_MoveablePhysClass(void) { return this; }
  60. const MoveablePhysDefClass * Get_MoveablePhysDef(void) { return (MoveablePhysDefClass*)Definition; }
  61. /*
  62. ** DEBUGGING, re-initialize this object because our definition changed
  63. */
  64. virtual void Definition_Changed(void);
  65. /*
  66. ** PhysClass interface.
  67. ** Post_Timestep_Process - moveable objects update their shadows in post-timestep...
  68. */
  69. virtual bool Needs_Timestep(void) { return true; }
  70. virtual void Post_Timestep_Process(void);
  71. /*
  72. ** Physical properites
  73. */
  74. virtual void Set_Mass(float mass) { Mass = mass; MassInv = 1.0f / mass; }
  75. float Get_Mass(void) { return Mass; }
  76. float Get_Mass_Inv(void) { return MassInv; }
  77. virtual void Set_Gravity_Multiplier(float grav) { GravScale = grav; }
  78. float Get_Gravity_Multiplier(void) const { return GravScale; }
  79. virtual void Set_Elasticity(float e) { Elasticity = e; }
  80. float Get_Elasticity(void) const { return Elasticity; }
  81. virtual void Get_Inertia_Inv(Matrix3 * set_I_inv);
  82. /*
  83. ** Teleport support
  84. */
  85. virtual bool Can_Teleport(const Matrix3D &new_tm, bool check_dyn_only = false,NonRefPhysListClass * result_list = NULL) { return false; }
  86. virtual bool Can_Teleport_And_Stand(const Matrix3D &new_tm, Matrix3D *out) { *out = new_tm; return false; }
  87. virtual bool Find_Teleport_Location(const Vector3 &start, float radius, Vector3 *out) { return false; }
  88. virtual bool Can_Move_To(const Matrix3D &new_tm) { return false; }
  89. virtual bool Cinematic_Move_To(const Matrix3D & new_tm);
  90. /*
  91. ** Controller
  92. */
  93. void Set_Controller(PhysControllerClass * control) { Controller = control; }
  94. PhysControllerClass * Get_Controller(void) { return Controller; }
  95. /*
  96. ** Save-Load system
  97. */
  98. virtual bool Save (ChunkSaveClass &csave);
  99. virtual bool Load (ChunkLoadClass &cload);
  100. virtual void On_Post_Load (void);
  101. /*
  102. ** Access to the state of the object
  103. */
  104. virtual void Get_Velocity(Vector3 * set_vel) const = 0;
  105. virtual void Set_Velocity(const Vector3 & newvel) { }
  106. /*
  107. ** Shadow Casting.
  108. ** Get_Blob_Shadow_Bounding_Box - Should return a tight object-space aabox; used for shadow blobs
  109. */
  110. virtual void Get_Shadow_Blob_Box(AABoxClass * set_obj_space_box);
  111. virtual bool Is_Casting_Shadow(void) { return ShadowManager.Is_Casting_Shadow(); }
  112. /*
  113. ** Rider support. All moveable objects can be riders.
  114. */
  115. virtual void Link_To_Carrier(PhysClass * carrier,RenderObjClass * carrier_sub_obj = NULL);
  116. virtual PhysClass * Peek_Carrier_Object(void); // TSS added 08-15-01
  117. virtual RenderObjClass * Peek_Carrier_Sub_Object(void);
  118. protected:
  119. float Mass;
  120. float MassInv;
  121. float GravScale;
  122. float Elasticity;
  123. PhysControllerClass * Controller;
  124. PhysClass * Carrier;
  125. RenderObjClass * CarrierSubObject;
  126. DynamicShadowManagerClass ShadowManager;
  127. // Not Implemented:
  128. MoveablePhysClass(const MoveablePhysClass &);
  129. MoveablePhysClass & operator = (const MoveablePhysClass &);
  130. };
  131. inline void MoveablePhysClass::Get_Inertia_Inv(Matrix3 * set_I_inv)
  132. {
  133. set_I_inv->Make_Identity();
  134. (*set_I_inv)[0][0] = MassInv;
  135. (*set_I_inv)[1][1] = MassInv;
  136. (*set_I_inv)[2][2] = MassInv;
  137. }
  138. /*
  139. ** MoveablePhysDefClass
  140. ** Initialization Structure/Factory/Editor Integration for a MoveablePhysClass
  141. */
  142. class MoveablePhysDefClass : public DynamicPhysDefClass
  143. {
  144. public:
  145. MoveablePhysDefClass(void);
  146. // From PhysDefClass
  147. virtual const char * Get_Type_Name(void) { return "MoveablePhysDef"; }
  148. virtual bool Is_Type(const char *);
  149. // From PersistClass
  150. virtual bool Save(ChunkSaveClass &csave);
  151. virtual bool Load(ChunkLoadClass &cload);
  152. // In-Game Editing (DEBUGGING/TESTING ONLY)
  153. float Get_Mass(void) { return Mass; }
  154. float Get_Grav_Scale(void) { return GravScale; }
  155. void Set_Mass(float new_mass) { Mass = new_mass; }
  156. void Set_Grav_Scale(float new_g){ GravScale = new_g; }
  157. // Editable interface requirements
  158. DECLARE_EDITABLE(MoveablePhysDefClass,DynamicPhysDefClass);
  159. protected:
  160. float Mass;
  161. float GravScale;
  162. float Elasticity;
  163. enum {
  164. CINEMATIC_COLLISION_NONE = 0,
  165. CINEMATIC_COLLISION_STOP,
  166. CINEMATIC_COLLISION_PUSH,
  167. CINEMATIC_COLLISION_KILL
  168. };
  169. int CinematicCollisionMode;
  170. friend class MoveablePhysClass;
  171. };
  172. #endif