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.

104 lines
3.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef PHYSICS_BONE_FOLLOWER_H
  7. #define PHYSICS_BONE_FOLLOWER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. class CBoneFollower;
  12. //
  13. // To use bone followers in an entity, contain a CBoneFollowerManager in it. Then:
  14. // - Call InitBoneFollowers() in the entity's CreateVPhysics().
  15. // - Call UpdateBoneFollowers() after you move your bones.
  16. // - Call DestroyBoneFollowers() when your entity's removed
  17. struct physfollower_t
  18. {
  19. DECLARE_SIMPLE_DATADESC();
  20. int boneIndex;
  21. CHandle<CBoneFollower> hFollower;
  22. };
  23. struct vcollide_t;
  24. // create a manager and a list of followers directly from a ragdoll
  25. void CreateBoneFollowersFromRagdoll( CBaseAnimating *pEntity, class CBoneFollowerManager *pManager, vcollide_t *pCollide );
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. //-----------------------------------------------------------------------------
  29. class CBoneFollowerManager
  30. {
  31. DECLARE_SIMPLE_DATADESC();
  32. public:
  33. CBoneFollowerManager();
  34. ~CBoneFollowerManager();
  35. // Use either of these to create the bone followers in your entity's CreateVPhysics()
  36. void InitBoneFollowers( CBaseAnimating *pParentEntity, int iNumBones, const char **pFollowerBoneNames );
  37. void AddBoneFollower( CBaseAnimating *pParentEntity, const char *pFollowerBoneName, solid_t *pSolid = NULL ); // Adds a single bone follower
  38. // Call this after you move your bones
  39. void UpdateBoneFollowers( CBaseAnimating *pParentEntity );
  40. // Call this when your entity's removed
  41. void DestroyBoneFollowers( void );
  42. physfollower_t *GetBoneFollower( int iFollowerIndex );
  43. int GetBoneFollowerIndex( CBoneFollower *pFollower );
  44. int GetNumBoneFollowers( void ) const { return m_iNumBones; }
  45. private:
  46. bool CreatePhysicsFollower( CBaseAnimating *pParentEntity, physfollower_t &follow, const char *pBoneName, solid_t *pSolid );
  47. private:
  48. int m_iNumBones;
  49. CUtlVector<physfollower_t> m_physBones;
  50. };
  51. class CBoneFollower : public CBaseEntity
  52. {
  53. DECLARE_CLASS( CBoneFollower, CBaseEntity );
  54. DECLARE_DATADESC();
  55. DECLARE_SERVERCLASS();
  56. public:
  57. // CBaseEntity
  58. void VPhysicsUpdate( IPhysicsObject *pPhysics );
  59. int UpdateTransmitState(void);
  60. // NOTE: These are forwarded to the parent object!
  61. void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  62. void VPhysicsFriction( IPhysicsObject *pObject, float energy, int surfaceProps, int surfacePropsHit );
  63. void VPhysicsShadowCollision( int index, gamevcollisionevent_t *pEvent );
  64. bool TestCollision( const Ray_t &ray, unsigned int mask, trace_t& trace );
  65. int ObjectCaps( void );
  66. void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  67. void Touch( CBaseEntity *pOther );
  68. void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr );
  69. // locals
  70. bool Init( CBaseEntity *pOwner, const char *pModelName, solid_t &solid, const Vector &position, const QAngle &orientation );
  71. void UpdateFollower( const Vector &position, const QAngle &orientation, float flInterval );
  72. void SetTraceData( int physicsBone, int hitGroup );
  73. // factory
  74. static CBoneFollower *Create( CBaseEntity *pOwner, const char *pModelName, solid_t &solid, const Vector &position, const QAngle &orientation );
  75. private:
  76. CNetworkVar( int, m_modelIndex );
  77. CNetworkVar( int, m_solidIndex );
  78. int m_physicsBone;
  79. int m_hitGroup;
  80. };
  81. #endif // PHYSICS_BONE_FOLLOWER_H