animobj.h 14 KB

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