Team Fortress 2 Source Code as on 22/4/2020
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.

1064 lines
45 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Public interfaces to vphysics DLL
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef VPHYSICS_INTERFACE_V30_H
  8. #define VPHYSICS_INTERFACE_V30_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "interface.h"
  13. #include "mathlib/vector.h"
  14. #include "mathlib/vector4d.h"
  15. #include "vcollide.h"
  16. //-----------------------------------------------------------------------------
  17. // Forward declarations
  18. //-----------------------------------------------------------------------------
  19. class IPhysicsObjectPairHash;
  20. class IPhysicsConstraint;
  21. class IPhysicsConstraintGroup;
  22. class IPhysicsFluidController;
  23. class IPhysicsSpring;
  24. class IPhysicsVehicleController;
  25. class IPhysicsCollisionSet;
  26. class IPhysicsPlayerController;
  27. class IPhysicsFrictionSnapshot;
  28. struct Ray_t;
  29. struct constraint_ragdollparams_t;
  30. struct constraint_hingeparams_t;
  31. struct constraint_fixedparams_t;
  32. struct constraint_ballsocketparams_t;
  33. struct constraint_slidingparams_t;
  34. struct constraint_pulleyparams_t;
  35. struct constraint_lengthparams_t;
  36. struct constraint_groupparams_t;
  37. struct vehicleparams_t;
  38. struct matrix3x4_t;
  39. struct fluidparams_t;
  40. struct springparams_t;
  41. struct objectparams_t;
  42. struct debugcollide_t;
  43. class CGameTrace;
  44. typedef CGameTrace trace_t;
  45. struct physics_stats_t;
  46. struct physics_performanceparams_t;
  47. struct physsaveparams_t;
  48. struct physrestoreparams_t;
  49. struct physprerestoreparams_t;
  50. namespace VPhysicsInterfaceV30
  51. {
  52. //-----------------------------------------------------------------------------
  53. // Forward declarations
  54. //-----------------------------------------------------------------------------
  55. class IPhysicsObject;
  56. class IPhysicsEnvironment;
  57. class IPhysicsSurfaceProps;
  58. class IConvexInfo;
  59. enum PhysInterfaceId_t
  60. {
  61. PIID_UNKNOWN,
  62. PIID_IPHYSICSOBJECT,
  63. PIID_IPHYSICSFLUIDCONTROLLER,
  64. PIID_IPHYSICSSPRING,
  65. PIID_IPHYSICSCONSTRAINTGROUP,
  66. PIID_IPHYSICSCONSTRAINT,
  67. PIID_IPHYSICSSHADOWCONTROLLER,
  68. PIID_IPHYSICSPLAYERCONTROLLER,
  69. PIID_IPHYSICSMOTIONCONTROLLER,
  70. PIID_IPHYSICSVEHICLECONTROLLER,
  71. PIID_IPHYSICSGAMETRACE,
  72. PIID_NUM_TYPES
  73. };
  74. class ISave;
  75. class IRestore;
  76. #define VPHYSICS_DEBUG_OVERLAY_INTERFACE_VERSION_1 "VPhysicsDebugOverlay001"
  77. abstract_class IVPhysicsDebugOverlay
  78. {
  79. public:
  80. virtual void AddEntityTextOverlay(int ent_index, int line_offset, float duration, int r, int g, int b, int a, PRINTF_FORMAT_STRING const char *format, ...) = 0;
  81. virtual void AddBoxOverlay(const Vector& origin, const Vector& mins, const Vector& max, QAngle const& orientation, int r, int g, int b, int a, float duration) = 0;
  82. virtual void AddTriangleOverlay(const Vector& p1, const Vector& p2, const Vector& p3, int r, int g, int b, int a, bool noDepthTest, float duration) = 0;
  83. virtual void AddLineOverlay(const Vector& origin, const Vector& dest, int r, int g, int b,bool noDepthTest, float duration) = 0;
  84. virtual void AddTextOverlay(const Vector& origin, float duration, PRINTF_FORMAT_STRING const char *format, ...) = 0;
  85. virtual void AddTextOverlay(const Vector& origin, int line_offset, float duration, PRINTF_FORMAT_STRING const char *format, ...) = 0;
  86. virtual void AddScreenTextOverlay(float flXPos, float flYPos,float flDuration, int r, int g, int b, int a, const char *text) = 0;
  87. virtual void AddSweptBoxOverlay(const Vector& start, const Vector& end, const Vector& mins, const Vector& max, const QAngle & angles, int r, int g, int b, int a, float flDuration) = 0;
  88. virtual void AddTextOverlayRGB(const Vector& origin, int line_offset, float duration, float r, float g, float b, float alpha, PRINTF_FORMAT_STRING const char *format, ...) = 0;
  89. };
  90. #define VPHYSICS_INTERFACE_VERSION_30 "VPhysics030"
  91. abstract_class IPhysics
  92. {
  93. public:
  94. virtual IPhysicsEnvironment *CreateEnvironment( void ) = 0;
  95. virtual void DestroyEnvironment( IPhysicsEnvironment * ) = 0;
  96. virtual IPhysicsEnvironment *GetActiveEnvironmentByIndex( int index ) = 0;
  97. // Creates a fast hash of pairs of objects
  98. // Useful for maintaining a table of object relationships like pairs that do not collide.
  99. virtual IPhysicsObjectPairHash *CreateObjectPairHash() = 0;
  100. virtual void DestroyObjectPairHash( IPhysicsObjectPairHash *pHash ) = 0;
  101. // holds a cache of these by id. So you can get by id to search for the previously created set
  102. // UNDONE: Sets are currently limited to 32 elements. More elements will return NULL in create.
  103. // NOTE: id is not allowed to be zero.
  104. virtual IPhysicsCollisionSet *FindOrCreateCollisionSet( unsigned int id, int maxElementCount ) = 0;
  105. virtual IPhysicsCollisionSet *FindCollisionSet( unsigned int id ) = 0;
  106. virtual void DestroyAllCollisionSets() = 0;
  107. };
  108. // CPhysConvex is a single convex solid
  109. class CPhysConvex;
  110. // CPhysPolysoup is an abstract triangle soup mesh
  111. class CPhysPolysoup;
  112. class ICollisionQuery;
  113. class IVPhysicsKeyParser;
  114. struct convertconvexparams_t;
  115. // UNDONE: Find a better place for this? Should be in collisionutils, but it's needs VPHYSICS' solver.
  116. struct truncatedcone_t
  117. {
  118. Vector origin;
  119. Vector normal;
  120. float h; // height of the cone (hl units)
  121. float theta; // cone angle (degrees)
  122. };
  123. #define VPHYSICS_COLLISION_INTERFACE_VERSION_7 "VPhysicsCollision007"
  124. abstract_class IPhysicsCollision
  125. {
  126. public:
  127. virtual ~IPhysicsCollision( void ) {}
  128. // produce a convex element from verts (convex hull around verts)
  129. virtual CPhysConvex *ConvexFromVerts( Vector **pVerts, int vertCount ) = 0;
  130. // produce a convex element from planes (csg of planes)
  131. virtual CPhysConvex *ConvexFromPlanes( float *pPlanes, int planeCount, float mergeDistance ) = 0;
  132. // calculate volume of a convex element
  133. virtual float ConvexVolume( CPhysConvex *pConvex ) = 0;
  134. // Convert an array of convex elements to a compiled collision model (this deletes the convex elements)
  135. virtual CPhysCollide *ConvertConvexToCollide( CPhysConvex **pConvex, int convexCount ) = 0;
  136. virtual float ConvexSurfaceArea( CPhysConvex *pConvex ) = 0;
  137. // store game-specific data in a convex solid
  138. virtual void SetConvexGameData( CPhysConvex *pConvex, unsigned int gameData ) = 0;
  139. // If not converted, free the convex elements with this call
  140. virtual void ConvexFree( CPhysConvex *pConvex ) = 0;
  141. // concave objects
  142. // create a triangle soup
  143. virtual CPhysPolysoup *PolysoupCreate( void ) = 0;
  144. // destroy the container and memory
  145. virtual void PolysoupDestroy( CPhysPolysoup *pSoup ) = 0;
  146. // add a triangle to the soup
  147. virtual void PolysoupAddTriangle( CPhysPolysoup *pSoup, const Vector &a, const Vector &b, const Vector &c, int materialIndex7bits ) = 0;
  148. // convert the convex into a compiled collision model
  149. virtual CPhysCollide *ConvertPolysoupToCollide( CPhysPolysoup *pSoup, bool useMOPP ) = 0;
  150. // Get the memory size in bytes of the collision model for serialization
  151. virtual int CollideSize( CPhysCollide *pCollide ) = 0;
  152. // serialize the collide to a block of memory
  153. virtual int CollideWrite( char *pDest, CPhysCollide *pCollide ) = 0;
  154. // Free a collide that was created with ConvertConvexToCollide()
  155. // UNDONE: Move this up near the other Collide routines when the version is changed
  156. virtual void DestroyCollide( CPhysCollide *pCollide ) = 0;
  157. // compute the volume of a collide
  158. virtual float CollideVolume( CPhysCollide *pCollide ) = 0;
  159. // compute surface area for tools
  160. virtual float CollideSurfaceArea( CPhysCollide *pCollide ) = 0;
  161. // Get the support map for a collide in the given direction
  162. virtual Vector CollideGetExtent( const CPhysCollide *pCollide, const Vector &collideOrigin, const QAngle &collideAngles, const Vector &direction ) = 0;
  163. // Get an AABB for an oriented collision model
  164. virtual void CollideGetAABB( Vector &mins, Vector &maxs, const CPhysCollide *pCollide, const Vector &collideOrigin, const QAngle &collideAngles ) = 0;
  165. // Convert a bbox to a collide
  166. virtual CPhysCollide *BBoxToCollide( const Vector &mins, const Vector &maxs ) = 0;
  167. // Trace an AABB against a collide
  168. virtual void TraceBox( const Vector &start, const Vector &end, const Vector &mins, const Vector &maxs, const CPhysCollide *pCollide, const Vector &collideOrigin, const QAngle &collideAngles, trace_t *ptr ) = 0;
  169. virtual void TraceBox( const Ray_t &ray, const CPhysCollide *pCollide, const Vector &collideOrigin, const QAngle &collideAngles, trace_t *ptr ) = 0;
  170. // Trace one collide against another
  171. virtual void TraceCollide( const Vector &start, const Vector &end, const CPhysCollide *pSweepCollide, const QAngle &sweepAngles, const CPhysCollide *pCollide, const Vector &collideOrigin, const QAngle &collideAngles, trace_t *ptr ) = 0;
  172. // loads a set of solids into a vcollide_t
  173. virtual void VCollideLoad( vcollide_t *pOutput, int solidCount, const char *pBuffer, int size ) = 0;
  174. // destroyts the set of solids created by VCollideLoad
  175. virtual void VCollideUnload( vcollide_t *pVCollide ) = 0;
  176. // begins parsing a vcollide. NOTE: This keeps pointers to the text
  177. // If you free the text and call members of IVPhysicsKeyParser, it will crash
  178. virtual IVPhysicsKeyParser *VPhysicsKeyParserCreate( const char *pKeyData ) = 0;
  179. // Free the parser created by VPhysicsKeyParserCreate
  180. virtual void VPhysicsKeyParserDestroy( IVPhysicsKeyParser *pParser ) = 0;
  181. // creates a list of verts from a collision mesh
  182. virtual int CreateDebugMesh( CPhysCollide const *pCollisionModel, Vector **outVerts ) = 0;
  183. // destroy the list of verts created by CreateDebugMesh
  184. virtual void DestroyDebugMesh( int vertCount, Vector *outVerts ) = 0;
  185. // create a queryable version of the collision model
  186. virtual ICollisionQuery *CreateQueryModel( CPhysCollide *pCollide ) = 0;
  187. // destroy the queryable version
  188. virtual void DestroyQueryModel( ICollisionQuery *pQuery ) = 0;
  189. virtual IPhysicsCollision *ThreadContextCreate( void ) = 0;
  190. virtual void ThreadContextDestroy( IPhysicsCollision *pThreadContex ) = 0;
  191. virtual unsigned int ReadStat( int statID ) = 0;
  192. // UNDONE: Move this up when changing the interface version
  193. virtual void TraceBox( const Ray_t &ray, unsigned int contentsMask, IConvexInfo *pConvexInfo, const CPhysCollide *pCollide, const Vector &collideOrigin, const QAngle &collideAngles, trace_t *ptr ) = 0;
  194. virtual void CollideGetMassCenter( CPhysCollide *pCollide, Vector *pOutMassCenter ) = 0;
  195. virtual void CollideSetMassCenter( CPhysCollide *pCollide, const Vector &massCenter ) = 0;
  196. // query the collide index in the physics model for the instance
  197. virtual int CollideIndex( const CPhysCollide *pCollide ) = 0;
  198. virtual CPhysCollide *ConvertConvexToCollideParams( CPhysConvex **pConvex, int convexCount, const convertconvexparams_t &convertParams ) = 0;
  199. virtual CPhysConvex *BBoxToConvex( const Vector &mins, const Vector &maxs ) = 0;
  200. // get the approximate cross-sectional area projected orthographically on the bbox of the collide
  201. // NOTE: These are fractional areas - unitless. Basically this is the fraction of the OBB on each axis that
  202. // would be visible if the object were rendered orthographically.
  203. // NOTE: This has been precomputed when the collide was built or this function will return 1,1,1
  204. virtual Vector CollideGetOrthographicAreas( const CPhysCollide *pCollide ) = 0;
  205. // dumps info about the collide to Msg()
  206. virtual void OutputDebugInfo( const CPhysCollide *pCollide ) = 0;
  207. // relatively slow test for box vs. truncated cone
  208. virtual bool IsBoxIntersectingCone( const Vector &boxAbsMins, const Vector &boxAbsMaxs, const truncatedcone_t &cone ) = 0;
  209. };
  210. // this can be used to post-process a collision model
  211. abstract_class ICollisionQuery
  212. {
  213. public:
  214. virtual ~ICollisionQuery() {}
  215. // number of convex pieces in the whole solid
  216. virtual int ConvexCount( void ) = 0;
  217. // triangle count for this convex piece
  218. virtual int TriangleCount( int convexIndex ) = 0;
  219. // get the stored game data
  220. virtual unsigned int GetGameData( int convexIndex ) = 0;
  221. // Gets the triangle's verts to an array
  222. virtual void GetTriangleVerts( int convexIndex, int triangleIndex, Vector *verts ) = 0;
  223. // UNDONE: This doesn't work!!!
  224. virtual void SetTriangleVerts( int convexIndex, int triangleIndex, const Vector *verts ) = 0;
  225. // returns the 7-bit material index
  226. virtual int GetTriangleMaterialIndex( int convexIndex, int triangleIndex ) = 0;
  227. // sets a 7-bit material index for this triangle
  228. virtual void SetTriangleMaterialIndex( int convexIndex, int triangleIndex, int index7bits ) = 0;
  229. };
  230. //-----------------------------------------------------------------------------
  231. // Purpose: Ray traces from game engine.
  232. //-----------------------------------------------------------------------------
  233. abstract_class IPhysicsGameTrace
  234. {
  235. public:
  236. virtual void VehicleTraceRay( const Ray_t &ray, void *pVehicle, trace_t *pTrace ) = 0;
  237. virtual void VehicleTraceRayWithWater( const Ray_t &ray, void *pVehicle, trace_t *pTrace ) = 0;
  238. virtual bool VehiclePointInWater( const Vector &vecPoint ) = 0;
  239. };
  240. // The caller should implement this to return contents masks per convex on a collide
  241. abstract_class IConvexInfo
  242. {
  243. public:
  244. virtual unsigned int GetContents( int convexGameData ) = 0;
  245. };
  246. class CPhysicsEventHandler;
  247. abstract_class IPhysicsCollisionData
  248. {
  249. public:
  250. virtual void GetSurfaceNormal( Vector &out ) = 0; // normal points toward second object (object index 1)
  251. virtual void GetContactPoint( Vector &out ) = 0; // contact point of collision (in world space)
  252. virtual void GetContactSpeed( Vector &out ) = 0; // speed of surface 1 relative to surface 0 (in world space)
  253. };
  254. struct vcollisionevent_t
  255. {
  256. IPhysicsObject *pObjects[2];
  257. int surfaceProps[2];
  258. bool isCollision;
  259. bool isShadowCollision;
  260. float deltaCollisionTime;
  261. float collisionSpeed; // only valid at postCollision
  262. IPhysicsCollisionData *pInternalData; // may change pre/post collision
  263. };
  264. abstract_class IPhysicsCollisionEvent
  265. {
  266. public:
  267. // returns the two objects that collided, time between last collision of these objects
  268. // and an opaque data block of collision information
  269. // NOTE: PreCollision/PostCollision ALWAYS come in matched pairs!!!
  270. virtual void PreCollision( vcollisionevent_t *pEvent ) = 0;
  271. virtual void PostCollision( vcollisionevent_t *pEvent ) = 0;
  272. // This is a scrape event. The object has scraped across another object consuming the indicated energy
  273. virtual void Friction( IPhysicsObject *pObject, float energy, int surfaceProps, int surfacePropsHit, IPhysicsCollisionData *pData ) = 0;
  274. virtual void StartTouch( IPhysicsObject *pObject1, IPhysicsObject *pObject2, IPhysicsCollisionData *pTouchData ) = 0;
  275. virtual void EndTouch( IPhysicsObject *pObject1, IPhysicsObject *pObject2, IPhysicsCollisionData *pTouchData ) = 0;
  276. virtual void FluidStartTouch( IPhysicsObject *pObject, IPhysicsFluidController *pFluid ) = 0;
  277. virtual void FluidEndTouch( IPhysicsObject *pObject, IPhysicsFluidController *pFluid ) = 0;
  278. virtual void PostSimulationFrame() = 0;
  279. virtual void ObjectEnterTrigger( IPhysicsObject *pTrigger, IPhysicsObject *pObject ) {}
  280. virtual void ObjectLeaveTrigger( IPhysicsObject *pTrigger, IPhysicsObject *pObject ) {}
  281. };
  282. abstract_class IPhysicsObjectEvent
  283. {
  284. public:
  285. // these can be used to optimize out queries on sleeping objects
  286. // Called when an object is woken after sleeping
  287. virtual void ObjectWake( IPhysicsObject *pObject ) = 0;
  288. // called when an object goes to sleep (no longer simulating)
  289. virtual void ObjectSleep( IPhysicsObject *pObject ) = 0;
  290. };
  291. class IPhysicsConstraintEvent
  292. {
  293. public:
  294. // the constraint is now inactive, the game code is required to delete it or re-activate it.
  295. virtual void ConstraintBroken( IPhysicsConstraint * ) = 0;
  296. };
  297. struct hlshadowcontrol_params_t
  298. {
  299. Vector targetPosition;
  300. QAngle targetRotation;
  301. float maxAngular;
  302. float maxDampAngular;
  303. float maxSpeed;
  304. float maxDampSpeed;
  305. float dampFactor;
  306. float teleportDistance;
  307. };
  308. // UNDONE: At some point allow this to be parameterized using hlshadowcontrol_params_t.
  309. // All of the infrastructure is in place to do that.
  310. abstract_class IPhysicsShadowController
  311. {
  312. public:
  313. virtual ~IPhysicsShadowController( void ) {}
  314. virtual void Update( const Vector &position, const QAngle &angles, float timeOffset ) = 0;
  315. virtual void MaxSpeed( float maxSpeed, float maxAngularSpeed ) = 0;
  316. virtual void StepUp( float height ) = 0;
  317. // If the teleport distance is non-zero, the object will be teleported to
  318. // the target location when the error exceeds this quantity.
  319. virtual void SetTeleportDistance( float teleportDistance ) = 0;
  320. virtual bool AllowsTranslation() = 0;
  321. virtual bool AllowsRotation() = 0;
  322. // There are two classes of shadow objects:
  323. // 1) Game physics controlled, shadow follows game physics (this is the default)
  324. // 2) Physically controlled - shadow position is a target, but the game hasn't guaranteed that the space can be occupied by this object
  325. virtual void SetPhysicallyControlled( bool isPhysicallyControlled ) = 0;
  326. virtual bool IsPhysicallyControlled() = 0;
  327. virtual void GetLastImpulse( Vector *pOut ) = 0;
  328. virtual void UseShadowMaterial( bool bUseShadowMaterial ) = 0;
  329. virtual void ObjectMaterialChanged( int materialIndex ) = 0;
  330. };
  331. class CPhysicsSimObject;
  332. class IPhysicsMotionController;
  333. // Callback for simulation
  334. class IMotionEvent
  335. {
  336. public:
  337. // These constants instruct the simulator as to how to apply the values copied to linear & angular
  338. // GLOBAL/LOCAL refer to the coordinate system of the values, whereas acceleration/force determine whether or not
  339. // mass is divided out (forces must be divided by mass to compute acceleration)
  340. enum simresult_e { SIM_NOTHING = 0, SIM_LOCAL_ACCELERATION, SIM_LOCAL_FORCE, SIM_GLOBAL_ACCELERATION, SIM_GLOBAL_FORCE };
  341. virtual simresult_e Simulate( IPhysicsMotionController *pController, IPhysicsObject *pObject, float deltaTime, Vector &linear, AngularImpulse &angular ) = 0;
  342. };
  343. abstract_class IPhysicsMotionController
  344. {
  345. public:
  346. virtual ~IPhysicsMotionController( void ) {}
  347. virtual void SetEventHandler( IMotionEvent *handler ) = 0;
  348. virtual void AttachObject( IPhysicsObject *pObject, bool checkIfAlreadyAttached ) = 0;
  349. virtual void DetachObject( IPhysicsObject *pObject ) = 0;
  350. // returns the number of objects currently attached to the controller
  351. virtual int CountObjects( void ) = 0;
  352. // NOTE: pObjectList is an array with at least CountObjects() allocated
  353. virtual void GetObjects( IPhysicsObject **pObjectList ) = 0;
  354. // detaches all attached objects
  355. virtual void ClearObjects( void ) = 0;
  356. // wakes up all attached objects
  357. virtual void WakeObjects( void ) = 0;
  358. enum priority_t
  359. {
  360. LOW_PRIORITY = 0,
  361. MEDIUM_PRIORITY = 1,
  362. HIGH_PRIORITY = 2,
  363. };
  364. virtual void SetPriority( priority_t priority ) = 0;
  365. };
  366. // -------------------
  367. // Collision filter function. Return 0 if objects should not be tested for collisions, nonzero otherwise
  368. // Install with IPhysicsEnvironment::SetCollisionFilter()
  369. // -------------------
  370. abstract_class IPhysicsCollisionSolver
  371. {
  372. public:
  373. virtual int ShouldCollide( IPhysicsObject *pObj0, IPhysicsObject *pObj1, void *pGameData0, void *pGameData1 ) = 0;
  374. virtual int ShouldSolvePenetration( IPhysicsObject *pObj0, IPhysicsObject *pObj1, void *pGameData0, void *pGameData1, float dt ) = 0;
  375. // pObject has already done the max number of collisions this tick, should we freeze it to save CPU?
  376. virtual bool ShouldFreezeObject( IPhysicsObject *pObject ) = 0;
  377. // The system has already done too many collision checks, performance will suffer.
  378. // How many more should it do?
  379. virtual int AdditionalCollisionChecksThisTick( int currentChecksDone ) = 0;
  380. };
  381. enum PhysicsTraceType_t
  382. {
  383. VPHYSICS_TRACE_EVERYTHING = 0,
  384. VPHYSICS_TRACE_STATIC_ONLY,
  385. VPHYSICS_TRACE_MOVING_ONLY,
  386. VPHYSICS_TRACE_TRIGGERS_ONLY,
  387. VPHYSICS_TRACE_STATIC_AND_MOVING,
  388. };
  389. abstract_class IPhysicsTraceFilter
  390. {
  391. public:
  392. virtual bool ShouldHitObject( IPhysicsObject *pObject, int contentsMask ) = 0;
  393. virtual PhysicsTraceType_t GetTraceType() const = 0;
  394. };
  395. abstract_class IPhysicsEnvironment
  396. {
  397. public:
  398. virtual ~IPhysicsEnvironment( void ) {}
  399. virtual void SetDebugOverlay( CreateInterfaceFn debugOverlayFactory ) = 0;
  400. virtual IVPhysicsDebugOverlay *GetDebugOverlay( void ) = 0;
  401. // gravity is a 3-vector in in/s^2
  402. virtual void SetGravity( const Vector &gravityVector ) = 0;
  403. virtual void GetGravity( Vector &gravityVector ) = 0;
  404. // air density is in kg / m^3 (water is 1000)
  405. // This controls drag, air that is more dense has more drag.
  406. virtual void SetAirDensity( float density ) = 0;
  407. virtual float GetAirDensity( void ) = 0;
  408. // object creation
  409. // create a polygonal object. pCollisionModel was created by the physics builder DLL in a pre-process.
  410. virtual IPhysicsObject *CreatePolyObject( const CPhysCollide *pCollisionModel, int materialIndex, const Vector &position, const QAngle &angles, objectparams_t *pParams ) = 0;
  411. // same as above, but this one cannot move or rotate (infinite mass/inertia)
  412. virtual IPhysicsObject *CreatePolyObjectStatic( const CPhysCollide *pCollisionModel, int materialIndex, const Vector &position, const QAngle &angles, objectparams_t *pParams ) = 0;
  413. // Create a perfectly spherical object
  414. virtual IPhysicsObject *CreateSphereObject( float radius, int materialIndex, const Vector &position, const QAngle &angles, objectparams_t *pParams, bool isStatic ) = 0;
  415. // Create a polygonal fluid body out of the specified collision model
  416. // This object will affect any other objects that collide with the collision model
  417. virtual IPhysicsFluidController *CreateFluidController( IPhysicsObject *pFluidObject, fluidparams_t *pParams ) = 0;
  418. // Create a simulated spring that connects 2 objects
  419. virtual IPhysicsSpring *CreateSpring( IPhysicsObject *pObjectStart, IPhysicsObject *pObjectEnd, springparams_t *pParams ) = 0;
  420. // Create a constraint in the space of pReferenceObject which is attached by the constraint to pAttachedObject
  421. virtual IPhysicsConstraint *CreateRagdollConstraint( IPhysicsObject *pReferenceObject, IPhysicsObject *pAttachedObject, IPhysicsConstraintGroup *pGroup, const constraint_ragdollparams_t &ragdoll ) = 0;
  422. virtual IPhysicsConstraint *CreateHingeConstraint( IPhysicsObject *pReferenceObject, IPhysicsObject *pAttachedObject, IPhysicsConstraintGroup *pGroup, const constraint_hingeparams_t &hinge ) = 0;
  423. virtual IPhysicsConstraint *CreateFixedConstraint( IPhysicsObject *pReferenceObject, IPhysicsObject *pAttachedObject, IPhysicsConstraintGroup *pGroup, const constraint_fixedparams_t &fixed ) = 0;
  424. virtual IPhysicsConstraint *CreateSlidingConstraint( IPhysicsObject *pReferenceObject, IPhysicsObject *pAttachedObject, IPhysicsConstraintGroup *pGroup, const constraint_slidingparams_t &sliding ) = 0;
  425. virtual IPhysicsConstraint *CreateBallsocketConstraint( IPhysicsObject *pReferenceObject, IPhysicsObject *pAttachedObject, IPhysicsConstraintGroup *pGroup, const constraint_ballsocketparams_t &ballsocket ) = 0;
  426. virtual IPhysicsConstraint *CreatePulleyConstraint( IPhysicsObject *pReferenceObject, IPhysicsObject *pAttachedObject, IPhysicsConstraintGroup *pGroup, const constraint_pulleyparams_t &pulley ) = 0;
  427. virtual IPhysicsConstraint *CreateLengthConstraint( IPhysicsObject *pReferenceObject, IPhysicsObject *pAttachedObject, IPhysicsConstraintGroup *pGroup, const constraint_lengthparams_t &length ) = 0;
  428. virtual IPhysicsConstraintGroup *CreateConstraintGroup( const constraint_groupparams_t &groupParams ) = 0;
  429. // destroy an object created with CreatePolyObject() or CreatePolyObjectStatic()
  430. virtual void DestroyObject( IPhysicsObject * ) = 0;
  431. virtual void DestroySpring( IPhysicsSpring * ) = 0;
  432. // Destroy an object created with CreateFluidController()
  433. virtual void DestroyFluidController( IPhysicsFluidController * ) = 0;
  434. virtual void DestroyConstraint( IPhysicsConstraint * ) = 0;
  435. virtual void DestroyConstraintGroup( IPhysicsConstraintGroup *pGroup ) = 0;
  436. // install a function to filter collisions/penentration
  437. virtual void SetCollisionSolver( IPhysicsCollisionSolver *pSolver ) = 0;
  438. // run the simulator for deltaTime seconds
  439. virtual void Simulate( float deltaTime ) = 0;
  440. // true if currently running the simulator (i.e. in a callback during physenv->Simulate())
  441. virtual bool IsInSimulation( void ) const = 0;
  442. // Manage the timestep (period) of the simulator. The main functions are all integrated with
  443. // this period as dt.
  444. virtual float GetSimulationTimestep( void ) = 0;
  445. virtual void SetSimulationTimestep( float timestep ) = 0;
  446. // returns the current simulation clock's value. This is an absolute time.
  447. virtual float GetSimulationTime( void ) = 0;
  448. virtual void ResetSimulationClock( void ) = 0;
  449. // Collision callbacks (game code collision response)
  450. virtual void SetCollisionEventHandler( IPhysicsCollisionEvent *pCollisionEvents ) = 0;
  451. virtual void SetObjectEventHandler( IPhysicsObjectEvent *pObjectEvents ) = 0;
  452. virtual void SetConstraintEventHandler( IPhysicsConstraintEvent *pConstraintEvents ) = 0;
  453. virtual IPhysicsShadowController *CreateShadowController( IPhysicsObject *pObject, bool allowTranslation, bool allowRotation ) = 0;
  454. virtual void DestroyShadowController( IPhysicsShadowController * ) = 0;
  455. virtual IPhysicsPlayerController *CreatePlayerController( IPhysicsObject *pObject ) = 0;
  456. virtual void DestroyPlayerController( IPhysicsPlayerController * ) = 0;
  457. virtual IPhysicsMotionController *CreateMotionController( IMotionEvent *pHandler ) = 0;
  458. virtual void DestroyMotionController( IPhysicsMotionController *pController ) = 0;
  459. virtual IPhysicsVehicleController *CreateVehicleController( IPhysicsObject *pVehicleBodyObject, const vehicleparams_t &params, unsigned int nVehicleType, IPhysicsGameTrace *pGameTrace ) = 0;
  460. virtual void DestroyVehicleController( IPhysicsVehicleController * ) = 0;
  461. virtual void SetQuickDelete( bool bQuick ) = 0;
  462. virtual int GetActiveObjectCount( void ) = 0;
  463. virtual void GetActiveObjects( IPhysicsObject **pOutputObjectList ) = 0;
  464. virtual void CleanupDeleteList( void ) = 0;
  465. virtual void EnableDeleteQueue( bool enable ) = 0;
  466. // Save/Restore methods
  467. virtual bool Save( const physsaveparams_t &params ) = 0;
  468. virtual void PreRestore( const physprerestoreparams_t &params ) = 0;
  469. virtual bool Restore( const physrestoreparams_t &params ) = 0;
  470. virtual void PostRestore() = 0;
  471. // Debugging:
  472. virtual bool IsCollisionModelUsed( CPhysCollide *pCollide ) = 0;
  473. // Physics world version of the enginetrace API:
  474. virtual void TraceRay( const Ray_t &ray, unsigned int fMask, IPhysicsTraceFilter *pTraceFilter, trace_t *pTrace ) = 0;
  475. virtual void SweepCollideable( const CPhysCollide *pCollide, const Vector &vecAbsStart, const Vector &vecAbsEnd,
  476. const QAngle &vecAngles, unsigned int fMask, IPhysicsTraceFilter *pTraceFilter, trace_t *pTrace ) = 0;
  477. // performance tuning
  478. virtual void GetPerformanceSettings( physics_performanceparams_t *pOutput ) = 0;
  479. virtual void SetPerformanceSettings( const physics_performanceparams_t *pSettings ) = 0;
  480. // perf/cost statistics
  481. virtual void ReadStats( physics_stats_t *pOutput ) = 0;
  482. virtual void ClearStats() = 0;
  483. };
  484. enum callbackflags
  485. {
  486. CALLBACK_GLOBAL_COLLISION = 0x0001,
  487. CALLBACK_GLOBAL_FRICTION = 0x0002,
  488. CALLBACK_GLOBAL_TOUCH = 0x0004,
  489. CALLBACK_GLOBAL_TOUCH_STATIC = 0x0008,
  490. CALLBACK_SHADOW_COLLISION = 0x0010,
  491. CALLBACK_GLOBAL_COLLIDE_STATIC = 0x0020,
  492. CALLBACK_IS_VEHICLE_WHEEL = 0x0040,
  493. CALLBACK_FLUID_TOUCH = 0x0100,
  494. CALLBACK_NEVER_DELETED = 0x0200, // HACKHACK: This means this object will never be deleted (set on the world)
  495. CALLBACK_MARKED_FOR_DELETE = 0x0400, // This allows vphysics to skip some work for this object since it will be
  496. // deleted later this frame. (Set automatically by destroy calls)
  497. CALLBACK_ENABLING_COLLISION = 0x0800, // This is active during the time an object is enabling collisions
  498. // allows us to skip collisions between "new" objects and objects marked for delete
  499. CALLBACK_DO_FLUID_SIMULATION = 0x1000, // remove this to opt out of fluid simulations
  500. CALLBACK_IS_PLAYER_CONTROLLER= 0x2000, // HACKHACK: Set this on players until player cotrollers are unified with shadow controllers
  501. CALLBACK_CHECK_COLLISION_DISABLE = 0x4000,
  502. CALLBACK_MARKED_FOR_TEST = 0x8000, // debug -- marked object is being debugged
  503. };
  504. abstract_class IPhysicsObject
  505. {
  506. public:
  507. virtual ~IPhysicsObject( void ) {}
  508. // returns true if this object is static/unmoveable
  509. // NOTE: returns false for objects that are not created static, but set EnableMotion(false);
  510. // Call IsMoveable() to find if the object is static OR has motion disabled
  511. virtual bool IsStatic( void ) = 0;
  512. // "wakes up" an object
  513. // NOTE: ALL OBJECTS ARE "Asleep" WHEN CREATED
  514. virtual void Wake( void ) = 0;
  515. virtual void Sleep( void ) = 0;
  516. virtual bool IsAsleep( void ) = 0;
  517. // Game can store data in each object (link back to game object)
  518. virtual void SetGameData( void *pGameData ) = 0;
  519. virtual void *GetGameData( void ) const = 0;
  520. // This flags word can be defined by the game as well
  521. virtual void SetGameFlags( unsigned short userFlags ) = 0;
  522. virtual unsigned short GetGameFlags( void ) const = 0;
  523. virtual void SetGameIndex( unsigned short gameIndex ) = 0;
  524. virtual unsigned short GetGameIndex( void ) const = 0;
  525. // setup various callbacks for this object
  526. virtual void SetCallbackFlags( unsigned short callbackflags ) = 0;
  527. // get the current callback state for this object
  528. virtual unsigned short GetCallbackFlags( void ) = 0;
  529. // mass accessors
  530. virtual void SetMass( float mass ) = 0;
  531. virtual float GetMass( void ) const = 0;
  532. // get 1/mass (it's cached)
  533. virtual float GetInvMass( void ) const = 0;
  534. virtual Vector GetInertia( void ) const = 0;
  535. virtual Vector GetInvInertia( void ) const = 0;
  536. virtual void SetInertia( const Vector &inertia ) = 0;
  537. virtual void SetDamping( const float *speed, const float *rot ) = 0;
  538. virtual void GetDamping( float *speed, float *rot ) = 0;
  539. // material index
  540. virtual int GetMaterialIndex() const = 0;
  541. virtual void SetMaterialIndex( int materialIndex ) = 0;
  542. // Enable / disable collisions for this object
  543. virtual void EnableCollisions( bool enable ) = 0;
  544. // Enable / disable gravity for this object
  545. virtual void EnableGravity( bool enable ) = 0;
  546. // Enable / disable air friction / drag for this object
  547. virtual void EnableDrag( bool enable ) = 0;
  548. // Enable / disable motion (pin / unpin the object)
  549. virtual void EnableMotion( bool enable ) = 0;
  550. // call this when the collision filter conditions change due to this
  551. // object's state (e.g. changing solid type or collision group)
  552. virtual void RecheckCollisionFilter() = 0;
  553. // NOTE: These are here for convenience, but you can do them yourself by using the matrix
  554. // returned from GetPositionMatrix()
  555. // convenient coordinate system transformations (params - dest, src)
  556. virtual void LocalToWorld( Vector *worldPosition, const Vector &localPosition ) = 0;
  557. virtual void WorldToLocal( Vector *localPosition, const Vector &worldPosition ) = 0;
  558. // transforms a vector (no translation) from object-local to world space
  559. virtual void LocalToWorldVector( Vector *worldVector, const Vector &localVector ) = 0;
  560. // transforms a vector (no translation) from world to object-local space
  561. virtual void WorldToLocalVector( Vector *localVector, const Vector &worldVector ) = 0;
  562. // push on an object
  563. // force vector is direction & magnitude of impulse kg in / s
  564. virtual void ApplyForceCenter( const Vector &forceVector ) = 0;
  565. virtual void ApplyForceOffset( const Vector &forceVector, const Vector &worldPosition ) = 0;
  566. // Calculates the force/torque on the center of mass for an offset force impulse (pass output to ApplyForceCenter / ApplyTorqueCenter)
  567. virtual void CalculateForceOffset( const Vector &forceVector, const Vector &worldPosition, Vector *centerForce, AngularImpulse *centerTorque ) = 0;
  568. // Calculates the linear/angular velocities on the center of mass for an offset force impulse (pass output to AddVelocity)
  569. virtual void CalculateVelocityOffset( const Vector &forceVector, const Vector &worldPosition, Vector *centerVelocity, AngularImpulse *centerAngularVelocity ) = 0;
  570. // apply torque impulse. This will change the angular velocity on the object.
  571. // HL Axes, kg degrees / s
  572. virtual void ApplyTorqueCenter( const AngularImpulse &torque ) = 0;
  573. // NOTE: This will teleport the object
  574. virtual void SetPosition( const Vector &worldPosition, const QAngle &angles, bool isTeleport ) = 0;
  575. virtual void SetPositionMatrix( const matrix3x4_t&matrix, bool isTeleport ) = 0;
  576. virtual void GetPosition( Vector *worldPosition, QAngle *angles ) = 0;
  577. virtual void GetPositionMatrix( matrix3x4_t *positionMatrix ) = 0;
  578. // force the velocity to a new value
  579. // NOTE: velocity is in worldspace, angularVelocity is relative to the object's
  580. // local axes (just like pev->velocity, pev->avelocity)
  581. virtual void SetVelocity( const Vector *velocity, const AngularImpulse *angularVelocity ) = 0;
  582. // like the above, but force the change into the simulator immediately
  583. virtual void SetVelocityInstantaneous( const Vector *velocity, const AngularImpulse *angularVelocity ) = 0;
  584. // NOTE: velocity is in worldspace, angularVelocity is relative to the object's
  585. // local axes (just like pev->velocity, pev->avelocity)
  586. virtual void GetVelocity( Vector *velocity, AngularImpulse *angularVelocity ) = 0;
  587. // NOTE: These are velocities, not forces. i.e. They will have the same effect regardless of
  588. // the object's mass or inertia
  589. virtual void AddVelocity( const Vector *velocity, const AngularImpulse *angularVelocity ) = 0;
  590. virtual void GetVelocityAtPoint( const Vector &worldPosition, Vector &velocity ) = 0;
  591. virtual float GetEnergy() = 0;
  592. // returns true if the object is in contact with another object
  593. // if true, puts a point on the contact surface in contactPoint, and
  594. // a pointer to the object in contactObject
  595. // NOTE: You can pass NULL for either to avoid computations
  596. // JAY: This is still an experiment
  597. virtual bool GetContactPoint( Vector *contactPoint, IPhysicsObject **contactObject ) = 0;
  598. // refactor this a bit - move some of this to IPhysicsShadowController
  599. virtual void SetShadow( float maxSpeed, float maxAngularSpeed, bool allowPhysicsMovement, bool allowPhysicsRotation ) = 0;
  600. virtual void UpdateShadow( const Vector &targetPosition, const QAngle &targetAngles, bool tempDisableGravity, float timeOffset ) = 0;
  601. // returns number of ticks since last Update() call
  602. virtual int GetShadowPosition( Vector *position, QAngle *angles ) = 0;
  603. virtual IPhysicsShadowController *GetShadowController( void ) const = 0;
  604. virtual const CPhysCollide *GetCollide( void ) const = 0;
  605. virtual const char *GetName() = 0;
  606. virtual void RemoveShadowController() = 0;
  607. virtual bool IsMoveable() = 0;
  608. // applies the math of the shadow controller to this object.
  609. // for use in your own controllers
  610. // returns the new value of secondsToArrival with dt time elapsed
  611. virtual float ComputeShadowControl( const hlshadowcontrol_params_t &params, float secondsToArrival, float dt ) = 0;
  612. // coefficients are optional, pass either
  613. virtual void SetDragCoefficient( float *pDrag, float *pAngularDrag ) = 0;
  614. // Get the radius if this is a sphere object (zero if this is a polygonal mesh)
  615. virtual float GetSphereRadius() = 0;
  616. virtual float CalculateLinearDrag( const Vector &unitDirection ) const = 0;
  617. virtual float CalculateAngularDrag( const Vector &objectSpaceRotationAxis ) const = 0;
  618. virtual void SetBuoyancyRatio( float ratio ) = 0; // Override bouyancy
  619. virtual void BecomeTrigger() = 0;
  620. virtual void RemoveTrigger() = 0;
  621. virtual bool IsTrigger() = 0;
  622. virtual bool IsFluid() = 0; // fluids are special triggers with fluid controllers attached, they return true to IsTrigger() as well!
  623. // sets the object to be hinged. Fixed it place, but able to rotate around one axis.
  624. virtual void BecomeHinged( int localAxis ) = 0;
  625. // resets the object to original state
  626. virtual void RemoveHinged() = 0;
  627. virtual bool IsHinged() = 0;
  628. virtual unsigned int GetContents() = 0;
  629. virtual void SetContents( unsigned int contents ) = 0;
  630. virtual Vector GetMassCenterLocalSpace() = 0;
  631. // used to iterate the contact points of an object
  632. virtual IPhysicsFrictionSnapshot *CreateFrictionSnapshot() = 0;
  633. virtual void DestroyFrictionSnapshot( IPhysicsFrictionSnapshot *pSnapshot ) = 0;
  634. // dumps info about the object to Msg()
  635. virtual void OutputDebugInfo() = 0;
  636. virtual void GetImplicitVelocity( Vector *velocity, AngularImpulse *angularVelocity ) = 0;
  637. // this is a hack to recheck current contacts
  638. // some of them may not be valid if the object's collision rules have recently changed
  639. // UNDONE: Force this in RecheckCollisionFilter() ?
  640. virtual void RecheckContactPoints() = 0;
  641. };
  642. abstract_class IPhysicsSpring
  643. {
  644. public:
  645. virtual ~IPhysicsSpring( void ) {}
  646. virtual void GetEndpoints( Vector *worldPositionStart, Vector *worldPositionEnd ) = 0;
  647. virtual void SetSpringConstant( float flSpringContant) = 0;
  648. virtual void SetSpringDamping( float flSpringDamping) = 0;
  649. virtual void SetSpringLength( float flSpringLenght) = 0;
  650. // Get the starting object
  651. virtual IPhysicsObject *GetStartObject( void ) = 0;
  652. // Get the end object
  653. virtual IPhysicsObject *GetEndObject( void ) = 0;
  654. };
  655. //-----------------------------------------------------------------------------
  656. // Purpose: These properties are defined per-material. This is accessible at
  657. // each triangle in a collision mesh
  658. //-----------------------------------------------------------------------------
  659. struct surfacephysicsparams_t
  660. {
  661. // vphysics physical properties
  662. float friction;
  663. float elasticity; // collision elasticity - used to compute coefficient of restitution
  664. float density; // physical density (in kg / m^3)
  665. float thickness; // material thickness if not solid (sheet materials) in inches
  666. float dampening;
  667. };
  668. struct surfaceaudioparams_t
  669. {
  670. // sounds / audio data
  671. float reflectivity; // like elasticity, but how much sound should be reflected by this surface
  672. float hardnessFactor; // like elasticity, but only affects impact sound choices
  673. float roughnessFactor; // like friction, but only affects scrape sound choices
  674. // audio thresholds
  675. float roughThreshold; // surface roughness > this causes "rough" scrapes, < this causes "smooth" scrapes
  676. float hardThreshold; // surface hardness > this causes "hard" impacts, < this causes "soft" impacts
  677. float hardVelocityThreshold; // collision velocity > this causes "hard" impacts, < this causes "soft" impacts
  678. // NOTE: Hard impacts must meet both hardnessFactor AND velocity thresholds
  679. };
  680. struct surfacesoundnames_t
  681. {
  682. unsigned short stepleft;
  683. unsigned short stepright;
  684. unsigned short impactSoft;
  685. unsigned short impactHard;
  686. unsigned short scrapeSmooth;
  687. unsigned short scrapeRough;
  688. unsigned short bulletImpact;
  689. unsigned short rolling;
  690. unsigned short breakSound;
  691. unsigned short strainSound;
  692. };
  693. struct surfacegameprops_t
  694. {
  695. // game movement data
  696. float maxSpeedFactor; // Modulates player max speed when walking on this surface
  697. float jumpFactor; // Indicates how much higher the player should jump when on the surface
  698. // Game-specific data
  699. unsigned short material;
  700. // Indicates whether or not the player is on a ladder.
  701. unsigned char climbable;
  702. unsigned char pad;
  703. };
  704. //-----------------------------------------------------------------------------
  705. // Purpose: Each different material has an entry like this
  706. //-----------------------------------------------------------------------------
  707. struct surfacedata_t
  708. {
  709. surfacephysicsparams_t physics; // physics parameters
  710. surfaceaudioparams_t audio; // audio parameters
  711. surfacesoundnames_t sounds; // names of linked sounds
  712. surfacegameprops_t game; // Game data / properties
  713. };
  714. #define VPHYSICS_SURFACEPROPS_INTERFACE_VERSION_1 "VPhysicsSurfaceProps001"
  715. abstract_class IPhysicsSurfaceProps
  716. {
  717. public:
  718. virtual ~IPhysicsSurfaceProps( void ) {}
  719. // parses a text file containing surface prop keys
  720. virtual int ParseSurfaceData( const char *pFilename, const char *pTextfile ) = 0;
  721. // current number of entries in the database
  722. virtual int SurfacePropCount( void ) = 0;
  723. virtual int GetSurfaceIndex( const char *pSurfacePropName ) = 0;
  724. virtual void GetPhysicsProperties( int surfaceDataIndex, float *density, float *thickness, float *friction, float *elasticity ) = 0;
  725. virtual surfacedata_t *GetSurfaceData( int surfaceDataIndex ) = 0;
  726. virtual const char *GetString( unsigned short stringTableIndex ) = 0;
  727. virtual const char *GetPropName( int surfaceDataIndex ) = 0;
  728. // sets the global index table for world materials
  729. virtual void SetWorldMaterialIndexTable( int *pMapArray, int mapSize ) = 0;
  730. // NOTE: Same as GetPhysicsProperties, but maybe more convenient
  731. virtual void GetPhysicsParameters( int surfaceDataIndex, surfacephysicsparams_t *pParamsOut ) = 0;
  732. };
  733. abstract_class IPhysicsFluidController
  734. {
  735. public:
  736. virtual ~IPhysicsFluidController( void ) {}
  737. virtual void SetGameData( void *pGameData ) = 0;
  738. virtual void *GetGameData( void ) const = 0;
  739. virtual void GetSurfacePlane( Vector *pNormal, float *pDist ) = 0;
  740. virtual float GetDensity() = 0;
  741. virtual void WakeAllSleepingObjects() = 0;
  742. virtual int GetContents() const = 0;
  743. };
  744. //-----------------------------------------------------------------------------
  745. // Purpose: parameter block for creating fluid dynamic motion
  746. // UNDONE: Expose additional fluid model paramters?
  747. //-----------------------------------------------------------------------------
  748. struct fluidparams_t
  749. {
  750. Vector4D surfacePlane; // x,y,z normal, dist (plane constant) fluid surface
  751. Vector currentVelocity; // velocity of the current in inches/second
  752. float damping; // damping factor for buoyancy (tweak)
  753. float torqueFactor;
  754. float viscosityFactor;
  755. void *pGameData;
  756. bool useAerodynamics;// true if this controller should calculate surface pressure
  757. int contents;
  758. fluidparams_t() {}
  759. fluidparams_t( fluidparams_t const& src )
  760. {
  761. Vector4DCopy( src.surfacePlane, surfacePlane );
  762. VectorCopy( src.currentVelocity, currentVelocity );
  763. damping = src.damping;
  764. torqueFactor = src.torqueFactor;
  765. viscosityFactor = src.viscosityFactor;
  766. contents = src.contents;
  767. }
  768. };
  769. //-----------------------------------------------------------------------------
  770. // Purpose: parameter block for creating linear springs
  771. // UNDONE: Expose additional spring model paramters?
  772. //-----------------------------------------------------------------------------
  773. struct springparams_t
  774. {
  775. springparams_t()
  776. {
  777. memset( this, 0, sizeof(*this) );
  778. }
  779. float constant; // spring constant
  780. float naturalLength;// relaxed length
  781. float damping; // damping factor
  782. float relativeDamping; // relative damping (damping proportional to the change in the relative position of the objects)
  783. Vector startPosition;
  784. Vector endPosition;
  785. bool useLocalPositions; // start & end Position are in local space to start and end objects if this is true
  786. bool onlyStretch; // only apply forces when the length is greater than the natural length
  787. };
  788. //-----------------------------------------------------------------------------
  789. // Purpose: parameter block for creating polygonal objects
  790. //-----------------------------------------------------------------------------
  791. struct objectparams_t
  792. {
  793. Vector *massCenterOverride;
  794. float mass;
  795. float inertia;
  796. float damping;
  797. float rotdamping;
  798. float rotInertiaLimit;
  799. const char *pName; // used only for debugging
  800. void *pGameData;
  801. float volume;
  802. float dragCoefficient;
  803. bool enableCollisions;
  804. };
  805. struct convertconvexparams_t
  806. {
  807. bool buildOuterConvexHull;
  808. bool buildDragAxisAreas;
  809. bool buildOptimizedTraceTables;
  810. float dragAreaEpsilon;
  811. CPhysConvex *pForcedOuterHull;
  812. void Defaults()
  813. {
  814. dragAreaEpsilon = 0.25f; // 0.5in x 0.5in square
  815. buildOuterConvexHull = false;
  816. buildDragAxisAreas = false;
  817. buildOptimizedTraceTables = false;
  818. pForcedOuterHull = NULL;
  819. }
  820. };
  821. //-----------------------------------------------------------------------------
  822. // Physics interface IDs
  823. //
  824. // Note that right now the order of the enum also defines the order of save/load
  825. //-----------------------------------------------------------------------------
  826. // Purpose: parameter blocks for save and load operations
  827. //-----------------------------------------------------------------------------
  828. struct physsaveparams_t
  829. {
  830. ISave *pSave;
  831. void *pObject;
  832. PhysInterfaceId_t type;
  833. };
  834. struct physrestoreparams_t
  835. {
  836. IRestore *pRestore;
  837. void **ppObject;
  838. PhysInterfaceId_t type;
  839. void *pGameData;
  840. const char *pName; // used only for debugging
  841. const CPhysCollide *pCollisionModel;
  842. IPhysicsEnvironment *pEnvironment;
  843. IPhysicsGameTrace *pGameTrace;
  844. };
  845. struct physrecreateparams_t
  846. {
  847. void *pOldObject;
  848. void *pNewObject;
  849. };
  850. struct physprerestoreparams_t
  851. {
  852. int recreatedObjectCount;
  853. physrecreateparams_t recreatedObjectList[1];
  854. };
  855. //-------------------------------------
  856. #define DEFINE_PIID( type, enumval ) \
  857. template <> inline PhysInterfaceId_t GetPhysIID<type>( type ** ) { return enumval; }
  858. template <class PHYSPTR> inline PhysInterfaceId_t GetPhysIID(PHYSPTR **); // will get link error if no match
  859. DEFINE_PIID( IPhysicsObject, PIID_IPHYSICSOBJECT );
  860. DEFINE_PIID( IPhysicsFluidController, PIID_IPHYSICSFLUIDCONTROLLER );
  861. DEFINE_PIID( IPhysicsSpring, PIID_IPHYSICSSPRING );
  862. DEFINE_PIID( IPhysicsConstraintGroup, PIID_IPHYSICSCONSTRAINTGROUP );
  863. DEFINE_PIID( IPhysicsConstraint, PIID_IPHYSICSCONSTRAINT );
  864. DEFINE_PIID( IPhysicsShadowController, PIID_IPHYSICSSHADOWCONTROLLER );
  865. DEFINE_PIID( IPhysicsPlayerController, PIID_IPHYSICSPLAYERCONTROLLER );
  866. DEFINE_PIID( IPhysicsMotionController, PIID_IPHYSICSMOTIONCONTROLLER );
  867. DEFINE_PIID( IPhysicsVehicleController, PIID_IPHYSICSVEHICLECONTROLLER );
  868. DEFINE_PIID( IPhysicsGameTrace, PIID_IPHYSICSGAMETRACE );
  869. //-----------------------------------------------------------------------------
  870. } // end namespace VPhysicsInterfaceV30
  871. #endif // VPHYSICS_INTERFACE_V30_H