Physics_Monster.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_MONSTER_H__
  21. #define __PHYSICS_MONSTER_H__
  22. /*
  23. ===================================================================================
  24. Monster physics
  25. Simulates the motion of a monster through the environment. The monster motion
  26. is typically driven by animations.
  27. ===================================================================================
  28. */
  29. typedef enum {
  30. MM_OK,
  31. MM_SLIDING,
  32. MM_BLOCKED,
  33. MM_STEPPED,
  34. MM_FALLING
  35. } monsterMoveResult_t;
  36. typedef struct monsterPState_s {
  37. int atRest;
  38. bool onGround;
  39. idVec3 origin;
  40. idVec3 velocity;
  41. idVec3 localOrigin;
  42. idVec3 pushVelocity;
  43. } monsterPState_t;
  44. class idPhysics_Monster : public idPhysics_Actor {
  45. public:
  46. CLASS_PROTOTYPE( idPhysics_Monster );
  47. idPhysics_Monster( void );
  48. void Save( idSaveGame *savefile ) const;
  49. void Restore( idRestoreGame *savefile );
  50. // maximum step up the monster can take, default 18 units
  51. void SetMaxStepHeight( const float newMaxStepHeight );
  52. float GetMaxStepHeight( void ) const;
  53. // minimum cosine of floor angle to be able to stand on the floor
  54. void SetMinFloorCosine( const float newMinFloorCosine );
  55. // set delta for next move
  56. void SetDelta( const idVec3 &d );
  57. // returns true if monster is standing on the ground
  58. bool OnGround( void ) const;
  59. // returns the movement result
  60. monsterMoveResult_t GetMoveResult( void ) const;
  61. // overrides any velocity for pure delta movement
  62. void ForceDeltaMove( bool force );
  63. // whether velocity should be affected by gravity
  64. void UseFlyMove( bool force );
  65. // don't use delta movement
  66. void UseVelocityMove( bool force );
  67. // get entity blocking the move
  68. idEntity * GetSlideMoveEntity( void ) const;
  69. // enable/disable activation by impact
  70. void EnableImpact( void );
  71. void DisableImpact( void );
  72. public: // common physics interface
  73. bool Evaluate( int timeStepMSec, int endTimeMSec );
  74. void UpdateTime( int endTimeMSec );
  75. int GetTime( void ) const;
  76. void GetImpactInfo( const int id, const idVec3 &point, impactInfo_t *info ) const;
  77. void ApplyImpulse( const int id, const idVec3 &point, const idVec3 &impulse );
  78. void Activate( void );
  79. void PutToRest( void );
  80. bool IsAtRest( void ) const;
  81. int GetRestStartTime( void ) const;
  82. void SaveState( void );
  83. void RestoreState( void );
  84. void SetOrigin( const idVec3 &newOrigin, int id = -1 );
  85. void SetAxis( const idMat3 &newAxis, int id = -1 );
  86. void Translate( const idVec3 &translation, int id = -1 );
  87. void Rotate( const idRotation &rotation, int id = -1 );
  88. void SetLinearVelocity( const idVec3 &newLinearVelocity, int id = 0 );
  89. const idVec3 & GetLinearVelocity( int id = 0 ) const;
  90. void SetPushed( int deltaTime );
  91. const idVec3 & GetPushedLinearVelocity( const int id = 0 ) const;
  92. void SetMaster( idEntity *master, const bool orientated = true );
  93. void WriteToSnapshot( idBitMsgDelta &msg ) const;
  94. void ReadFromSnapshot( const idBitMsgDelta &msg );
  95. private:
  96. // monster physics state
  97. monsterPState_t current;
  98. monsterPState_t saved;
  99. // properties
  100. float maxStepHeight; // maximum step height
  101. float minFloorCosine; // minimum cosine of floor angle
  102. idVec3 delta; // delta for next move
  103. bool forceDeltaMove;
  104. bool fly;
  105. bool useVelocityMove;
  106. bool noImpact; // if true do not activate when another object collides
  107. // results of last evaluate
  108. monsterMoveResult_t moveResult;
  109. idEntity * blockingEntity;
  110. private:
  111. void CheckGround( monsterPState_t &state );
  112. monsterMoveResult_t SlideMove( idVec3 &start, idVec3 &velocity, const idVec3 &delta );
  113. monsterMoveResult_t StepMove( idVec3 &start, idVec3 &velocity, const idVec3 &delta );
  114. void Rest( void );
  115. };
  116. #endif /* !__PHYSICS_MONSTER_H__ */