2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 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.
24 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.
26 ===========================================================================
29 #ifndef __PHYSICS_PLAYER_H__
30 #define __PHYSICS_PLAYER_H__
33 ===================================================================================
37 Simulates the motion of a player through the environment. Input from the
38 player is used to allow a certain degree of control over the motion.
40 ===================================================================================
45 PM_NORMAL, // normal physics
46 PM_DEAD, // no acceleration or turning, but free falling
47 PM_SPECTATOR, // flying without gravity but with collision detection
48 PM_FREEZE, // stuck in place without control
49 PM_NOCLIP // flying without collision detection nor gravity
61 typedef struct playerPState_s {
72 class idPhysics_Player : public idPhysics_Actor {
75 CLASS_PROTOTYPE( idPhysics_Player );
77 idPhysics_Player( void );
79 void Save( idSaveGame *savefile ) const;
80 void Restore( idRestoreGame *savefile );
83 void SetSpeed( const float newWalkSpeed, const float newCrouchSpeed );
84 void SetMaxStepHeight( const float newMaxStepHeight );
85 float GetMaxStepHeight( void ) const;
86 void SetMaxJumpHeight( const float newMaxJumpHeight );
87 void SetMovementType( const pmtype_t type );
88 void SetPlayerInput( const usercmd_t &cmd, const idAngles &newViewAngles );
89 void SetKnockBack( const int knockBackTime );
90 void SetDebugLevel( bool set );
91 // feed back from last physics frame
92 waterLevel_t GetWaterLevel( void ) const;
93 int GetWaterType( void ) const;
94 bool HasJumped( void ) const;
95 bool HasSteppedUp( void ) const;
96 float GetStepUp( void ) const;
97 bool IsCrouching( void ) const;
98 bool OnLadder( void ) const;
99 const idVec3 & PlayerGetOrigin( void ) const; // != GetOrigin
101 public: // common physics interface
102 bool Evaluate( int timeStepMSec, int endTimeMSec );
103 void UpdateTime( int endTimeMSec );
104 int GetTime( void ) const;
106 void GetImpactInfo( const int id, const idVec3 &point, impactInfo_t *info ) const;
107 void ApplyImpulse( const int id, const idVec3 &point, const idVec3 &impulse );
108 bool IsAtRest( void ) const;
109 int GetRestStartTime( void ) const;
111 void SaveState( void );
112 void RestoreState( void );
114 void SetOrigin( const idVec3 &newOrigin, int id = -1 );
115 void SetAxis( const idMat3 &newAxis, int id = -1 );
117 void Translate( const idVec3 &translation, int id = -1 );
118 void Rotate( const idRotation &rotation, int id = -1 );
120 void SetLinearVelocity( const idVec3 &newLinearVelocity, int id = 0 );
122 const idVec3 & GetLinearVelocity( int id = 0 ) const;
124 void SetPushed( int deltaTime );
125 const idVec3 & GetPushedLinearVelocity( const int id = 0 ) const;
126 void ClearPushedVelocity( void );
128 void SetMaster( idEntity *master, const bool orientated = true );
130 void WriteToSnapshot( idBitMsgDelta &msg ) const;
131 void ReadFromSnapshot( const idBitMsgDelta &msg );
134 // player physics state
135 playerPState_t current;
136 playerPState_t saved;
143 int debugLevel; // if set, diagnostic output will be printed
149 // run-time variables
160 const idMaterial * groundMaterial;
166 // results of last evaluate
167 waterLevel_t waterLevel;
171 float CmdScale( const usercmd_t &cmd ) const;
172 void Accelerate( const idVec3 &wishdir, const float wishspeed, const float accel );
173 bool SlideMove( bool gravity, bool stepUp, bool stepDown, bool push );
174 void Friction( void );
175 void WaterJumpMove( void );
176 void WaterMove( void );
177 void FlyMove( void );
178 void AirMove( void );
179 void WalkMove( void );
180 void DeadMove( void );
181 void NoclipMove( void );
182 void SpectatorMove( void );
183 void LadderMove( void );
184 void CorrectAllSolid( trace_t &trace, int contents );
185 void CheckGround( void );
186 void CheckDuck( void );
187 void CheckLadder( void );
188 bool CheckJump( void );
189 bool CheckWaterJump( void );
190 void SetWaterLevel( void );
191 void DropTimers( void );
192 void MovePlayer( int msec );
195 #endif /* !__PHYSICS_PLAYER_H__ */