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.

117 lines
2.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef ROPE_PHYSICS_H
  8. #define ROPE_PHYSICS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "simple_physics.h"
  13. #include "networkvar.h"
  14. class CRopeSpring
  15. {
  16. public:
  17. Vector *m_pNode1;
  18. Vector *m_pNode2;
  19. };
  20. class CBaseRopePhysics : public CSimplePhysics::IHelper
  21. {
  22. public:
  23. DECLARE_CLASS_NOBASE( CBaseRopePhysics );
  24. CBaseRopePhysics(
  25. CSimplePhysics::CNode *pNodes,
  26. int nNodes,
  27. CRopeSpring *pSprings,
  28. float *flSpringDistsSqr );
  29. // nNodes should be less than or equal to what you passed into the constructor.
  30. void SetNumNodes( int nNodes );
  31. // Restart timers and such.
  32. void Restart();
  33. void ResetSpringLength(float flSpringDist );
  34. float GetSpringLength() const;
  35. void ResetNodeSpringLength( int iStartNode, float flSpringDist );
  36. // Set simulation parameters.
  37. // If you pass in a delegate, you can be called to apply constraints.
  38. void SetupSimulation( float flSpringDist, CSimplePhysics::IHelper *pDelegate=0 );
  39. // Set the physics delegate.
  40. void SetDelegate( CSimplePhysics::IHelper *pDelegate );
  41. void Simulate( float dt );
  42. int NumNodes() { return m_nNodes; }
  43. CSimplePhysics::CNode* GetNode( int iNode ) { return &m_pNodes[iNode]; }
  44. CSimplePhysics::CNode* GetFirstNode() { return &m_pNodes[0]; }
  45. CSimplePhysics::CNode* GetLastNode() { return &m_pNodes[ m_nNodes-1 ]; }
  46. public:
  47. virtual void GetNodeForces( CSimplePhysics::CNode *pNodes, int iNode, Vector *pAccel );
  48. virtual void ApplyConstraints( CSimplePhysics::CNode *pNodes, int nNodes );
  49. private:
  50. int NumSprings() {return m_nNodes - 1;}
  51. protected:
  52. CSimplePhysics::IHelper *m_pDelegate;
  53. CSimplePhysics::CNode *m_pNodes;
  54. int m_nNodes;
  55. CRopeSpring *m_pSprings;
  56. float m_flSpringDist;
  57. float m_flSpringDistSqr;
  58. // Spring lengths per node
  59. float *m_flNodeSpringDistsSqr;
  60. CSimplePhysics m_Physics;
  61. };
  62. template< int NUM_NODES >
  63. class CRopePhysics : public CBaseRopePhysics
  64. {
  65. public:
  66. CRopePhysics();
  67. CSimplePhysics::CNode m_Nodes[NUM_NODES];
  68. CRopeSpring m_Springs[NUM_NODES - 1];
  69. float m_SpringDistsSqr[NUM_NODES - 1];
  70. };
  71. template< int NUM_NODES >
  72. CRopePhysics<NUM_NODES>::CRopePhysics() :
  73. CBaseRopePhysics( m_Nodes, NUM_NODES, m_Springs, m_SpringDistsSqr )
  74. {
  75. }
  76. #endif // ROPE_PHYSICS_H