animobj.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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 : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/animobj.h $*
  25. * *
  26. * Author:: Greg_h *
  27. * *
  28. * $Modtime:: 12/10/01 11:18a $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * Animatable3DObjClass::Base_Update -- animation update function for the base pose *
  35. * Animatable3DObjClass::Anim_Update -- Update function for a single animation *
  36. * Animatable3DObjClass::Blend_Update -- update function for a blend of two animations *
  37. * Animatable3DObjClass::Combo_Update -- Animation update for a combination of anims *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #if defined(_MSC_VER)
  40. #pragma once
  41. #endif
  42. #ifndef ANIMOBJ_H
  43. #define ANIMOBJ_H
  44. #include "always.h"
  45. #include "composite.h"
  46. #include "htree.h"
  47. #include "hanim.h"
  48. class SkinClass;
  49. class RenderInfoClass;
  50. /**
  51. ** Animatable3DObjClass
  52. ** This class performs some of the work necessary to implement hierarchical animation.
  53. ** It implements much of the bone and animation interface of RenderObjClass.
  54. */
  55. class Animatable3DObjClass : public CompositeRenderObjClass
  56. {
  57. public:
  58. Animatable3DObjClass(const char * htree_name);
  59. Animatable3DObjClass(const Animatable3DObjClass & src);
  60. Animatable3DObjClass & operator = (const Animatable3DObjClass &);
  61. virtual ~Animatable3DObjClass(void);
  62. /////////////////////////////////////////////////////////////////////////////
  63. // Render Object Interface - Rendering
  64. /////////////////////////////////////////////////////////////////////////////
  65. virtual void Render(RenderInfoClass & rinfo);
  66. virtual void Special_Render(SpecialRenderInfoClass & rinfo);
  67. /////////////////////////////////////////////////////////////////////////////
  68. // Render Object Interface - "Scene Graph"
  69. /////////////////////////////////////////////////////////////////////////////
  70. virtual void Set_Transform(const Matrix3D &m);
  71. virtual void Set_Position(const Vector3 &v);
  72. /////////////////////////////////////////////////////////////////////////////
  73. // Render Object Interface - Hierarchical Animation
  74. /////////////////////////////////////////////////////////////////////////////
  75. virtual void Set_Animation(void);
  76. virtual void Set_Animation( HAnimClass * motion,
  77. float frame, int anim_mode = ANIM_MODE_MANUAL);
  78. virtual void Set_Animation( HAnimClass * motion0,
  79. float frame0,
  80. HAnimClass * motion1,
  81. float frame1,
  82. float percentage);
  83. virtual void Set_Animation( HAnimComboClass * anim_combo);
  84. virtual void Set_Animation_Frame_Rate_Multiplier(float multiplier); // 020607 srj -- added
  85. virtual HAnimClass * Peek_Animation_And_Info(float& frame, int& numFrames, int& mode, float& mult); // 020710 srj -- added
  86. virtual HAnimClass * Peek_Animation( void );
  87. virtual bool Is_Animation_Complete( void ) const;
  88. virtual int Get_Num_Bones(void);
  89. virtual const char * Get_Bone_Name(int bone_index);
  90. virtual int Get_Bone_Index(const char * bonename);
  91. virtual const Matrix3D & Get_Bone_Transform(const char * bonename);
  92. virtual const Matrix3D & Get_Bone_Transform(int boneindex);
  93. virtual void Capture_Bone(int boneindex);
  94. virtual void Release_Bone(int boneindex);
  95. virtual bool Is_Bone_Captured(int boneindex) const;
  96. virtual void Control_Bone(int bindex,const Matrix3D & objtm,bool world_space_translation = false);
  97. virtual const HTreeClass * Get_HTree(void) const { return HTree; }
  98. //
  99. // Simple bone evaluation methods for when the caller doesn't want
  100. // to update the heirarchy, but needs to know the transform of
  101. // a bone at a given frame.
  102. //
  103. virtual bool Simple_Evaluate_Bone(int boneindex, Matrix3D *tm) const;
  104. virtual bool Simple_Evaluate_Bone(int boneindex, float frame, Matrix3D *tm) const;
  105. // (gth) TESTING DYNAMICALLY SWAPPING SKELETONS!
  106. virtual void Set_HTree(HTreeClass * htree);
  107. ///Generals change so we can set sub-object transforms directly without having them revert to base pose
  108. ///when marked dirty. DON'T USE THIS UNLESS YOU HAVE A GOOD REASON! -MW
  109. void Friend_Set_Hierarchy_Valid(bool onoff) const { IsTreeValid = onoff; }
  110. protected:
  111. // internally used to compute the current frame if the object is in ANIM_MODE_MANUAL
  112. float Compute_Current_Frame(float *newDirection=NULL) const;
  113. // Update the sub-object transforms according to the current anim state and root transform.
  114. virtual void Update_Sub_Object_Transforms(void);
  115. // Update the transforms using the base pose only
  116. void Base_Update(const Matrix3D & root);
  117. // Update the transforms using a single frame of motion data
  118. void Anim_Update( const Matrix3D & root,
  119. HAnimClass * motion,
  120. float frame);
  121. // Update the transforms blending two frames of motion data
  122. void Blend_Update( const Matrix3D & root,
  123. HAnimClass * motion0,
  124. float frame0,
  125. HAnimClass * motion1,
  126. float frame1,
  127. float percentage);
  128. // Update the transforms with an AnimationCombination
  129. void Combo_Update( const Matrix3D & root,
  130. HAnimComboClass *anim);
  131. // flag to kep track of whether the hierarchy tree transforms are currently valid
  132. bool Is_Hierarchy_Valid(void) const { return IsTreeValid; }
  133. void Set_Hierarchy_Valid(bool onoff) const { IsTreeValid = onoff; }
  134. // Progress anims for single anim (loop and once)
  135. void Single_Anim_Progress( void );
  136. // Release any anims
  137. void Release( void );
  138. protected:
  139. // Is the hierarchy tree currently valid
  140. mutable bool IsTreeValid;
  141. // Hierarchy Tree
  142. HTreeClass * HTree;
  143. // Animation state for the next frame. When we add more flexible motion
  144. // compositing, add a new state and its associated data to the union below
  145. enum {
  146. NONE = 0,
  147. BASE_POSE,
  148. SINGLE_ANIM,
  149. DOUBLE_ANIM,
  150. MULTIPLE_ANIM,
  151. };
  152. int CurMotionMode;
  153. union {
  154. // CurMotionMode == SINGLE_ANIM
  155. struct {
  156. HAnimClass * Motion;
  157. float Frame;
  158. float PrevFrame;
  159. int AnimMode;
  160. mutable int LastSyncTime;
  161. float animDirection;
  162. float frameRateMultiplier; // 020607 srj -- added
  163. } ModeAnim;
  164. // CurMotionMode == DOUBLE_ANIM
  165. struct {
  166. HAnimClass * Motion0;
  167. HAnimClass * Motion1;
  168. float Frame0;
  169. float Frame1;
  170. float PrevFrame0;
  171. float PrevFrame1;
  172. float Percentage;
  173. } ModeInterp;
  174. // CurMotionMode == MULTIPLE_ANIM
  175. struct {
  176. HAnimComboClass * AnimCombo;
  177. } ModeCombo;
  178. };
  179. friend class SkinClass;
  180. };
  181. /***********************************************************************************************
  182. * Animatable3DObjClass::Base_Update -- animation update function for the base pose *
  183. * *
  184. * INPUT: *
  185. * *
  186. * OUTPUT: *
  187. * *
  188. * WARNINGS: *
  189. * *
  190. * HISTORY: *
  191. * 3/2/99 GTH : Created. *
  192. *=============================================================================================*/
  193. inline void Animatable3DObjClass::Base_Update(const Matrix3D & root)
  194. {
  195. /*
  196. ** This method simply puts the meshes in the base pose's configuration
  197. */
  198. if (HTree) {
  199. HTree->Base_Update(root);
  200. }
  201. Set_Hierarchy_Valid(true);
  202. }
  203. /***********************************************************************************************
  204. * Animatable3DObjClass::Anim_Update -- Update function for a single animation *
  205. * *
  206. * INPUT: *
  207. * *
  208. * OUTPUT: *
  209. * *
  210. * WARNINGS: *
  211. * *
  212. * HISTORY: *
  213. * 3/2/99 GTH : Created. *
  214. *=============================================================================================*/
  215. inline void Animatable3DObjClass::Anim_Update(const Matrix3D & root,HAnimClass * motion,float frame)
  216. {
  217. /*
  218. ** Apply motion to the base pose
  219. */
  220. if ((motion) && (HTree)) {
  221. if (ModeAnim.Motion->Class_ID() == HAnimClass::CLASSID_HRAWANIM)
  222. HTree->Anim_Update(Transform,(HRawAnimClass*)ModeAnim.Motion,ModeAnim.Frame);
  223. else
  224. HTree->Anim_Update(root,motion,frame);
  225. }
  226. Set_Hierarchy_Valid(true);
  227. }
  228. /***********************************************************************************************
  229. * Animatable3DObjClass::Blend_Update -- update function for a blend of two animations *
  230. * *
  231. * INPUT: *
  232. * *
  233. * OUTPUT: *
  234. * *
  235. * WARNINGS: *
  236. * *
  237. * HISTORY: *
  238. * 3/2/99 GTH : Created. *
  239. *=============================================================================================*/
  240. inline void Animatable3DObjClass::Blend_Update
  241. (
  242. const Matrix3D & root,
  243. HAnimClass * motion0,
  244. float frame0,
  245. HAnimClass * motion1,
  246. float frame1,
  247. float percentage
  248. )
  249. {
  250. /*
  251. ** Apply motion to the base pose
  252. */
  253. if (HTree) {
  254. HTree->Blend_Update(root,motion0,frame0,motion1,frame1,percentage);
  255. }
  256. Set_Hierarchy_Valid(true);
  257. }
  258. /***********************************************************************************************
  259. * Animatable3DObjClass::Combo_Update -- Animation update for a combination of anims *
  260. * *
  261. * INPUT: *
  262. * *
  263. * OUTPUT: *
  264. * *
  265. * WARNINGS: *
  266. * *
  267. * HISTORY: *
  268. * 3/2/99 GTH : Created. *
  269. *=============================================================================================*/
  270. inline void Animatable3DObjClass::Combo_Update( const Matrix3D & root, HAnimComboClass *anim )
  271. {
  272. if (HTree) {
  273. HTree->Combo_Update(root, anim);
  274. }
  275. Set_Hierarchy_Valid(true);
  276. }
  277. #endif //ANIMOBJ_H