doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Physics_Player.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
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.
13 
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.
18 
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/>.
21 
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.
23 
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.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __PHYSICS_PLAYER_H__
30 #define __PHYSICS_PLAYER_H__
31 
32 /*
33 ===================================================================================
34 
35  Player physics
36 
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.
39 
40 ===================================================================================
41 */
42 
43 // movementType
44 typedef enum {
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
50 } pmtype_t;
51 
52 typedef enum {
57 } waterLevel_t;
58 
59 #define MAXTOUCH 32
60 
61 typedef struct playerPState_s {
66  float stepUp;
71 
73 
74 public:
76 
77  idPhysics_Player( void );
78 
79  void Save( idSaveGame *savefile ) const;
80  void Restore( idRestoreGame *savefile );
81 
82  // initialisation
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
100 
101 public: // common physics interface
102  bool Evaluate( int timeStepMSec, int endTimeMSec );
103  void UpdateTime( int endTimeMSec );
104  int GetTime( void ) const;
105 
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;
110 
111  void SaveState( void );
112  void RestoreState( void );
113 
114  void SetOrigin( const idVec3 &newOrigin, int id = -1 );
115  void SetAxis( const idMat3 &newAxis, int id = -1 );
116 
117  void Translate( const idVec3 &translation, int id = -1 );
118  void Rotate( const idRotation &rotation, int id = -1 );
119 
120  void SetLinearVelocity( const idVec3 &newLinearVelocity, int id = 0 );
121 
122  const idVec3 & GetLinearVelocity( int id = 0 ) const;
123 
124  void SetPushed( int deltaTime );
125  const idVec3 & GetPushedLinearVelocity( const int id = 0 ) const;
126  void ClearPushedVelocity( void );
127 
128  void SetMaster( idEntity *master, const bool orientated = true );
129 
130  void WriteToSnapshot( idBitMsgDelta &msg ) const;
131  void ReadFromSnapshot( const idBitMsgDelta &msg );
132 
133 private:
134  // player physics state
137 
138  // properties
139  float walkSpeed;
140  float crouchSpeed;
143  int debugLevel; // if set, diagnostic output will be printed
144 
145  // player input
148 
149  // run-time variables
151  float frametime;
152  float playerSpeed;
155 
156  // walk movement
157  bool walking;
161 
162  // ladder movement
163  bool ladder;
165 
166  // results of last evaluate
169 
170 private:
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 );
193 };
194 
195 #endif /* !__PHYSICS_PLAYER_H__ */
void WaterJumpMove(void)
int GetWaterType(void) const
playerPState_t saved
const idMaterial * groundMaterial
void CorrectAllSolid(trace_t &trace, int contents)
waterLevel_t GetWaterLevel(void) const
int GetTime(void) const
const idVec3 & GetPushedLinearVelocity(const int id=0) const
Definition: Vector.h:316
void SpectatorMove(void)
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
void SetWaterLevel(void)
float GetStepUp(void) const
void SetPlayerInput(const usercmd_t &cmd, const idAngles &newViewAngles)
bool HasJumped(void) const
void SetDebugLevel(bool set)
CLASS_PROTOTYPE(idPhysics_Player)
float CmdScale(const usercmd_t &cmd) const
void Translate(const idVec3 &translation, int id=-1)
waterLevel_t
bool Evaluate(int timeStepMSec, int endTimeMSec)
void SetLinearVelocity(const idVec3 &newLinearVelocity, int id=0)
void SetMaxStepHeight(const float newMaxStepHeight)
int GetRestStartTime(void) const
bool OnLadder(void) const
void SetPushed(int deltaTime)
const idVec3 & GetLinearVelocity(int id=0) const
struct playerPState_s playerPState_t
float GetMaxStepHeight(void) const
void Rotate(const idRotation &rotation, int id=-1)
const idVec3 & PlayerGetOrigin(void) const
void GetImpactInfo(const int id, const idVec3 &point, impactInfo_t *info) const
void ApplyImpulse(const int id, const idVec3 &point, const idVec3 &impulse)
Definition: Matrix.h:333
void Restore(idRestoreGame *savefile)
void CheckGround(void)
bool CheckWaterJump(void)
void UpdateTime(int endTimeMSec)
void Accelerate(const idVec3 &wishdir, const float wishspeed, const float accel)
bool IsAtRest(void) const
bool IsCrouching(void) const
void SetSpeed(const float newWalkSpeed, const float newCrouchSpeed)
pmtype_t
void MovePlayer(int msec)
void ClearPushedVelocity(void)
void SetOrigin(const idVec3 &newOrigin, int id=-1)
void ReadFromSnapshot(const idBitMsgDelta &msg)
waterLevel_t waterLevel
void SetMovementType(const pmtype_t type)
playerPState_t current
void WriteToSnapshot(idBitMsgDelta &msg) const
void SetAxis(const idMat3 &newAxis, int id=-1)
void SetMaxJumpHeight(const float newMaxJumpHeight)
void SetKnockBack(const int knockBackTime)
void Save(idSaveGame *savefile) const
bool HasSteppedUp(void) const
void SetMaster(idEntity *master, const bool orientated=true)
bool SlideMove(bool gravity, bool stepUp, bool stepDown, bool push)