htree.h 7.6 KB

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