Physics_Player.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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_PLAYER_H__
  21. #define __PHYSICS_PLAYER_H__
  22. /*
  23. ===================================================================================
  24. Player physics
  25. Simulates the motion of a player through the environment. Input from the
  26. player is used to allow a certain degree of control over the motion.
  27. ===================================================================================
  28. */
  29. // movementType
  30. typedef enum {
  31. PM_NORMAL, // normal physics
  32. PM_DEAD, // no acceleration or turning, but free falling
  33. PM_SPECTATOR, // flying without gravity but with collision detection
  34. PM_FREEZE, // stuck in place without control
  35. PM_NOCLIP // flying without collision detection nor gravity
  36. } pmtype_t;
  37. typedef enum {
  38. WATERLEVEL_NONE,
  39. WATERLEVEL_FEET,
  40. WATERLEVEL_WAIST,
  41. WATERLEVEL_HEAD
  42. } waterLevel_t;
  43. #define MAXTOUCH 32
  44. typedef struct playerPState_s {
  45. idVec3 origin;
  46. idVec3 velocity;
  47. idVec3 localOrigin;
  48. idVec3 pushVelocity;
  49. float stepUp;
  50. int movementType;
  51. int movementFlags;
  52. int movementTime;
  53. } playerPState_t;
  54. class idPhysics_Player : public idPhysics_Actor {
  55. public:
  56. CLASS_PROTOTYPE( idPhysics_Player );
  57. idPhysics_Player( void );
  58. void Save( idSaveGame *savefile ) const;
  59. void Restore( idRestoreGame *savefile );
  60. // initialisation
  61. void SetSpeed( const float newWalkSpeed, const float newCrouchSpeed );
  62. void SetMaxStepHeight( const float newMaxStepHeight );
  63. float GetMaxStepHeight( void ) const;
  64. void SetMaxJumpHeight( const float newMaxJumpHeight );
  65. void SetMovementType( const pmtype_t type );
  66. void SetPlayerInput( const usercmd_t &cmd, const idAngles &newViewAngles );
  67. void SetKnockBack( const int knockBackTime );
  68. void SetDebugLevel( bool set );
  69. // feed back from last physics frame
  70. waterLevel_t GetWaterLevel( void ) const;
  71. int GetWaterType( void ) const;
  72. bool HasJumped( void ) const;
  73. bool HasSteppedUp( void ) const;
  74. float GetStepUp( void ) const;
  75. bool IsCrouching( void ) const;
  76. bool OnLadder( void ) const;
  77. const idVec3 & PlayerGetOrigin( void ) const; // != GetOrigin
  78. public: // common physics interface
  79. bool Evaluate( int timeStepMSec, int endTimeMSec );
  80. void UpdateTime( int endTimeMSec );
  81. int GetTime( void ) const;
  82. void GetImpactInfo( const int id, const idVec3 &point, impactInfo_t *info ) const;
  83. void ApplyImpulse( const int id, const idVec3 &point, const idVec3 &impulse );
  84. bool IsAtRest( void ) const;
  85. int GetRestStartTime( void ) const;
  86. void SaveState( void );
  87. void RestoreState( void );
  88. void SetOrigin( const idVec3 &newOrigin, int id = -1 );
  89. void SetAxis( const idMat3 &newAxis, int id = -1 );
  90. void Translate( const idVec3 &translation, int id = -1 );
  91. void Rotate( const idRotation &rotation, int id = -1 );
  92. void SetLinearVelocity( const idVec3 &newLinearVelocity, int id = 0 );
  93. const idVec3 & GetLinearVelocity( int id = 0 ) const;
  94. void SetPushed( int deltaTime );
  95. const idVec3 & GetPushedLinearVelocity( const int id = 0 ) const;
  96. void ClearPushedVelocity( void );
  97. void SetMaster( idEntity *master, const bool orientated = true );
  98. void WriteToSnapshot( idBitMsgDelta &msg ) const;
  99. void ReadFromSnapshot( const idBitMsgDelta &msg );
  100. private:
  101. // player physics state
  102. playerPState_t current;
  103. playerPState_t saved;
  104. // properties
  105. float walkSpeed;
  106. float crouchSpeed;
  107. float maxStepHeight;
  108. float maxJumpHeight;
  109. int debugLevel; // if set, diagnostic output will be printed
  110. // player input
  111. usercmd_t command;
  112. idAngles viewAngles;
  113. // run-time variables
  114. int framemsec;
  115. float frametime;
  116. float playerSpeed;
  117. idVec3 viewForward;
  118. idVec3 viewRight;
  119. // walk movement
  120. bool walking;
  121. bool groundPlane;
  122. trace_t groundTrace;
  123. const idMaterial * groundMaterial;
  124. // ladder movement
  125. bool ladder;
  126. idVec3 ladderNormal;
  127. // results of last evaluate
  128. waterLevel_t waterLevel;
  129. int waterType;
  130. private:
  131. float CmdScale( const usercmd_t &cmd ) const;
  132. void Accelerate( const idVec3 &wishdir, const float wishspeed, const float accel );
  133. bool SlideMove( bool gravity, bool stepUp, bool stepDown, bool push );
  134. void Friction( void );
  135. void WaterJumpMove( void );
  136. void WaterMove( void );
  137. void FlyMove( void );
  138. void AirMove( void );
  139. void WalkMove( void );
  140. void DeadMove( void );
  141. void NoclipMove( void );
  142. void SpectatorMove( void );
  143. void LadderMove( void );
  144. void CorrectAllSolid( trace_t &trace, int contents );
  145. void CheckGround( void );
  146. void CheckDuck( void );
  147. void CheckLadder( void );
  148. bool CheckJump( void );
  149. bool CheckWaterJump( void );
  150. void SetWaterLevel( void );
  151. void DropTimers( void );
  152. void MovePlayer( int msec );
  153. };
  154. #endif /* !__PHYSICS_PLAYER_H__ */