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.

177 lines
7.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef PHYSICS_SHARED_H
  7. #define PHYSICS_SHARED_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. class IPhysics;
  12. class IPhysicsEnvironment;
  13. class IPhysicsSurfaceProps;
  14. class IPhysicsCollision;
  15. class IPhysicsObject;
  16. class IPhysicsObjectPairHash;
  17. class CSoundPatch;
  18. extern IPhysicsObject *g_PhysWorldObject;
  19. extern IPhysics *physics;
  20. extern IPhysicsCollision *physcollision;
  21. extern IPhysicsEnvironment *physenv;
  22. #ifdef PORTAL
  23. extern IPhysicsEnvironment *physenv_main;
  24. #endif
  25. extern IPhysicsSurfaceProps *physprops;
  26. extern IPhysicsObjectPairHash *g_EntityCollisionHash;
  27. extern const objectparams_t g_PhysDefaultObjectParams;
  28. // Compute enough energy of a reference mass travelling at speed
  29. // makes numbers more intuitive
  30. #define MASS_SPEED2ENERGY(mass, speed) ((speed)*(speed)*(mass))
  31. // energy of a 10kg mass moving at speed
  32. #define MASS10_SPEED2ENERGY(speed) MASS_SPEED2ENERGY(10,speed)
  33. #define MASS_ENERGY2SPEED(mass,energy) (FastSqrt((energy)/mass))
  34. #define ENERGY_VOLUME_SCALE (1.0f / 15500.0f)
  35. #define FLUID_TIME_MAX 2.0f // keep track of last time hitting fluid for up to 2 seconds
  36. // VPHYSICS object game-specific flags
  37. #define FVPHYSICS_DMG_SLICE 0x0001 // does slice damage, not just blunt damage
  38. #define FVPHYSICS_CONSTRAINT_STATIC 0x0002 // object is constrained to the world, so it should behave like a static
  39. #define FVPHYSICS_PLAYER_HELD 0x0004 // object is held by the player, so have a very inelastic collision response
  40. #define FVPHYSICS_PART_OF_RAGDOLL 0x0008 // object is part of a client or server ragdoll
  41. #define FVPHYSICS_MULTIOBJECT_ENTITY 0x0010 // object is part of a multi-object entity
  42. #define FVPHYSICS_HEAVY_OBJECT 0x0020 // HULK SMASH! (Do large damage even if the mass is small)
  43. #define FVPHYSICS_PENETRATING 0x0040 // This object is currently stuck inside another object
  44. #define FVPHYSICS_NO_PLAYER_PICKUP 0x0080 // Player can't pick this up for some game rule reason
  45. #define FVPHYSICS_WAS_THROWN 0x0100 // Player threw this object
  46. #define FVPHYSICS_DMG_DISSOLVE 0x0200 // does dissolve damage, not just blunt damage
  47. #define FVPHYSICS_NO_IMPACT_DMG 0x0400 // don't do impact damage to anything
  48. #define FVPHYSICS_NO_NPC_IMPACT_DMG 0x0800 // Don't do impact damage to NPC's. This is temporary for NPC's shooting combine balls (sjb)
  49. #define FVPHYSICS_PUSH_PLAYER 0x1000 // this is a shadow object that can push the player's physics
  50. #define FVPHYSICS_NO_SELF_COLLISIONS 0x8000 // don't collide with other objects that are part of the same entity
  51. //-----------------------------------------------------------------------------
  52. // Purpose: A little cache of current objects making noises
  53. //-----------------------------------------------------------------------------
  54. struct friction_t
  55. {
  56. CSoundPatch *patch;
  57. CBaseEntity *pObject;
  58. float flLastUpdateTime;
  59. float flLastEffectTime;
  60. };
  61. enum
  62. {
  63. TOUCH_START=0,
  64. TOUCH_END,
  65. };
  66. struct touchevent_t
  67. {
  68. CBaseEntity *pEntity0;
  69. CBaseEntity *pEntity1;
  70. int touchType;
  71. Vector endPoint; //sv
  72. Vector normal; //sv
  73. };
  74. struct fluidevent_t
  75. {
  76. EHANDLE hEntity;
  77. float impactTime;
  78. };
  79. void PhysFrictionSound( CBaseEntity *pEntity, IPhysicsObject *pObject, float energy, int surfaceProps, int surfacePropsHit );
  80. void PhysFrictionSound( CBaseEntity *pEntity, IPhysicsObject *pObject, const char *pSoundName, HSOUNDSCRIPTHASH& handle, float flVolume );
  81. void PhysCleanupFrictionSounds( CBaseEntity *pEntity );
  82. void PhysFrictionEffect( Vector &vecPos, Vector vecVel, float energy, int surfaceProps, int surfacePropsHit );
  83. float PhysGetEntityMass( CBaseEntity *pEntity );
  84. // Convenience routine
  85. // ORs gameFlags with the physics object's current game flags
  86. inline unsigned short PhysSetGameFlags( IPhysicsObject *pPhys, unsigned short gameFlags )
  87. {
  88. unsigned short flags = pPhys->GetGameFlags();
  89. flags |= gameFlags;
  90. pPhys->SetGameFlags( flags );
  91. return flags;
  92. }
  93. // mask off gameFlags
  94. inline unsigned short PhysClearGameFlags( IPhysicsObject *pPhys, unsigned short gameFlags )
  95. {
  96. unsigned short flags = pPhys->GetGameFlags();
  97. flags &= ~gameFlags;
  98. pPhys->SetGameFlags( flags );
  99. return flags;
  100. }
  101. // Create a vphysics object based on a model
  102. IPhysicsObject *PhysModelCreate( CBaseEntity *pEntity, int modelIndex, const Vector &origin, const QAngle &angles, solid_t *pSolid = NULL );
  103. IPhysicsObject *PhysModelCreateBox( CBaseEntity *pEntity, const Vector &mins, const Vector &maxs, const Vector &origin, bool isStatic );
  104. IPhysicsObject *PhysModelCreateOBB( CBaseEntity *pEntity, const Vector &mins, const Vector &maxs, const Vector &origin, const QAngle &angle, bool isStatic );
  105. // Create a vphysics object based on a BSP model (unmoveable)
  106. IPhysicsObject *PhysModelCreateUnmoveable( CBaseEntity *pEntity, int modelIndex, const Vector &origin, const QAngle &angles );
  107. // Create a vphysics object based on an existing collision model
  108. IPhysicsObject *PhysModelCreateCustom( CBaseEntity *pEntity, const CPhysCollide *pModel, const Vector &origin, const QAngle &angles, const char *pName, bool isStatic, solid_t *pSolid = NULL );
  109. // Create a bbox collision model (these may be shared among entities, they are auto-deleted at end of level. do not manage)
  110. CPhysCollide *PhysCreateBbox( const Vector &mins, const Vector &maxs );
  111. // Create a vphysics sphere object
  112. IPhysicsObject *PhysSphereCreate( CBaseEntity *pEntity, float radius, const Vector &origin, solid_t &solid );
  113. // Destroy a physics object created using PhysModelCreate...()
  114. void PhysDestroyObject( IPhysicsObject *pObject, CBaseEntity *pEntity = NULL );
  115. void PhysDisableObjectCollisions( IPhysicsObject *pObject0, IPhysicsObject *pObject1 );
  116. void PhysDisableEntityCollisions( IPhysicsObject *pObject0, IPhysicsObject *pObject1 );
  117. void PhysDisableEntityCollisions( CBaseEntity *pEntity0, CBaseEntity *pEntity1 );
  118. void PhysEnableObjectCollisions( IPhysicsObject *pObject0, IPhysicsObject *pObject1 );
  119. void PhysEnableEntityCollisions( IPhysicsObject *pObject0, IPhysicsObject *pObject1 );
  120. void PhysEnableEntityCollisions( CBaseEntity *pEntity0, CBaseEntity *pEntity1 );
  121. bool PhysEntityCollisionsAreDisabled( CBaseEntity *pEntity0, CBaseEntity *pEntity1 );
  122. // create the world physics objects
  123. IPhysicsObject *PhysCreateWorld_Shared( CBaseEntity *pWorld, vcollide_t *pWorldCollide, const objectparams_t &defaultParams );
  124. // parse the parameters for a single solid from the model's collision data
  125. bool PhysModelParseSolid( solid_t &solid, CBaseEntity *pEntity, int modelIndex );
  126. // parse the parameters for a solid matching a particular index
  127. bool PhysModelParseSolidByIndex( solid_t &solid, CBaseEntity *pEntity, int modelIndex, int solidIndex );
  128. void PhysParseSurfaceData( class IPhysicsSurfaceProps *pProps, class IFileSystem *pFileSystem );
  129. // fill out this solid_t with the AABB defaults (high inertia/no rotation)
  130. void PhysGetDefaultAABBSolid( solid_t &solid );
  131. // Compute an output velocity based on sliding along the current contact points
  132. // in the closest direction toward inputVelocity.
  133. void PhysComputeSlideDirection( IPhysicsObject *pPhysics, const Vector &inputVelocity, const AngularImpulse &inputAngularVelocity,
  134. Vector *pOutputVelocity, Vector *pOutputAngularVelocity, float minMass );
  135. void PhysForceClearVelocity( IPhysicsObject *pPhys );
  136. bool PhysHasContactWithOtherInDirection( IPhysicsObject *pPhysics, const Vector &dir );
  137. //-----------------------------------------------------------------------------
  138. // Singleton access
  139. //-----------------------------------------------------------------------------
  140. IGameSystem* PhysicsGameSystem();
  141. #endif // PHYSICS_SHARED_H