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.

536 lines
22 KiB

  1. //========= Copyright � Valve Corporation, All rights reserved. ============//
  2. //
  3. // A port of CRnSoftbody
  4. // Note: mathlib is tentative place for this code. We will probably move it to a separate lib or dll or vphysics.dll
  5. //
  6. #ifndef MATHLIB_SOFTBODY_HDR
  7. #define MATHLIB_SOFTBODY_HDR
  8. #include "rubikon/param_types.h"
  9. #include "rubikon/debugname.h"
  10. #include "rubikon/intersection.h"
  11. // #include "rnmath.h"
  12. // #include "geometry.h"
  13. // #include "mass.h"
  14. // #include "graphedge.h"
  15. // #include "collisionfilter.h"
  16. // #include "rnserialize.h"
  17. // #include "legacyobject.h"
  18. #include "tier1/utlbuffer.h"
  19. #include "mathlib/femodel.h"
  20. #include "tier1/hierarchicalbitvec.h"
  21. #include "rubikon/serializehelpers.h"
  22. class CRnSoftbodyDesc;
  23. class CSoftbodyEnvironment;
  24. class CRnBody;
  25. class CRnJoint;
  26. struct PhysSoftbodyDesc_t;
  27. class CJob ;
  28. class CSoftbody;
  29. class CFeModel;
  30. struct FilterTransformsParams_t;
  31. struct SetNodePositionsParams_t;
  32. class CFeModelReplaceContext;
  33. class IVDebugOverlay;
  34. class IMesh;
  35. struct FilterTransformsParams_t
  36. {
  37. matrix3x4a_t *pOutputWorldTransforms;
  38. const int16 *pCtrlToBone;
  39. const uint32 *pValidTransforms;
  40. VectorAligned *pNodePos;
  41. bool flMatrixScale; // Scale to convey in matrices; 1.0 will not scale anything (appropriate for Hammer conventions). 0.0 means use the model scale (appropriate for game conventions)
  42. };
  43. struct SetNodePositionsParams_t
  44. {
  45. SetNodePositionsParams_t()
  46. {
  47. nFrame = 1;
  48. }
  49. const VectorAligned *pPos;
  50. int nCount;
  51. Vector vAbsOrigin;
  52. QAngle vAbsAngles;
  53. int nFrame;
  54. };
  55. class CParticleGlue
  56. {
  57. public:
  58. float m_flStickiness;
  59. float m_flWeight1; // 0: only use parent [0], >0 : blend from [0] to [1]
  60. uint16 m_nParentNode[ 2 ]; // this is actual node index; we're mostly parented to static nodes
  61. public:
  62. CParticleGlue(){}
  63. CParticleGlue( uint nParentNode, float flStickiness )
  64. {
  65. m_flStickiness = flStickiness;
  66. m_flWeight1 = 0;
  67. m_nParentNode[ 0 ] = m_nParentNode[ 1 ] = nParentNode;
  68. }
  69. };
  70. class ALIGN16 CSoftbody
  71. {
  72. public:
  73. CSoftbody( void );
  74. CSoftbody( CSoftbodyEnvironment *pWorld, const CFeModel *pFeModel );
  75. ~CSoftbody();
  76. void Shutdown( );
  77. void Init( int numModelBones = 0);
  78. void Init( CSoftbodyEnvironment *pWorld, const CFeModel *pFeModel, int numModelBones );
  79. void InitFeModel( int numModelBones = 0 );
  80. void InitDefaults( );
  81. void Integrate( float flTimeStep );
  82. void IntegrateWind( VectorAligned *pPos, float flTimeStep );
  83. void RawSimulate( int nIterations, float flTimeStep );
  84. void ValidatingSimulate( int nIterations, float flTimeStep );
  85. void AddAnimationAttraction( float flTimeStep );
  86. void Predict( float flTimeStep );
  87. void Post( );
  88. void Collide();
  89. void CollideWithWorldInternal();
  90. void CollideWithRigidsInternal();
  91. // void CollideTaperedCapsule( uint16 nCollisionMask, const VectorAligned &vCenter0, float flRadius0, const VectorAligned &vCenter1, float flRadius1, const Vector &vAxis, float flDist );
  92. // void CollideTaperedCapsule( uint16 nCollisionMask, const VectorAligned &vCenter0, float flRadius0, const VectorAligned &vCenter1, float flRadius1 );
  93. // @begin_publish
  94. uint Step( int nIterations, float flTimeStep );
  95. uint Step( float flTimeStep );
  96. uint GetStateHash()const;
  97. void TouchAnimatedTransforms();
  98. void SetAnimatedTransform( int nParticle, const matrix3x4a_t &transform );
  99. void SetAnimatedTransforms( const matrix3x4a_t *pSimulationWorldTransforms );
  100. void SetAnimatedTransformsNoScale( const matrix3x4a_t *pSimulationWorldTransforms );
  101. matrix3x4a_t* GetParticleTransforms( const VectorAligned *pInputNodePos = NULL, uint nFlags = 0 );
  102. const VectorAligned* GetNodePositions( int nFrame = 1 ) const { return nFrame ? m_pPos1 : m_pPos0; }
  103. VectorAligned* GetNodePositions( int nFrame = 1 ) { return nFrame ? m_pPos1 : m_pPos0; }
  104. void SetNodePositions( const Vector *pPos, int nCount, int nFrame = 1 );
  105. void SetNodePositions( SetNodePositionsParams_t &params );
  106. uint GetNodeCount() const { return m_nNodeCount; }
  107. uint GetCtrlCount() const { return m_nParticleCount; }
  108. Vector GetNodeVelocity( uint nNode ) const { return ( m_pPos1[ nNode ] - m_pPos0[ nNode ] ) / m_flLastTimestep; }
  109. Vector GetCtrlVelocity( uint nCtrl ) const;
  110. matrix3x4a_t* GetAnimatedTransforms( ) { return m_pParticles; }
  111. const matrix3x4a_t* GetAnimatedTransforms() const { return m_pParticles; }
  112. matrix3x4a_t* GetSimulatedTransforms() { return m_pParticles + m_nParticleCount; }
  113. const matrix3x4a_t* GetSimulatedTransforms() const { return m_pParticles + m_nParticleCount; }
  114. const CFeModel *GetFeModel()const { return m_pFeModel; }
  115. CFeModel *GetFeModel( ){ return m_pFeModel; }
  116. CSoftbodyEnvironment *GetEnvironment( ) const { return m_pEnvironment; }
  117. int GetParticleCount( ) const { return m_nParticleCount; }
  118. void SetDebugNameV( const char* pNameFormat, va_list args ) { m_DebugName.SetV( pNameFormat, args );}
  119. const char *GetDebugName() const { return m_DebugName.Get(); }
  120. void AppendDebugInfo( CUtlString &line );
  121. void Draw( const RnDebugDrawOptions_t &options, IVDebugOverlay* pDebugOverlay );
  122. void Draw( const RnDebugDrawOptions_t &options, IMesh *pDynamicMesh );
  123. void SetPose() { SetPose( m_pFeModel->m_pInitPose ); }
  124. void SetPose( const CTransform *pPose );
  125. void SetPose( const CTransform &tm ) { SetPose( tm, m_pFeModel->m_pInitPose ); }
  126. void SetPose( const CTransform &tm, const CTransform *pPose );
  127. void SetPoseFromBones( const int16 *pCtrlToBone, const matrix3x4a_t *pBones, float flScale = 1.0f );
  128. void SetCtrl( int nParticle, const CTransform &tm );
  129. void SetDebugSelection( int nSelection );
  130. void SetSimFlags( uint nNewSimFlags );
  131. void AddSimFlags( uint nAddSimFlags ) { SetSimFlags( m_nSimFlags | nAddSimFlags ); }
  132. void ClearSimFlags( uint nClearSimFlags ) { SetSimFlags( m_nSimFlags & ~nClearSimFlags ); }
  133. void SetAnimSpace( PhysicsSoftbodyAnimSpace_t nAnimSpace ) { m_nAnimSpace = nAnimSpace; }
  134. PhysicsSoftbodyAnimSpace_t GetAnimSpace()const { return m_nAnimSpace; }
  135. uint GetSimFlags()const { return m_nSimFlags; }
  136. int CastCone( const Vector &vStart, const Vector &vDir, float flConePitch );
  137. uint GetContactCount( )const { return 0; }
  138. void SetOverPredict( float flOverPredict ) { m_flOverPredict = flOverPredict; }
  139. float GetOverPredict( ) const { return m_flOverPredict; }
  140. void ResetVelocities( );
  141. void SetThreadStretch( float flBendUnderRelax ) { m_flThreadStretch = flBendUnderRelax; }
  142. float GetThreadStretch( )const { return m_flThreadStretch; }
  143. void SetSurfaceStretch( float flStretchUnderRelax ) { m_flSurfaceStretch = flStretchUnderRelax; }
  144. float GetSurfaceStretch( )const { return m_flSurfaceStretch; }
  145. void SetStepUnderRelax( float flStepUnderRelax ) { m_flStepUnderRelax = flStepUnderRelax; }
  146. float GetStepUnderRelax( void ) const { return m_flStepUnderRelax; }
  147. AABB_t BuildBounds( )const;
  148. void FilterTransforms( const FilterTransformsParams_t &params );
  149. void FilterTransforms( matrix3x4a_t *pModelBones );
  150. void SetGravityScale( float flScale ) { m_flGravityScale = flScale; }
  151. void EnableGravity( bool bEnableGravity ) { m_bGravityDisabled = !bEnableGravity; }
  152. void EnableGravity( ) { m_bGravityDisabled = false; }
  153. void DisableGravity( ) { m_bGravityDisabled = true; }
  154. bool IsGravityEnabled( ) const { return !m_bGravityDisabled; }
  155. bool IsGravityDisabled( ) const { return m_bGravityDisabled; }
  156. bool IsFtlPassEnabled( ) const { return m_bEnableFtlPass; }
  157. void EnableFtlPass( bool bEnable ) { m_bEnableFtlPass = bEnable; }
  158. float GetGravityScale( void ) const{ return m_flGravityScale; }
  159. Vector GetEffectiveGravity( void ) const;
  160. float GetEffectiveGravityScale( void ) const;
  161. void EnableAnimationAttraction( bool bEnable ) { m_bEnableAnimationAttraction = bEnable; }
  162. bool IsAnimationAttractionEnabled( )const { return m_bEnableAnimationAttraction; }
  163. void EnableFollowNode( bool bEnable ) { m_bEnableFollowNodes = bEnable; }
  164. bool IsFollowNodeEnabled( ) const { return m_bEnableFollowNodes; }
  165. void EnableSprings( bool bEnable ){ m_bEnableSprings = bEnable; }
  166. bool AreSpringsEnabled( )const { return m_bEnableSprings; }
  167. void EnableInclusiveCollisionSpheres( bool bEnable ) { m_bEnableInclusiveCollisionSpheres = bEnable; }
  168. bool AreInclusiveCollisionSpheresEnabled( ) const { return m_bEnableInclusiveCollisionSpheres; }
  169. void EnableExclusiveCollisionSpheres( bool bEnable ) { m_bEnableExclusiveCollisionSpheres = bEnable; }
  170. bool AreExclusiveCollisionSpheresEnabled( ) const { return m_bEnableExclusiveCollisionSpheres; }
  171. void EnableCollisionPlanes( bool bEnable ) { m_bEnableCollisionPlanes = bEnable; }
  172. bool AreCollisionPlanesEnabled( ) const { return m_bEnableCollisionPlanes; }
  173. void EnableGroundCollision( bool bEnable ) { m_bEnableGroundCollision = bEnable; }
  174. bool IsGroundCollisionEnabled( ) const { return m_bEnableGroundCollision; }
  175. void EnableGroundTrace( bool bEnable ) { m_bEnableGroundTrace = bEnable; }
  176. bool IsGroundTraceEnabled( ) const { return m_bEnableGroundTrace; }
  177. float GetTimeStep( void )const { return m_flLastTimestep; }
  178. void SetModelScale( float flModelScale ) { m_flModelScale = flModelScale; }
  179. float GetModelScale( )const { return m_flModelScale; }
  180. void SetVelocityDamping( float flDamping ) { m_flVelocityDamping = flDamping; } // 1.0f - full damping; 0.0 - no damping (default)
  181. float GetVelocityDamping( )const { return m_flVelocityDamping; }
  182. void SetUserData( uint nIndex, void *pData );
  183. void* GetUserData( uint nIndex );
  184. //void SetOrigin( const Vector &vAbsOrigin );
  185. void InitializeTransforms( const int16 *pCtrlToBone, const matrix3x4a_t *pSimulationWorldTransforms );
  186. void SetAbsAngles( const QAngle &vNewAngles, bool bTeleport );
  187. const QAngle GetAbsAngles() const { return m_vSimAngles; }
  188. void SetAbsOrigin( const Vector &vNewOrigin, bool bTeleport );
  189. const Vector GetAbsOrigin()const { return m_vSimOrigin; }
  190. float GetEnergy( PhysicsSoftbodyEnergyTypeEnum_t nEnergy )const;
  191. float GetElasticEnergy( )const;
  192. float GetPotentialEnergy( )const;
  193. float GetKinematicEnergy( )const;
  194. void SetDampingMultiplier( float flMul ) { m_flDampingMultiplier = flMul; }
  195. float GetDampingMultiplier( )const { return m_flDampingMultiplier; }
  196. void SetGroundZ( float flGroundZ ) { m_vGround.Init( m_vSimOrigin.x, m_vSimOrigin.y, flGroundZ ); }
  197. float GetGroundZ( )const { return m_vGround.z; }
  198. bool IsDormant( )const;
  199. void GoDormant( );
  200. bool AdvanceSleepCounter();
  201. void GoWakeup( );
  202. bool IsActive()const;
  203. bool BeforeFilterTransforms( );
  204. void SetDebugDrawTreeBeginLevel( int nLevel ) { m_nDebugDrawTreeBeginLevel = nLevel; }
  205. int GetDebugDrawTreeBeginLevel() { return m_nDebugDrawTreeBeginLevel; }
  206. void SetDebugDrawTreeEndLevel( int nLevel ) { m_nDebugDrawTreeEndLevel = nLevel; }
  207. int GetDebugDrawTreeEndLevel() { return m_nDebugDrawTreeEndLevel; }
  208. void SetDebugDrawTreeFlags( uint nFlags ) { m_nDebugDrawTreeFlags = nFlags; }
  209. uint GetDebugDrawTreeFlags(){ return m_nDebugDrawTreeFlags; }
  210. void EnableDebugDraw( bool bEnable ){ m_bDebugDraw = bEnable; }
  211. void EnableDebugRendering( bool bEnable );
  212. float GetVelAirDrag() const { return m_flVelAirDrag; }
  213. void SetVelAirDrag( float flVelAirDrag ){ m_flVelAirDrag = flVelAirDrag; }
  214. float GetExpAirDrag() const { return m_flExpAirDrag; }
  215. void SetExpAirDrag( float flExpAirDrag ){ m_flExpAirDrag = flExpAirDrag; }
  216. float GetVelQuadAirDrag() const { return m_flVelQuadAirDrag; }
  217. void SetVelQuadAirDrag( float flVelQuadAirDrag ){ m_flVelQuadAirDrag = flVelQuadAirDrag; }
  218. float GetExpQuadAirDrag() const { return m_flExpQuadAirDrag; }
  219. void SetExpQuadAirDrag( float flExpQuadAirDrag ){ m_flExpQuadAirDrag = flExpQuadAirDrag; }
  220. float GetVelRodAirDrag() const { return m_flVelRodAirDrag; }
  221. void SetVelRodAirDrag( float flVelRodAirDrag ){ m_flVelRodAirDrag = flVelRodAirDrag; }
  222. float GetExpRodAirDrag() const { return m_flExpRodAirDrag; }
  223. void SetExpRodAirDrag( float flExpRodAirDrag ){ m_flExpRodAirDrag = flExpRodAirDrag; }
  224. float GetQuadVelocitySmoothRate()const { return m_flQuadVelocitySmoothRate; }
  225. void SetQuadVelocitySmoothRate( float flRate ){ m_flQuadVelocitySmoothRate = flRate; }
  226. float GetRodVelocitySmoothRate()const { return m_flRodVelocitySmoothRate; }
  227. void SetRodVelocitySmoothRate( float flRate ){ m_flRodVelocitySmoothRate = flRate; }
  228. uint16 GetQuadVelocitySmoothIterations()const { return m_nQuadVelocitySmoothIterations; }
  229. void SetQuadVelocitySmoothIterations( uint16 nIterations ){ m_nQuadVelocitySmoothIterations = nIterations; }
  230. uint16 GetRodVelocitySmoothIterations()const { return m_nRodVelocitySmoothIterations; }
  231. void SetRodVelocitySmoothIterations( uint16 nIterations ){ m_nRodVelocitySmoothIterations = nIterations; }
  232. const RnCollisionAttr_t &GetCollisionAttributes() const { return m_CollisionAttributes; }
  233. void SetCollisionAttributes( const RnCollisionAttr_t &attr );
  234. int GetIndexInWorld() const { return m_nIndexInWorld; }
  235. void ReplaceFeModel( CFeModelReplaceContext &context );
  236. matrix3x4_t GetDifferenceTransform( const Vector &vAltOrigin, const QAngle &vAltAngles );
  237. void ComputeInterpolatedNodePositions( float flFactor, VectorAligned *pPosOut );
  238. void SetInstanceSettings( void *pSettings );
  239. void SetFrozen( bool bFrozen ) { m_bFrozen = true; }
  240. bool IsFrozen()const { return m_bFrozen; }
  241. void SetVolumetricSolveAmount( float flVolumetricSolveAmount ) { m_flVolumetricSolveAmount = flVolumetricSolveAmount; }
  242. float GetVolumetricSolveAmount()const { return m_flVolumetricSolveAmount; }
  243. void ParseParticleState( CUtlBuffer &buf, float flTimeStep );
  244. CUtlString PrintParticleState( )const;
  245. int16 *GetModelBoneToCtrl() { return m_pModelBoneToCtrl; }
  246. void BindModelBoneToCtrl( int nModelBone, int nCtrl );
  247. //bool SetupCtrl( uint nCtrl, matrix3x4a_t &writeBone );
  248. // @end_publish
  249. void DebugDump( );
  250. void UpdateCtrlOffsets( bool bOverridePose );
  251. uint ComputeVirtualCtrls( CVarBitVec &virtualNodes );
  252. matrix3x4a_t &GetAnim( int i ) { return GetAnimatedTransforms()[ i ]; }
  253. const matrix3x4a_t &GetAnim( int i ) const { return GetAnimatedTransforms()[ i ]; }
  254. matrix3x4a_t &GetSim( int i ) { return GetSimulatedTransforms()[ i ]; }
  255. const matrix3x4a_t &GetSim( int i ) const { return GetSimulatedTransforms()[ i ]; }
  256. uint ShouldUsePreconditioner()const { return m_nSimFlags & ( SOFTBODY_SIM_DIAGONAL_PRECONDITIONER | SOFTBODY_SIM_TRIDIAGONAL_PRECONDITIONER | SOFTBODY_SIM_RELAXATION_PRECONDITIONER ); }
  257. class CWorldIndexPred
  258. {
  259. public:
  260. static int GetIndex( const CSoftbody *pBody ) { return pBody->m_nIndexInWorld; }
  261. static void SetIndex( CSoftbody *pBody, int nIndex ) { pBody->m_nIndexInWorld = nIndex; }
  262. };
  263. friend class CWorldIndexPred;
  264. uint GetParticleArrayCount( ) const { return m_nParticleCount * 2; }
  265. void Validate();
  266. void DebugPreStep( float flTimeStep );
  267. void DebugPostStep();
  268. class CConstraintIterator
  269. {
  270. public:
  271. CConstraintIterator( CSoftbody *pSoftbody );
  272. ~CConstraintIterator( );
  273. void Iterate( int nIterations );
  274. protected:
  275. CSoftbody *m_pSoftbody;
  276. CSoftbodyEnvironment *m_pEnvironment;
  277. CUtlVectorFixedGrowable< VectorAligned, 128 > m_PosBeforeCorrect; // the biggest hero in source1 is Medusa, with 104 nodes (52 useful, 52 virtual)
  278. };
  279. friend class CConstraintIterator;
  280. void GlueNode( uint nDynNode, uint nParentNode, float flStickiness );
  281. void GlueNode( uint nDynNode, uint nParentNode0, uint nParentNode1, float flStickiness, float flWeight1 );
  282. void GlueNode( uint nDynNode, const CParticleGlue &glue, float flReplacementStickiness );
  283. void DebugTraceMove( const char *pMsg );
  284. protected:
  285. void Integrate_S1( float flTimeStep );
  286. void ResolveStretch_S1( float flTimeStep );
  287. void ResolveAnimAttraction_S1( float flTimeStep );
  288. protected:
  289. friend class CRnSoftbodyChangeGuard;
  290. CRnDebugName m_DebugName;
  291. CSoftbodyEnvironment *m_pEnvironment;
  292. RnCollisionAttr_t m_CollisionAttributes;
  293. CFeModel *m_pFeModel; // Finite Element Model
  294. float m_flThreadStretch; // positive: underrelax; negative: overrelax
  295. float m_flSurfaceStretch;
  296. float m_flStepUnderRelax;
  297. float m_flOverPredict; // 0 : normal integration; positive: overpredict, correct, step back
  298. float m_flGravityScale;
  299. uint m_nNodeCount; // actual simulated node count (includes static and dynamic nodes: even though static nodes are not simulated, we need their coordinates to simulate the other nodes connected to them)
  300. uint m_nParticleCount; // Ctrl count
  301. float m_flModelScale;
  302. float m_flVelocityDamping;
  303. float m_flDampingMultiplier;
  304. float m_flClothScale;
  305. Vector m_vGround;
  306. Vector m_vSimOrigin;
  307. QAngle m_vSimAngles;
  308. matrix3x4a_t *m_pParticles SERIALIZE_ARRAY_SIZE( GetParticleArrayCount() );
  309. VectorAligned *m_pPos0 SERIALIZE_ARRAY_SIZE( m_nNodeCount );
  310. VectorAligned *m_pPos1 SERIALIZE_ARRAY_SIZE( m_nNodeCount );
  311. FeAabb_t *m_pAabb SERIALIZE_ARRAY_SIZE( m_pFeModel->GetDynamicNodeCount() - 1 );
  312. int16 *m_pModelBoneToCtrl;
  313. int16 *m_pCtrlToModelBone;
  314. CHierarchicalBitVector m_StickyBuffer; // sticky particles
  315. CParticleGlue *m_pParticleGlue SERIALIZE_ARRAY_SIZE( m_pFeModel->GetDynamicNodeCount() );
  316. enum StateEnum_t
  317. {
  318. STATE_ACTIVE, // actively simulating, taking in transforms, filtering out transforms
  319. STATE_DORMANT,// not simulating, not taking in transforms, not filtering anything
  320. STATE_WAKEUP, // StateCounter == 0 : not simulating, readying to take in transforms, not filtering anything, not copying transforms
  321. // StateCounter > 0 : not simulating, taking in transforms, not filtering anything, copying transforms
  322. STEPS_INVISIBLE_BEFORE_DORMANT = 12,
  323. FRAMES_INVISIBLE_BEFORE_DORMANT = 3
  324. };
  325. uint32 m_nSimFlags;
  326. uint32 m_nStepsSimulated;
  327. int8 m_nDebugDrawTreeEndLevel;
  328. int8 m_nDebugDrawTreeBeginLevel;
  329. uint8 m_nDebugDrawTreeFlags;
  330. // STATE_ACTIVE: how many steps we've taken without having FilterTransforms called once
  331. // STATE_DORMANT: doesn't matter
  332. // STATE_WAKEUP: how many times we've set animated transforms (need 2 to switch to ACTIVE state)
  333. uint8 m_nStateCounter;
  334. float m_flLastTimestep;
  335. float m_flVelAirDrag;
  336. float m_flExpAirDrag;
  337. float m_flVelQuadAirDrag;
  338. float m_flExpQuadAirDrag;
  339. float m_flVelRodAirDrag;
  340. float m_flExpRodAirDrag;
  341. float m_flQuadVelocitySmoothRate;
  342. float m_flRodVelocitySmoothRate;
  343. float m_flVolumetricSolveAmount;
  344. uint16 m_nQuadVelocitySmoothIterations;
  345. uint16 m_nRodVelocitySmoothIterations;
  346. int m_nIndexInWorld;
  347. int m_nDebugSelection;
  348. Vector m_vRopeOffset; // <sergiy> a horrible S1 cloth rope hack I'm faithfully replicating so that dota cloth looks exactly the same
  349. uintp m_pUserData[ 2 ] ;
  350. StateEnum_t m_nActivityState;
  351. //uint m_nDebugNode;
  352. uint8 m_nEnableWorldShapeCollision : 4;
  353. PhysicsSoftbodyAnimSpace_t m_nAnimSpace : 2;
  354. bool m_bAnimTransformChanged : 1; // True means that the animation transforms, that the game sets from outside, have changed and need to be propagated into the simulation
  355. bool m_bSimTransformsOutdated : 1; // True means that the sim transforms, that the game queries from outside, are out of date and need to be copied from the simulation (and their rotations computed)
  356. bool m_bGravityDisabled : 1;
  357. bool m_bEnableAnimationAttraction : 1;
  358. bool m_bEnableFollowNodes : 1;
  359. bool m_bEnableSprings : 1;
  360. bool m_bEnableInclusiveCollisionSpheres : 1;
  361. bool m_bEnableExclusiveCollisionSpheres : 1;
  362. bool m_bEnableCollisionPlanes : 1;
  363. bool m_bEnableGroundCollision : 1;
  364. bool m_bEnableGroundTrace : 1;
  365. bool m_bEnableFtlPass : 1;
  366. bool m_bFrozen : 1;
  367. bool m_bDebugDraw : 1;
  368. bool m_bEnableSimd : 1;
  369. /*
  370. bool m_bTeleportOnNextSetAbsOrigin : 1;
  371. bool m_bTeleportOnNextSetAbsAngles : 1;
  372. */
  373. friend class CTaperedCapsuleColliderFunctor;
  374. friend class CGluePredictFunctor;
  375. friend class CSphereColliderFunctor;
  376. } ALIGN16_POST;
  377. inline void CSoftbody::GlueNode( uint nDynNode, uint nParentNode, float flStickiness )
  378. {
  379. Assert( nDynNode < m_pFeModel->GetDynamicNodeCount() );
  380. m_StickyBuffer.Set( nDynNode );
  381. CParticleGlue &glue = m_pParticleGlue[ nDynNode ];
  382. glue.m_flStickiness = flStickiness;
  383. glue.m_flWeight1 = 0;
  384. glue.m_nParentNode[ 0 ] = nParentNode;
  385. glue.m_nParentNode[ 1 ] = nParentNode;
  386. }
  387. inline void CSoftbody::GlueNode( uint nDynNode, uint nParentNode0, uint nParentNode1, float flStickiness, float flWeight1 )
  388. {
  389. Assert( nDynNode < m_pFeModel->GetDynamicNodeCount() );
  390. m_StickyBuffer.Set( nDynNode );
  391. CParticleGlue &glue = m_pParticleGlue[ nDynNode ];
  392. glue.m_flStickiness = flStickiness;
  393. glue.m_flWeight1 = flWeight1;
  394. glue.m_nParentNode[ 0 ] = nParentNode0;
  395. glue.m_nParentNode[ 1 ] = nParentNode1;
  396. }
  397. inline void CSoftbody::GlueNode( uint nDynNode, const CParticleGlue &glueBase, float flReplacementStickiness )
  398. {
  399. m_StickyBuffer.Set( nDynNode );
  400. CParticleGlue &glueNode = m_pParticleGlue[ nDynNode ];
  401. glueNode.m_flStickiness = flReplacementStickiness;
  402. glueNode.m_flWeight1 = glueBase.m_flWeight1; // 0: only use parent [0], >0 : blend from [0] to [1]
  403. glueNode.m_nParentNode[ 0 ] = glueBase.m_nParentNode[ 0 ];
  404. glueNode.m_nParentNode[ 1 ] = glueBase.m_nParentNode[ 1 ];
  405. }
  406. class CSphereColliderFunctor
  407. {
  408. public:
  409. VectorAligned m_Sphere;
  410. VectorAligned *m_pDynPos1;
  411. const float *m_pNodeCollisionRadii;
  412. CSoftbody *m_pSoftbody;
  413. float m_flStickiness;
  414. uint16 m_nParentNode; // needed for gluing particle to this node
  415. public:
  416. CSphereColliderFunctor(){}
  417. CSphereColliderFunctor( CSoftbody *pSoftbody, const Vector &vSphereCenter, float flSphereRadius, float flStickiness, uint16 nParentNode )
  418. {
  419. m_flStickiness = flStickiness;
  420. m_nParentNode = nParentNode;
  421. m_pSoftbody = pSoftbody;
  422. m_Sphere = vSphereCenter;
  423. m_Sphere.w = flSphereRadius;
  424. const CFeModel *pFeModel = pSoftbody->GetFeModel();
  425. m_pDynPos1 = pSoftbody->m_pPos1 + pFeModel->m_nStaticNodes;
  426. m_pNodeCollisionRadii = pFeModel->m_pNodeCollisionRadii;
  427. }
  428. void Collide( uint16 nCollisionMask );
  429. };
  430. class CTaperedCapsuleColliderFunctor
  431. {
  432. public:
  433. VectorAligned m_vSphereCenter0;
  434. VectorAligned m_vSphereCenter1;
  435. VectorAligned *m_pDynPos1;
  436. const float *m_pNodeCollisionRadii;
  437. CSoftbody *m_pSoftbody;
  438. float m_flStickiness;
  439. uint16 m_nParentNode[ 2 ];
  440. float m_flSlope;
  441. Vector m_vAxisX;
  442. float m_flDist;
  443. public:
  444. CTaperedCapsuleColliderFunctor(){}
  445. CTaperedCapsuleColliderFunctor( CSoftbody *pSoftbody, const Vector &vSphereCenter0, float flSphereRadius0, const Vector &vSphereCenter1, float flSphereRadius1, float flStickiness, uint16 nParentNodes0, uint16 nParentNodes1 )
  446. {
  447. m_pSoftbody = pSoftbody;
  448. m_vSphereCenter0 = vSphereCenter0;
  449. m_vSphereCenter0.w = flSphereRadius0;
  450. m_vSphereCenter1 = vSphereCenter1;
  451. m_vSphereCenter1.w = flSphereRadius1;
  452. m_flStickiness = flStickiness;
  453. m_nParentNode[ 0 ] = nParentNodes0;
  454. m_nParentNode[ 1 ] = nParentNodes1;
  455. const CFeModel *pFeModel = pSoftbody->GetFeModel();
  456. m_pDynPos1 = pSoftbody->m_pPos1 + pFeModel->m_nStaticNodes;
  457. m_pNodeCollisionRadii = pFeModel->m_pNodeCollisionRadii;
  458. m_vAxisX = ( vSphereCenter1 - vSphereCenter0 ) ;
  459. m_flDist = m_vAxisX.Length();
  460. m_vAxisX /= m_flDist;
  461. m_flSlope = ( flSphereRadius1 - flSphereRadius0 ) / m_flDist;
  462. }
  463. void Collide( uint16 nCollisionMask );
  464. };
  465. #endif