htree.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. /* $Header: /VSS_Sync/ww3d2/htree.h 4 8/29/01 9:49p Vss_sync $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando / G 3D Library *
  24. * *
  25. * $Archive:: /VSS_Sync/ww3d2/htree.h $*
  26. * *
  27. * Author:: Greg_h *
  28. * *
  29. * $Modtime:: 8/29/01 7:29p $*
  30. * *
  31. * $Revision:: 4 $*
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #if defined(_MSC_VER)
  37. #pragma once
  38. #endif
  39. #ifndef HTREE_H
  40. #define HTREE_H
  41. #include "always.h"
  42. #include "pivot.h"
  43. #include "quat.h"
  44. #include "matrix3d.h"
  45. #include "vector3.h"
  46. #include "w3d_file.h"
  47. #include "wwdebug.h"
  48. class HAnimClass;
  49. class HAnimComboClass;
  50. class MeshClass;
  51. class ChunkLoadClass;
  52. class ChunkSaveClass;
  53. class HRawAnimClass;
  54. /*
  55. HTreeClass
  56. A hierarchy of coordinate systems in an initial
  57. configuration. All motion data is applied to one
  58. of these objects. Motion is stored as deltas from
  59. the hierarchy tree's initial configuration.
  60. Normally, the user will probably not deal with
  61. HTreeClasses; they are used internally
  62. by the HierarchyModelClass.
  63. */
  64. class HTreeClass : public W3DMPO
  65. {
  66. W3DMPO_GLUE(HTreeClass)
  67. public:
  68. enum
  69. {
  70. OK,
  71. LOAD_ERROR
  72. };
  73. HTreeClass(void);
  74. HTreeClass(const HTreeClass & src);
  75. ~HTreeClass(void);
  76. int Load_W3D(ChunkLoadClass & cload);
  77. void Init_Default(void);
  78. WWINLINE const char * Get_Name(void) const { return Name; }
  79. WWINLINE int Num_Pivots(void) const { return NumPivots; }
  80. int Get_Bone_Index(const char * name) const;
  81. const char * Get_Bone_Name(int boneid) const;
  82. int Get_Parent_Index(int bone_indx) const;
  83. void Base_Update(const Matrix3D & root);
  84. void Anim_Update( const Matrix3D & root,
  85. HAnimClass * motion,
  86. float frame);
  87. void Anim_Update(const Matrix3D & root,HRawAnimClass * motion,float frame);
  88. void Blend_Update( const Matrix3D & root,
  89. HAnimClass * motion0,
  90. float frame0,
  91. HAnimClass * motion1,
  92. float frame1,
  93. float percentage);
  94. void Combo_Update( const Matrix3D & root,
  95. HAnimComboClass * anim);
  96. WWINLINE const Matrix3D & Get_Transform(int pivot) const;
  97. WWINLINE bool Get_Visibility(int pivot) const;
  98. WWINLINE const Matrix3D & Get_Root_Transform(void) const;
  99. // User control over a bone. While a bone is captured, you can over-ride the
  100. // animation transform used by the bone.
  101. void Capture_Bone(int boneindex);
  102. void Release_Bone(int boneindex);
  103. bool Is_Bone_Captured(int boneindex) const;
  104. void Control_Bone(int boneindex,const Matrix3D & relative_tm,bool world_space_translation = false);
  105. //
  106. // Simple pivot evaluation methods for when the caller doesn't want
  107. // to update the whole animation, but needs to know the transform of
  108. // a pivot at a given frame.
  109. //
  110. bool Simple_Evaluate_Pivot (HAnimClass *motion, int pivot_index, float frame, const Matrix3D &obj_tm, Matrix3D *end_tm) const;
  111. // Scale this HTree by a constant factor:
  112. void Scale(float factor);
  113. // Morph the bones on the HTree using weights from a number of other HTrees
  114. static HTreeClass * Create_Morphed( int num_morph_sources,
  115. const float morph_weights[],
  116. const HTreeClass *tree_array[] );
  117. // Create an HTree by Interpolating between others
  118. static HTreeClass * Create_Interpolated( const HTreeClass * tree_a0_b0,
  119. const HTreeClass * tree_a0_b1,
  120. const HTreeClass * tree_a1_b0,
  121. const HTreeClass * tree_a1_b1,
  122. float lerp_a, float lerp_b );
  123. // Create an HTree by Interpolating between others
  124. static HTreeClass * Create_Interpolated( const HTreeClass * tree_base,
  125. const HTreeClass * tree_a,
  126. const HTreeClass * tree_b,
  127. float a_scale, float b_scale );
  128. private:
  129. char Name[W3D_NAME_LEN];
  130. int NumPivots;
  131. PivotClass * Pivot;
  132. float ScaleFactor;
  133. void Free(void);
  134. bool read_pivots(ChunkLoadClass & cload,bool pre30);
  135. friend class MeshClass;
  136. };
  137. WWINLINE const Matrix3D & HTreeClass::Get_Root_Transform(void) const
  138. {
  139. return Pivot[0].Transform;
  140. }
  141. WWINLINE bool HTreeClass::Get_Visibility(int pivot) const
  142. {
  143. WWASSERT(pivot >= 0);
  144. WWASSERT(pivot < NumPivots);
  145. return Pivot[pivot].IsVisible;
  146. }
  147. /***********************************************************************************************
  148. * HTreeClass::Get_Transform -- returns the transformation for the desired pivot *
  149. * *
  150. * INPUT: *
  151. * *
  152. * OUTPUT: *
  153. * *
  154. * WARNINGS: *
  155. * *
  156. * HISTORY: *
  157. * 08/11/1997 GH : Created. *
  158. *=============================================================================================*/
  159. WWINLINE const Matrix3D & HTreeClass::Get_Transform(int pivot) const
  160. {
  161. assert(pivot >= 0);
  162. assert(pivot < NumPivots);
  163. return Pivot[pivot].Transform;
  164. }
  165. #endif