Team Fortress 2 Source Code as on 22/4/2020
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.

133 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #ifndef RAGDOLL_H
  10. #define RAGDOLL_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "ragdoll_shared.h"
  15. #define RAGDOLL_VISUALIZE 0
  16. class C_BaseEntity;
  17. class CStudioHdr;
  18. struct mstudiobone_t;
  19. class Vector;
  20. class IPhysicsObject;
  21. class CBoneAccessor;
  22. abstract_class IRagdoll
  23. {
  24. public:
  25. virtual ~IRagdoll() {}
  26. virtual void RagdollBone( C_BaseEntity *ent, mstudiobone_t *pbones, int boneCount, bool *boneSimulated, CBoneAccessor &pBoneToWorld ) = 0;
  27. virtual const Vector& GetRagdollOrigin( ) = 0;
  28. virtual void GetRagdollBounds( Vector &mins, Vector &maxs ) = 0;
  29. virtual int RagdollBoneCount() const = 0;
  30. virtual IPhysicsObject *GetElement( int elementNum ) = 0;
  31. virtual void DrawWireframe( void ) = 0;
  32. virtual void VPhysicsUpdate( IPhysicsObject *pObject ) = 0;
  33. virtual bool TransformVectorToWorld(int boneIndex, const Vector *vTemp, Vector *vOut) = 0;
  34. };
  35. class CRagdoll : public IRagdoll
  36. {
  37. public:
  38. CRagdoll();
  39. ~CRagdoll( void );
  40. DECLARE_SIMPLE_DATADESC();
  41. void Init(
  42. C_BaseEntity *ent,
  43. CStudioHdr *pstudiohdr,
  44. const Vector &forceVector,
  45. int forceBone,
  46. const matrix3x4_t *pDeltaBones0,
  47. const matrix3x4_t *pDeltaBones1,
  48. const matrix3x4_t *pCurrentBonePosition,
  49. float boneDt,
  50. bool bFixedConstraints=false );
  51. virtual void RagdollBone( C_BaseEntity *ent, mstudiobone_t *pbones, int boneCount, bool *boneSimulated, CBoneAccessor &pBoneToWorld );
  52. virtual const Vector& GetRagdollOrigin( );
  53. virtual void GetRagdollBounds( Vector &theMins, Vector &theMaxs );
  54. void BuildRagdollBounds( C_BaseEntity *ent );
  55. virtual IPhysicsObject *GetElement( int elementNum );
  56. virtual IPhysicsConstraintGroup *GetConstraintGroup() { return m_ragdoll.pGroup; }
  57. virtual void DrawWireframe();
  58. virtual void VPhysicsUpdate( IPhysicsObject *pPhysics );
  59. virtual int RagdollBoneCount() const { return m_ragdoll.listCount; }
  60. //=============================================================================
  61. // HPE_BEGIN:
  62. // [menglish] Transforms a vector from the given bone's space to world space
  63. //=============================================================================
  64. virtual bool TransformVectorToWorld(int iBoneIndex, const Vector *vTemp, Vector *vOut);
  65. //=============================================================================
  66. // HPE_END
  67. //=============================================================================
  68. void SetInitialBonePosition( CStudioHdr *pstudiohdr, const CBoneAccessor &pDesiredBonePosition );
  69. bool IsValid() { return m_ragdoll.listCount > 0; }
  70. void ResetRagdollSleepAfterTime( void );
  71. float GetLastVPhysicsUpdateTime() const { return m_lastUpdate; }
  72. private:
  73. void CheckSettleStationaryRagdoll();
  74. void PhysForceRagdollToSleep();
  75. ragdoll_t m_ragdoll;
  76. Vector m_mins, m_maxs;
  77. Vector m_origin;
  78. float m_radius;
  79. float m_lastUpdate;
  80. bool m_allAsleep;
  81. Vector m_vecLastOrigin;
  82. float m_flLastOriginChangeTime;
  83. #if RAGDOLL_VISUALIZE
  84. matrix3x4_t m_savedBone1[MAXSTUDIOBONES];
  85. matrix3x4_t m_savedBone2[MAXSTUDIOBONES];
  86. matrix3x4_t m_savedBone3[MAXSTUDIOBONES];
  87. #endif
  88. public:
  89. ragdoll_t *GetRagdoll( void ){ return &m_ragdoll; }
  90. };
  91. CRagdoll *CreateRagdoll(
  92. C_BaseEntity *ent,
  93. CStudioHdr *pstudiohdr,
  94. const Vector &forceVector,
  95. int forceBone,
  96. const matrix3x4_t *pDeltaBones0,
  97. const matrix3x4_t *pDeltaBones1,
  98. const matrix3x4_t *pCurrentBonePosition,
  99. float boneDt,
  100. bool bFixedConstraints=false );
  101. // save this ragdoll's creation as the current tick
  102. void NoteRagdollCreationTick( C_BaseEntity *pRagdoll );
  103. // returns true if the ragdoll was created on this tick
  104. bool WasRagdollCreatedOnCurrentTick( C_BaseEntity *pRagdoll );
  105. #endif // RAGDOLL_H