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.

199 lines
6.3 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ============
  2. //
  3. // Generic constraint functions to compute bone constraints
  4. // Used by studio/engine, SFM & Maya
  5. //
  6. // Studio interface functions to the generic constraint functions
  7. //
  8. //===============================================================================
  9. #ifndef BONE_CONSTRAINTS_H
  10. #define BONE_CONSTRAINTS_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. //-----------------------------------------------------------------------------
  15. // Forward declarations
  16. //-----------------------------------------------------------------------------
  17. struct mstudiobone_t;
  18. class CBoneAccessor;
  19. class CStudioHdr;
  20. struct mstudioconstrainttarget_t;
  21. struct mstudioconstraintslave_t;
  22. //-----------------------------------------------------------------------------
  23. //
  24. //-----------------------------------------------------------------------------
  25. class CConstraintBones
  26. {
  27. public:
  28. enum AimConstraintUpType_t
  29. {
  30. AC_UP_TYPE_OBJECT_ROTATION, // Use supplied vector rotated by the specified object as up vector (Maya: Object Rotation Up), if no dag is supplied, reverts to Vector
  31. AC_UP_TYPE_VECTOR, // Use supplied vector as up vector (Maya: Vector)
  32. AC_UP_TYPE_OBJECT, // Use vector from slave to specified object in world space as up vector( Maya: Object Up), if no dag is supplied, reverts to Vector
  33. AC_UP_TYPE_PARENT_ROTATION, // Use supplied vector rotated by the parent object as up vector (Maya: None)
  34. AC_UP_TYPE_FIRST = AC_UP_TYPE_OBJECT_ROTATION, // The smallest possible value
  35. AC_UP_TYPE_LAST = AC_UP_TYPE_PARENT_ROTATION, // The largest possible value
  36. };
  37. // Compute the aggregate target position and orientation from the weighted target list and return
  38. // the resulting position and orientation in addition to updating the target dag.
  39. // All passed arrays must be nTargetCount in length
  40. static float ComputeTargetPosition(
  41. Vector &vTargetPosition,
  42. int nTargetCount,
  43. float *flTargetWeights,
  44. Vector *vTargetPositions,
  45. Vector *vTargetOffsets );
  46. // Compute the aggregate target orientation from the weighted target list and
  47. // return the total weight
  48. // All passed arrays must be nTargetCount in length
  49. static float ComputeTargetOrientation(
  50. Quaternion &qTargetOrientation,
  51. int nTargetCount,
  52. float *pflTargetWeights,
  53. Quaternion *pqTargetOrientations,
  54. Quaternion *pqTargetOffsets );
  55. // Compute the aggregate target position and orientation from the weighted
  56. // target list and return the total weight
  57. // All passed arrays must be nTargetCount in length
  58. static float ComputeTargetPositionOrientation(
  59. Vector &vTargetPosition,
  60. Quaternion &qTargetOrientation,
  61. int nTargetCount,
  62. float *pflTargetWeights,
  63. Vector *vTargetPositions,
  64. Vector *vTargetOffsets,
  65. Quaternion *pqTargetOrientations,
  66. Quaternion *pqTargetOffsets );
  67. // Compute the aggregate target position and orientation from the weighted
  68. // target list and return the total weight
  69. // All passed arrays must be nTargetCount in length
  70. static float ComputeTargetPositionOrientation(
  71. Vector &vTargetPosition,
  72. Quaternion &qTargetOrientation,
  73. int nTargetCount,
  74. float *pflTargetWeights,
  75. matrix3x4a_t *pmTargets,
  76. matrix3x4a_t *pmOffsets );
  77. static void ComputeAimConstraintOffset(
  78. Quaternion &qAimOffset,
  79. bool bPreserveOffset,
  80. const Vector &vTargetWorldPos,
  81. const matrix3x4_t &mSlaveParentToWorld,
  82. const Vector &vUp,
  83. const Vector &vSlaveLocalPos,
  84. const Quaternion &qSlaveLocal,
  85. matrix3x4_t *pmUpToWorld,
  86. AimConstraintUpType_t eUpType );
  87. // Calculate the orientation needed to make a transform where the y
  88. // vector of the transform matches the forward vector and the z vector matches
  89. // the up reference vector as closely as possible. The x vector will be in the
  90. // plane defined by using the forward vector as the normal.
  91. static void ComputeAimConstraintAimAt(
  92. Quaternion &qAim,
  93. const Vector &vForward,
  94. const Vector &vReferenceUp );
  95. // Given the various parameters, computes the local vForward & vReferenceUp
  96. // and calls ComputeAimConstraintAimAt
  97. static void ComputeAimConstraint(
  98. Quaternion &qAim,
  99. const Vector &vTargetWorldPos,
  100. const matrix3x4_t &mParentToWorld,
  101. const Vector &vUp,
  102. const Vector &vSlaveLocalPos,
  103. const matrix3x4_t *pmUpToWorld,
  104. AimConstraintUpType_t eUpType );
  105. //-----------------------------------------------------------------------------
  106. //
  107. //-----------------------------------------------------------------------------
  108. static void ComputeWorldUpVector(
  109. Vector *pvWorldUp,
  110. const matrix3x4_t & mParentToWorld,
  111. const Vector &vUp,
  112. const Vector &vSlaveLocalPos,
  113. const matrix3x4_t *pmUpToWorld,
  114. AimConstraintUpType_t eUpType );
  115. };
  116. //-----------------------------------------------------------------------------
  117. //
  118. //-----------------------------------------------------------------------------
  119. class CStudioConstraintBones : public CConstraintBones
  120. {
  121. public:
  122. // Utilities
  123. static float ComputeTargetPosition(
  124. Vector &vTargetPosition,
  125. mstudioconstrainttarget_t *pTargets,
  126. int nTargetCount,
  127. CBoneAccessor &boneToWorld );
  128. static float ComputeTargetOrientation(
  129. Quaternion &qTargetOrientation,
  130. mstudioconstrainttarget_t *pTargets,
  131. int nTargetCount,
  132. CBoneAccessor &boneToWorld );
  133. static float ComputeTargetPositionOrientation(
  134. Vector &vTargetPosition,
  135. Quaternion &qTargetOrientation,
  136. mstudioconstrainttarget_t *pTargets,
  137. int nTargetCount,
  138. CBoneAccessor &boneToWorld );
  139. static void ComputeBaseWorldMatrix(
  140. matrix3x4a_t &mBaseWorldMatrix,
  141. mstudioconstraintslave_t *pSlave,
  142. CBoneAccessor &boneToWorld,
  143. const CStudioHdr *pStudioHdr,
  144. const matrix3x4_t *pmViewTransform = NULL );
  145. // constraints
  146. static void ComputePointConstraint(
  147. const mstudiobone_t *pBones,
  148. int nBone,
  149. CBoneAccessor &boneToWorld,
  150. const CStudioHdr *pStudioHdr );
  151. static void ComputeOrientConstraint(
  152. const mstudiobone_t *pBones,
  153. int nBone,
  154. CBoneAccessor &boneToWorld,
  155. const CStudioHdr *pStudioHdr,
  156. const matrix3x4_t *pmViewTransform );
  157. static void ComputeAimConstraint(
  158. const mstudiobone_t *pBones,
  159. int nBone,
  160. CBoneAccessor &boneToWorld,
  161. const CStudioHdr *pStudioHdr,
  162. const matrix3x4_t *pmViewTransform,
  163. AimConstraintUpType_t eType );
  164. static void ComputeParentConstraint(
  165. const mstudiobone_t *pBones,
  166. int nBone,
  167. CBoneAccessor &boneToWorld,
  168. const CStudioHdr *pStudioHdr );
  169. };
  170. #endif // BONE_CONSTRAINTS_H