Physics_Base.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __PHYSICS_BASE_H__
  21. #define __PHYSICS_BASE_H__
  22. /*
  23. ===============================================================================
  24. Physics base for a moving object using one or more collision models.
  25. ===============================================================================
  26. */
  27. #define contactEntity_t idEntityPtr<idEntity>
  28. class idPhysics_Base : public idPhysics {
  29. public:
  30. CLASS_PROTOTYPE( idPhysics_Base );
  31. idPhysics_Base( void );
  32. ~idPhysics_Base( void );
  33. void Save( idSaveGame *savefile ) const;
  34. void Restore( idRestoreGame *savefile );
  35. public: // common physics interface
  36. void SetSelf( idEntity *e );
  37. void SetClipModel( idClipModel *model, float density, int id = 0, bool freeOld = true );
  38. idClipModel * GetClipModel( int id = 0 ) const;
  39. int GetNumClipModels( void ) const;
  40. void SetMass( float mass, int id = -1 );
  41. float GetMass( int id = -1 ) const;
  42. void SetContents( int contents, int id = -1 );
  43. int GetContents( int id = -1 ) const;
  44. void SetClipMask( int mask, int id = -1 );
  45. int GetClipMask( int id = -1 ) const;
  46. const idBounds & GetBounds( int id = -1 ) const;
  47. const idBounds & GetAbsBounds( int id = -1 ) const;
  48. bool Evaluate( int timeStepMSec, int endTimeMSec );
  49. void UpdateTime( int endTimeMSec );
  50. int GetTime( void ) const;
  51. void GetImpactInfo( const int id, const idVec3 &point, impactInfo_t *info ) const;
  52. void ApplyImpulse( const int id, const idVec3 &point, const idVec3 &impulse );
  53. void AddForce( const int id, const idVec3 &point, const idVec3 &force );
  54. void Activate( void );
  55. void PutToRest( void );
  56. bool IsAtRest( void ) const;
  57. int GetRestStartTime( void ) const;
  58. bool IsPushable( void ) const;
  59. void SaveState( void );
  60. void RestoreState( void );
  61. void SetOrigin( const idVec3 &newOrigin, int id = -1 );
  62. void SetAxis( const idMat3 &newAxis, int id = -1 );
  63. void Translate( const idVec3 &translation, int id = -1 );
  64. void Rotate( const idRotation &rotation, int id = -1 );
  65. const idVec3 & GetOrigin( int id = 0 ) const;
  66. const idMat3 & GetAxis( int id = 0 ) const;
  67. void SetLinearVelocity( const idVec3 &newLinearVelocity, int id = 0 );
  68. void SetAngularVelocity( const idVec3 &newAngularVelocity, int id = 0 );
  69. const idVec3 & GetLinearVelocity( int id = 0 ) const;
  70. const idVec3 & GetAngularVelocity( int id = 0 ) const;
  71. void SetGravity( const idVec3 &newGravity );
  72. const idVec3 & GetGravity( void ) const;
  73. const idVec3 & GetGravityNormal( void ) const;
  74. void ClipTranslation( trace_t &results, const idVec3 &translation, const idClipModel *model ) const;
  75. void ClipRotation( trace_t &results, const idRotation &rotation, const idClipModel *model ) const;
  76. int ClipContents( const idClipModel *model ) const;
  77. void DisableClip( void );
  78. void EnableClip( void );
  79. void UnlinkClip( void );
  80. void LinkClip( void );
  81. bool EvaluateContacts( void );
  82. int GetNumContacts( void ) const;
  83. const contactInfo_t & GetContact( int num ) const;
  84. void ClearContacts( void );
  85. void AddContactEntity( idEntity *e );
  86. void RemoveContactEntity( idEntity *e );
  87. bool HasGroundContacts( void ) const;
  88. bool IsGroundEntity( int entityNum ) const;
  89. bool IsGroundClipModel( int entityNum, int id ) const;
  90. void SetPushed( int deltaTime );
  91. const idVec3 & GetPushedLinearVelocity( const int id = 0 ) const;
  92. const idVec3 & GetPushedAngularVelocity( const int id = 0 ) const;
  93. void SetMaster( idEntity *master, const bool orientated = true );
  94. const trace_t * GetBlockingInfo( void ) const;
  95. idEntity * GetBlockingEntity( void ) const;
  96. int GetLinearEndTime( void ) const;
  97. int GetAngularEndTime( void ) const;
  98. void WriteToSnapshot( idBitMsgDelta &msg ) const;
  99. void ReadFromSnapshot( const idBitMsgDelta &msg );
  100. protected:
  101. idEntity * self; // entity using this physics object
  102. int clipMask; // contents the physics object collides with
  103. idVec3 gravityVector; // direction and magnitude of gravity
  104. idVec3 gravityNormal; // normalized direction of gravity
  105. idList<contactInfo_t> contacts; // contacts with other physics objects
  106. idList<contactEntity_t> contactEntities; // entities touching this physics object
  107. protected:
  108. // add ground contacts for the clip model
  109. void AddGroundContacts( const idClipModel *clipModel );
  110. // add contact entity links to contact entities
  111. void AddContactEntitiesForContacts( void );
  112. // active all contact entities
  113. void ActivateContactEntities( void );
  114. // returns true if the whole physics object is outside the world bounds
  115. bool IsOutsideWorld( void ) const;
  116. // draw linear and angular velocity
  117. void DrawVelocity( int id, float linearScale, float angularScale ) const;
  118. };
  119. #endif /* !__PHYSICS_BASE_H__ */