2
0

animcollisionmanager.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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/animcollisionmanager.h $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 9/09/01 2:44p $*
  31. * *
  32. * $Revision:: 13 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #ifndef ANIMCOLLISIONMANAGER_H
  38. #define ANIMCOLLISIONMANAGER_H
  39. #include "always.h"
  40. #include "ridermanager.h"
  41. #include "matrix3d.h"
  42. #include "vector.h"
  43. #include "rendobj.h"
  44. #include "wwstring.h"
  45. class AnimCollisionManagerDefClass;
  46. class HAnimClass;
  47. class ChunkSaveClass;
  48. class ChunkLoadClass;
  49. class BitStreamClass;
  50. class PushRecordClass;
  51. /**
  52. ** AnimCollisionManagerClass
  53. ** The job of this class is to handle collisions which are caused by animations. Some examples
  54. ** of this are: elevators, doors, and "cinematic events". StaticAnimPhysClass and DynamicAnimPhysClass
  55. ** both use this code to handle collisions with the dynamic objects in the scene.
  56. */
  57. class AnimCollisionManagerClass
  58. {
  59. public:
  60. AnimCollisionManagerClass(PhysClass & parent);
  61. ~AnimCollisionManagerClass(void);
  62. /*
  63. ** Initialization
  64. */
  65. void Init(const AnimCollisionManagerDefClass & def);
  66. void Update_Cached_Model_Parameters(void);
  67. /*
  68. ** Simulation, moves the animation forward, checks for animated collisions, updates riders
  69. ** Returns true if the object's animation pose changed.
  70. */
  71. bool Timestep(float dt);
  72. /*
  73. ** Animation Controls
  74. */
  75. enum AnimModeType
  76. {
  77. ANIMATE_LOOP = 0,
  78. ANIMATE_TARGET,
  79. ANIMATE_MANUAL,
  80. };
  81. void Set_Animation_Mode(AnimModeType mode);
  82. AnimModeType Get_Animation_Mode(void);
  83. void Set_Animation(const char * anim_name);
  84. HAnimClass * Peek_Animation(void);
  85. void Set_Target_Frame(float frame);
  86. void Set_Target_Frame_End(void);
  87. float Get_Target_Frame(void);
  88. bool Is_At_Target(void);
  89. void Set_Current_Frame(float frame);
  90. float Get_Current_Frame(void);
  91. void Set_Loop_Start(float frame0);
  92. void Set_Loop_End(float frame1);
  93. float Get_Loop_Start(void);
  94. float Get_Loop_End(void);
  95. /*
  96. ** Collision Control
  97. */
  98. enum CollisionModeType
  99. {
  100. COLLIDE_NONE = 0,
  101. COLLIDE_STOP,
  102. COLLIDE_PUSH,
  103. COLLIDE_KILL,
  104. };
  105. void Set_Collision_Mode(CollisionModeType mode);
  106. CollisionModeType Get_Collision_Mode(void);
  107. /*
  108. ** Rider Support
  109. */
  110. bool Link_Rider(PhysClass * rider) { RiderManager.Link_Rider(rider); return true; }
  111. bool Unlink_Rider(PhysClass * rider) { RiderManager.Unlink_Rider(rider); return true; }
  112. /*
  113. ** Save/Load Support
  114. */
  115. bool Save(ChunkSaveClass &csave);
  116. bool Load(ChunkLoadClass &cload);
  117. protected:
  118. /*
  119. ** Multi-mesh collision detection support
  120. */
  121. class CollideableObjClass
  122. {
  123. public:
  124. CollideableObjClass(void);
  125. CollideableObjClass(RenderObjClass * collisionmesh);
  126. CollideableObjClass(const CollideableObjClass & that);
  127. ~CollideableObjClass(void);
  128. CollideableObjClass & operator = (const CollideableObjClass & that);
  129. bool operator == (const CollideableObjClass & that) const { return false; }
  130. bool operator != (const CollideableObjClass & that) const { return true; }
  131. void Set_Collision_Object(RenderObjClass * mesh);
  132. RenderObjClass * Peek_Collision_Object(void) { return CollisionMesh; }
  133. void Cache_Start_Transform(void) { StartTransform = CollisionMesh->Get_Transform(); }
  134. void Cache_End_Transform(void) { EndTransform = CollisionMesh->Get_Transform(); }
  135. Matrix3D & Get_Start_Transform(void) { return StartTransform; }
  136. Matrix3D & Get_End_Transform(void) { return EndTransform; }
  137. void Install_Start_Transform(void) { CollisionMesh->Set_Transform(StartTransform); }
  138. void Install_End_Transform(void) { CollisionMesh->Set_Transform(EndTransform); }
  139. void Intersect_Scene(int colgroup,NonRefPhysListClass * list);
  140. int Clear_Collision_Bits(void);
  141. void Restore_Collision_Bits(int oldbits);
  142. protected:
  143. RenderObjClass * CollisionMesh;
  144. Matrix3D StartTransform;
  145. Matrix3D EndTransform;
  146. };
  147. /*
  148. ** Internal functions
  149. */
  150. bool Is_Collision_Model(RenderObjClass * model);
  151. int Recursive_Count_Collision_Models(RenderObjClass * model);
  152. void Recursive_Collect_Collision_Models(RenderObjClass * model);
  153. void Revert_Animation_State(void);
  154. bool Check_Collision(CollideableObjClass & collisionobj);
  155. bool Is_Intersecting(void);
  156. bool Push_Collided_Object(PhysClass * obj,const Matrix3D & delta_transform);
  157. void Internal_Set_Animation(const char * anim_name);
  158. /*
  159. ** Parent reference
  160. */
  161. PhysClass & Parent;
  162. /*
  163. ** Animation support
  164. */
  165. AnimModeType AnimationMode; // current animation mode and parameters.
  166. float TargetFrame;
  167. float LoopStart;
  168. float LoopEnd;
  169. HAnimClass * CurAnimation; // current animation state.
  170. float CurFrame;
  171. HAnimClass * PrevAnimation; // temporary variable used in timestep
  172. float PrevFrame; // temporary variable used in timestep
  173. /*
  174. ** Attached riders support
  175. */
  176. RiderManagerClass RiderManager;
  177. /*
  178. ** Animated collision support
  179. */
  180. CollisionModeType CollisionMode;
  181. DynamicVectorClass<CollideableObjClass> CollisionMeshes;
  182. /*
  183. ** Revert list, In the case that we have to revert our animation state,
  184. ** we have to undo all changes to external objects.
  185. */
  186. PushRecordClass * PushList;
  187. };
  188. /**
  189. ** AnimCollisionManagerDefClass
  190. ** This class is meant to be a component of a definition class for a physics object
  191. ** which has an AnimCollisionManager. The member variables of this class are public since
  192. ** various physics def classes make them directly editable.
  193. */
  194. class AnimCollisionManagerDefClass
  195. {
  196. public:
  197. AnimCollisionManagerDefClass(void);
  198. ~AnimCollisionManagerDefClass(void);
  199. void Validate_Parameters(void);
  200. bool Save(ChunkSaveClass &csave);
  201. bool Load(ChunkLoadClass &cload);
  202. public:
  203. int CollisionMode;
  204. int AnimationMode;
  205. StringClass AnimationName;
  206. };
  207. /*
  208. ** Use this macro to make all of the member variables in an AnimCollisionManagerDefClass editable.
  209. ** The first parameter to the macro is the type-name of your class (e.g. StaticAnimPhysDefClass) and
  210. ** the second parameter is the name of the member variable which is the animation manager (e.g. AnimManager).
  211. */
  212. #ifdef PARAM_EDITING_ON
  213. #define ANIMCOLLISIONMANAGERDEF_EDITABLE_PARAMS( class_name, member_name ) \
  214. PARAM_SEPARATOR( class_name, "Animation Settings"); \
  215. EnumParameterClass *collision_param = new EnumParameterClass(& member_name ## .CollisionMode); \
  216. collision_param->Set_Name ("CollisionMode"); \
  217. collision_param->Add_Value("NONE",AnimCollisionManagerClass::COLLIDE_NONE); \
  218. collision_param->Add_Value("STOP",AnimCollisionManagerClass::COLLIDE_STOP); \
  219. collision_param->Add_Value("PUSH",AnimCollisionManagerClass::COLLIDE_PUSH); \
  220. collision_param->Add_Value("KILL",AnimCollisionManagerClass::COLLIDE_KILL); \
  221. GENERIC_EDITABLE_PARAM( class_name , collision_param); \
  222. \
  223. EnumParameterClass *anim_param = new EnumParameterClass(& member_name ## .AnimationMode); \
  224. anim_param->Set_Name ("AnimationMode"); \
  225. anim_param->Add_Value("LOOP",AnimCollisionManagerClass::ANIMATE_LOOP); \
  226. anim_param->Add_Value("TARGET",AnimCollisionManagerClass::ANIMATE_TARGET); \
  227. anim_param->Add_Value("MANUAL",AnimCollisionManagerClass::ANIMATE_MANUAL); \
  228. GENERIC_EDITABLE_PARAM( class_name , anim_param); \
  229. \
  230. NAMED_EDITABLE_PARAM( class_name, ParameterClass::TYPE_STRING, member_name ## .AnimationName,"AnimationName"); \
  231. #else
  232. #define ANIMCOLLISIONMANAGERDEF_EDITABLE_PARAMS( class_name, member_name )
  233. #endif
  234. #endif //ANIMCOLLISIONMANAGER_H