animobj.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. ** Command & Conquer Generals(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:: 6/26/01 7:01p $*
  29. * *
  30. * $Revision:: 3 $*
  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. int AnimMode;
  159. mutable int LastSyncTime;
  160. float animDirection;
  161. float frameRateMultiplier; // 020607 srj -- added
  162. } ModeAnim;
  163. // CurMotionMode == DOUBLE_ANIM
  164. struct {
  165. HAnimClass * Motion0;
  166. HAnimClass * Motion1;
  167. float Frame0;
  168. float Frame1;
  169. float Percentage;
  170. } ModeInterp;
  171. // CurMotionMode == MULTIPLE_ANIM
  172. struct {
  173. HAnimComboClass * AnimCombo;
  174. } ModeCombo;
  175. };
  176. friend class SkinClass;
  177. };
  178. /***********************************************************************************************
  179. * Animatable3DObjClass::Base_Update -- animation update function for the base pose *
  180. * *
  181. * INPUT: *
  182. * *
  183. * OUTPUT: *
  184. * *
  185. * WARNINGS: *
  186. * *
  187. * HISTORY: *
  188. * 3/2/99 GTH : Created. *
  189. *=============================================================================================*/
  190. inline void Animatable3DObjClass::Base_Update(const Matrix3D & root)
  191. {
  192. /*
  193. ** This method simply puts the meshes in the base pose's configuration
  194. */
  195. if (HTree) {
  196. HTree->Base_Update(root);
  197. }
  198. Set_Hierarchy_Valid(true);
  199. }
  200. /***********************************************************************************************
  201. * Animatable3DObjClass::Anim_Update -- Update function for a single animation *
  202. * *
  203. * INPUT: *
  204. * *
  205. * OUTPUT: *
  206. * *
  207. * WARNINGS: *
  208. * *
  209. * HISTORY: *
  210. * 3/2/99 GTH : Created. *
  211. *=============================================================================================*/
  212. inline void Animatable3DObjClass::Anim_Update(const Matrix3D & root,HAnimClass * motion,float frame)
  213. {
  214. /*
  215. ** Apply motion to the base pose
  216. */
  217. if ((motion) && (HTree)) {
  218. if (ModeAnim.Motion->Class_ID() == HAnimClass::CLASSID_HRAWANIM)
  219. HTree->Anim_Update(Transform,(HRawAnimClass*)ModeAnim.Motion,ModeAnim.Frame);
  220. else
  221. HTree->Anim_Update(root,motion,frame);
  222. }
  223. Set_Hierarchy_Valid(true);
  224. }
  225. /***********************************************************************************************
  226. * Animatable3DObjClass::Blend_Update -- update function for a blend of two animations *
  227. * *
  228. * INPUT: *
  229. * *
  230. * OUTPUT: *
  231. * *
  232. * WARNINGS: *
  233. * *
  234. * HISTORY: *
  235. * 3/2/99 GTH : Created. *
  236. *=============================================================================================*/
  237. inline void Animatable3DObjClass::Blend_Update
  238. (
  239. const Matrix3D & root,
  240. HAnimClass * motion0,
  241. float frame0,
  242. HAnimClass * motion1,
  243. float frame1,
  244. float percentage
  245. )
  246. {
  247. /*
  248. ** Apply motion to the base pose
  249. */
  250. if (HTree) {
  251. HTree->Blend_Update(root,motion0,frame0,motion1,frame1,percentage);
  252. }
  253. Set_Hierarchy_Valid(true);
  254. }
  255. /***********************************************************************************************
  256. * Animatable3DObjClass::Combo_Update -- Animation update for a combination of anims *
  257. * *
  258. * INPUT: *
  259. * *
  260. * OUTPUT: *
  261. * *
  262. * WARNINGS: *
  263. * *
  264. * HISTORY: *
  265. * 3/2/99 GTH : Created. *
  266. *=============================================================================================*/
  267. inline void Animatable3DObjClass::Combo_Update( const Matrix3D & root, HAnimComboClass *anim )
  268. {
  269. if (HTree) {
  270. HTree->Combo_Update(root, anim);
  271. }
  272. Set_Hierarchy_Valid(true);
  273. }
  274. #endif //ANIMOBJ_H