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.

132 lines
3.7 KiB

  1. //========= Copyright � 1996-2005, 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, const 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. bool bBleedOutOnSleep=true);
  52. virtual void RagdollBone( C_BaseEntity *ent, const mstudiobone_t *pbones, int boneCount, bool *boneSimulated, CBoneAccessor &pBoneToWorld );
  53. virtual const Vector& GetRagdollOrigin( );
  54. virtual void GetRagdollBounds( Vector &theMins, Vector &theMaxs );
  55. void BuildRagdollBounds( C_BaseEntity *ent );
  56. virtual IPhysicsObject *GetElement( int elementNum );
  57. virtual IPhysicsConstraintGroup *GetConstraintGroup() { return m_ragdoll.pGroup; }
  58. virtual void DrawWireframe();
  59. virtual void VPhysicsUpdate( IPhysicsObject *pPhysics );
  60. virtual int RagdollBoneCount() const { return m_ragdoll.listCount; }
  61. virtual bool TransformVectorToWorld( int iBoneIndex, const Vector *vTemp, Vector *vOut );
  62. void SetInitialBonePosition( CStudioHdr *pstudiohdr, const CBoneAccessor &pDesiredBonePosition );
  63. bool IsValid() { return m_ragdoll.listCount > 0; }
  64. bool IsAsleep( void ) const { return m_allAsleep; }
  65. void ResetRagdollSleepAfterTime( void );
  66. float GetLastVPhysicsUpdateTime() const { return m_lastUpdate; }
  67. IPhysicsObject *RagdollPhysicsObject( int i ) { return m_ragdoll.list[ i ].pObject; }
  68. public:
  69. void CheckSettleStationaryRagdoll();
  70. void PhysForceRagdollToSleep();
  71. void CreateBloodPool();
  72. private:
  73. ragdoll_t m_ragdoll;
  74. Vector m_mins, m_maxs;
  75. Vector m_origin;
  76. float m_lastUpdate;
  77. bool m_allAsleep;
  78. Vector m_vecLastOrigin;
  79. float m_flLastOriginChangeTime;
  80. float m_flAwakeTime;
  81. bool m_doBleedOut;
  82. #if RAGDOLL_VISUALIZE
  83. matrix3x4_t m_savedBone1[MAXSTUDIOBONES];
  84. matrix3x4_t m_savedBone2[MAXSTUDIOBONES];
  85. matrix3x4_t m_savedBone3[MAXSTUDIOBONES];
  86. #endif
  87. public:
  88. ragdoll_t *GetRagdoll( void ){ return &m_ragdoll; }
  89. };
  90. CRagdoll *CreateRagdoll(
  91. C_BaseEntity *ent,
  92. CStudioHdr *pstudiohdr,
  93. const Vector &forceVector,
  94. int forceBone,
  95. const matrix3x4_t *pDeltaBones0,
  96. const matrix3x4_t *pDeltaBones1,
  97. const matrix3x4_t *pCurrentBonePosition,
  98. float boneDt,
  99. bool bFixedConstraints=false,
  100. bool bBleedOutOnSleep=true);
  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