Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
6.7 KiB

  1. //=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // $Header: $
  9. // $NoKeywords: $
  10. //
  11. // Interface used to construct morph buffers
  12. //=============================================================================
  13. #ifndef IMORPH_H
  14. #define IMORPH_H
  15. #ifdef _WIN32
  16. #pragma once
  17. #endif
  18. #include "mathlib/vector.h"
  19. #include <float.h>
  20. #include "tier0/dbg.h"
  21. #include "materialsystem/imaterial.h"
  22. //-----------------------------------------------------------------------------
  23. // Single morph data
  24. //-----------------------------------------------------------------------------
  25. struct MorphVertexInfo_t
  26. {
  27. int m_nVertexId; // What vertex is this going to affect?
  28. int m_nMorphTargetId; // What morph did it come from?
  29. Vector m_PositionDelta; // Positional morph delta
  30. Vector m_NormalDelta; // Normal morph delta
  31. float m_flWrinkleDelta; // Wrinkle morph delta
  32. float m_flSpeed;
  33. float m_flSide;
  34. };
  35. //-----------------------------------------------------------------------------
  36. // Morph weight data
  37. //-----------------------------------------------------------------------------
  38. enum MorphWeightType_t
  39. {
  40. MORPH_WEIGHT = 0,
  41. MORPH_WEIGHT_LAGGED,
  42. MORPH_WEIGHT_STEREO,
  43. MORPH_WEIGHT_STEREO_LAGGED,
  44. MORPH_WEIGHT_COUNT,
  45. };
  46. struct MorphWeight_t
  47. {
  48. float m_pWeight[MORPH_WEIGHT_COUNT];
  49. };
  50. //-----------------------------------------------------------------------------
  51. // Interface to the morph
  52. //-----------------------------------------------------------------------------
  53. abstract_class IMorph
  54. {
  55. public:
  56. // Locks the morph, destroys any existing contents
  57. virtual void Lock( float flFloatToFixedScale = 1.0f ) = 0;
  58. // Adds a morph
  59. virtual void AddMorph( const MorphVertexInfo_t &info ) = 0;
  60. // Unlocks the morph
  61. virtual void Unlock( ) = 0;
  62. };
  63. //-----------------------------------------------------------------------------
  64. // Morph builders
  65. //-----------------------------------------------------------------------------
  66. class CMorphBuilder
  67. {
  68. public:
  69. CMorphBuilder();
  70. ~CMorphBuilder();
  71. // Start building the morph
  72. void Begin( IMorph *pMorph, float flFloatToFixedScale = 1.0f );
  73. // End building the morph
  74. void End();
  75. void PositionDelta3fv( const float *pDelta );
  76. void PositionDelta3f( float dx, float dy, float dz );
  77. void PositionDelta3( const Vector &vec );
  78. void NormalDelta3fv( const float *pDelta );
  79. void NormalDelta3f( float dx, float dy, float dz );
  80. void NormalDelta3( const Vector &vec );
  81. void WrinkleDelta1f( float flWrinkle );
  82. // Both are 0-1 values indicating which morph target to use (for stereo morph targets)
  83. // and how much to blend between using lagged weights vs actual weights
  84. // Speed: 0 - use lagged, 1 - use actual
  85. void Speed1f( float flSpeed );
  86. void Side1f( float flSide );
  87. void AdvanceMorph( int nSourceVertex, int nMorphTargetId );
  88. private:
  89. MorphVertexInfo_t m_Info;
  90. IMorph *m_pMorph;
  91. };
  92. //-----------------------------------------------------------------------------
  93. // Constructor, destructor
  94. //-----------------------------------------------------------------------------
  95. inline CMorphBuilder::CMorphBuilder()
  96. {
  97. m_pMorph = NULL;
  98. }
  99. inline CMorphBuilder::~CMorphBuilder()
  100. {
  101. // You forgot to call End()!
  102. Assert( !m_pMorph );
  103. }
  104. //-----------------------------------------------------------------------------
  105. // Start building the morph
  106. //-----------------------------------------------------------------------------
  107. inline void CMorphBuilder::Begin( IMorph *pMorph, float flFloatToFixedScale )
  108. {
  109. Assert( pMorph && !m_pMorph );
  110. m_pMorph = pMorph;
  111. m_pMorph->Lock( flFloatToFixedScale );
  112. #ifdef _DEBUG
  113. m_Info.m_PositionDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
  114. m_Info.m_NormalDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
  115. m_Info.m_flWrinkleDelta = VEC_T_NAN;
  116. m_Info.m_flSpeed = VEC_T_NAN;
  117. m_Info.m_flSide = VEC_T_NAN;
  118. #endif
  119. }
  120. // End building the morph
  121. inline void CMorphBuilder::End()
  122. {
  123. Assert( m_pMorph );
  124. m_pMorph->Unlock();
  125. m_pMorph = NULL;
  126. }
  127. //-----------------------------------------------------------------------------
  128. // Set position delta
  129. //-----------------------------------------------------------------------------
  130. inline void CMorphBuilder::PositionDelta3fv( const float *pDelta )
  131. {
  132. Assert( m_pMorph );
  133. m_Info.m_PositionDelta.Init( pDelta[0], pDelta[1], pDelta[2] );
  134. }
  135. inline void CMorphBuilder::PositionDelta3f( float dx, float dy, float dz )
  136. {
  137. Assert( m_pMorph );
  138. m_Info.m_PositionDelta.Init( dx, dy, dz );
  139. }
  140. inline void CMorphBuilder::PositionDelta3( const Vector &vec )
  141. {
  142. Assert( m_pMorph );
  143. m_Info.m_PositionDelta = vec;
  144. }
  145. //-----------------------------------------------------------------------------
  146. // Set normal delta
  147. //-----------------------------------------------------------------------------
  148. inline void CMorphBuilder::NormalDelta3fv( const float *pDelta )
  149. {
  150. Assert( m_pMorph );
  151. m_Info.m_NormalDelta.Init( pDelta[0], pDelta[1], pDelta[2] );
  152. }
  153. inline void CMorphBuilder::NormalDelta3f( float dx, float dy, float dz )
  154. {
  155. Assert( m_pMorph );
  156. m_Info.m_NormalDelta.Init( dx, dy, dz );
  157. }
  158. inline void CMorphBuilder::NormalDelta3( const Vector &vec )
  159. {
  160. Assert( m_pMorph );
  161. m_Info.m_NormalDelta = vec;
  162. }
  163. //-----------------------------------------------------------------------------
  164. // Set wrinkle delta
  165. //-----------------------------------------------------------------------------
  166. inline void CMorphBuilder::WrinkleDelta1f( float flWrinkle )
  167. {
  168. Assert( m_pMorph );
  169. m_Info.m_flWrinkleDelta = flWrinkle;
  170. }
  171. //-----------------------------------------------------------------------------
  172. // Set speed,side data
  173. //-----------------------------------------------------------------------------
  174. inline void CMorphBuilder::Speed1f( float flSpeed )
  175. {
  176. Assert( m_pMorph );
  177. m_Info.m_flSpeed = flSpeed;
  178. }
  179. inline void CMorphBuilder::Side1f( float flSide )
  180. {
  181. Assert( m_pMorph );
  182. m_Info.m_flSide = flSide;
  183. }
  184. //-----------------------------------------------------------------------------
  185. // Advance morph
  186. //-----------------------------------------------------------------------------
  187. inline void CMorphBuilder::AdvanceMorph( int nSourceVertex, int nMorphTargetId )
  188. {
  189. Assert( m_pMorph );
  190. m_Info.m_nVertexId = nSourceVertex;
  191. m_Info.m_nMorphTargetId = nMorphTargetId;
  192. m_pMorph->AddMorph( m_Info );
  193. #ifdef _DEBUG
  194. m_Info.m_PositionDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
  195. m_Info.m_NormalDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
  196. m_Info.m_flWrinkleDelta = VEC_T_NAN;
  197. m_Info.m_flSpeed = VEC_T_NAN;
  198. m_Info.m_flSide = VEC_T_NAN;
  199. #endif
  200. }
  201. #endif // IMORPH_H