doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Physics_Base.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_BASE_H__
30 #define __PHYSICS_BASE_H__
31 
32 /*
33 ===============================================================================
34 
35  Physics base for a moving object using one or more collision models.
36 
37 ===============================================================================
38 */
39 
40 #define contactEntity_t idEntityPtr<idEntity>
41 
42 class idPhysics_Base : public idPhysics {
43 
44 public:
46 
47  idPhysics_Base( void );
48  ~idPhysics_Base( void );
49 
50  void Save( idSaveGame *savefile ) const;
51  void Restore( idRestoreGame *savefile );
52 
53 public: // common physics interface
54 
55  void SetSelf( idEntity *e );
56 
57  void SetClipModel( idClipModel *model, float density, int id = 0, bool freeOld = true );
58  idClipModel * GetClipModel( int id = 0 ) const;
59  int GetNumClipModels( void ) const;
60 
61  void SetMass( float mass, int id = -1 );
62  float GetMass( int id = -1 ) const;
63 
64  void SetContents( int contents, int id = -1 );
65  int GetContents( int id = -1 ) const;
66 
67  void SetClipMask( int mask, int id = -1 );
68  int GetClipMask( int id = -1 ) const;
69 
70  const idBounds & GetBounds( int id = -1 ) const;
71  const idBounds & GetAbsBounds( int id = -1 ) const;
72 
73  bool Evaluate( int timeStepMSec, int endTimeMSec );
74  void UpdateTime( int endTimeMSec );
75  int GetTime( void ) const;
76 
77  void GetImpactInfo( const int id, const idVec3 &point, impactInfo_t *info ) const;
78  void ApplyImpulse( const int id, const idVec3 &point, const idVec3 &impulse );
79  void AddForce( const int id, const idVec3 &point, const idVec3 &force );
80  void Activate( void );
81  void PutToRest( void );
82  bool IsAtRest( void ) const;
83  int GetRestStartTime( void ) const;
84  bool IsPushable( void ) const;
85 
86  void SaveState( void );
87  void RestoreState( void );
88 
89  void SetOrigin( const idVec3 &newOrigin, int id = -1 );
90  void SetAxis( const idMat3 &newAxis, int id = -1 );
91 
92  void Translate( const idVec3 &translation, int id = -1 );
93  void Rotate( const idRotation &rotation, int id = -1 );
94 
95  const idVec3 & GetOrigin( int id = 0 ) const;
96  const idMat3 & GetAxis( int id = 0 ) const;
97 
98  void SetLinearVelocity( const idVec3 &newLinearVelocity, int id = 0 );
99  void SetAngularVelocity( const idVec3 &newAngularVelocity, int id = 0 );
100 
101  const idVec3 & GetLinearVelocity( int id = 0 ) const;
102  const idVec3 & GetAngularVelocity( int id = 0 ) const;
103 
104  void SetGravity( const idVec3 &newGravity );
105  const idVec3 & GetGravity( void ) const;
106  const idVec3 & GetGravityNormal( void ) const;
107 
108  void ClipTranslation( trace_t &results, const idVec3 &translation, const idClipModel *model ) const;
109  void ClipRotation( trace_t &results, const idRotation &rotation, const idClipModel *model ) const;
110  int ClipContents( const idClipModel *model ) const;
111 
112  void DisableClip( void );
113  void EnableClip( void );
114 
115  void UnlinkClip( void );
116  void LinkClip( void );
117 
118  bool EvaluateContacts( void );
119  int GetNumContacts( void ) const;
120  const contactInfo_t & GetContact( int num ) const;
121  void ClearContacts( void );
122  void AddContactEntity( idEntity *e );
123  void RemoveContactEntity( idEntity *e );
124 
125  bool HasGroundContacts( void ) const;
126  bool IsGroundEntity( int entityNum ) const;
127  bool IsGroundClipModel( int entityNum, int id ) const;
128 
129  void SetPushed( int deltaTime );
130  const idVec3 & GetPushedLinearVelocity( const int id = 0 ) const;
131  const idVec3 & GetPushedAngularVelocity( const int id = 0 ) const;
132 
133  void SetMaster( idEntity *master, const bool orientated = true );
134 
135  const trace_t * GetBlockingInfo( void ) const;
136  idEntity * GetBlockingEntity( void ) const;
137 
138  int GetLinearEndTime( void ) const;
139  int GetAngularEndTime( void ) const;
140 
141  void WriteToSnapshot( idBitMsgDelta &msg ) const;
142  void ReadFromSnapshot( const idBitMsgDelta &msg );
143 
144 protected:
145  idEntity * self; // entity using this physics object
146  int clipMask; // contents the physics object collides with
147  idVec3 gravityVector; // direction and magnitude of gravity
148  idVec3 gravityNormal; // normalized direction of gravity
149  idList<contactInfo_t> contacts; // contacts with other physics objects
150  idList<contactEntity_t> contactEntities; // entities touching this physics object
151 
152 protected:
153  // add ground contacts for the clip model
154  void AddGroundContacts( const idClipModel *clipModel );
155  // add contact entity links to contact entities
156  void AddContactEntitiesForContacts( void );
157  // active all contact entities
158  void ActivateContactEntities( void );
159  // returns true if the whole physics object is outside the world bounds
160  bool IsOutsideWorld( void ) const;
161  // draw linear and angular velocity
162  void DrawVelocity( int id, float linearScale, float angularScale ) const;
163 };
164 
165 #endif /* !__PHYSICS_BASE_H__ */
const idVec3 & GetGravity(void) const
void WriteToSnapshot(idBitMsgDelta &msg) const
void RemoveContactEntity(idEntity *e)
void ClipTranslation(trace_t &results, const idVec3 &translation, const idClipModel *model) const
void DrawVelocity(int id, float linearScale, float angularScale) const
void SetMass(float mass, int id=-1)
void GetImpactInfo(const int id, const idVec3 &point, impactInfo_t *info) const
int GetNumClipModels(void) const
GLenum GLint GLuint mask
Definition: glext.h:5864
void SetAxis(const idMat3 &newAxis, int id=-1)
void AddForce(const int id, const idVec3 &point, const idVec3 &force)
void PutToRest(void)
CLASS_PROTOTYPE(idPhysics_Base)
bool IsOutsideWorld(void) const
void SaveState(void)
bool EvaluateContacts(void)
idClipModel * GetClipModel(int id=0) const
Definition: Vector.h:316
void UpdateTime(int endTimeMSec)
int GetNumContacts(void) const
const contactInfo_t & GetContact(int num) const
const idMat3 & GetAxis(int id=0) const
void Activate(void)
GLuint GLuint num
Definition: glext.h:5390
void Save(idSaveGame *savefile) const
idEntity * GetBlockingEntity(void) const
const idBounds & GetBounds(int id=-1) const
void SetClipModel(idClipModel *model, float density, int id=0, bool freeOld=true)
void SetOrigin(const idVec3 &newOrigin, int id=-1)
void ApplyImpulse(const int id, const idVec3 &point, const idVec3 &impulse)
int GetAngularEndTime(void) const
void SetSelf(idEntity *e)
void AddContactEntity(idEntity *e)
void DisableClip(void)
void EnableClip(void)
void UnlinkClip(void)
bool IsGroundClipModel(int entityNum, int id) const
float GetMass(int id=-1) const
const idVec3 & GetLinearVelocity(int id=0) const
const idVec3 & GetGravityNormal(void) const
void Rotate(const idRotation &rotation, int id=-1)
const idBounds & GetAbsBounds(int id=-1) const
void AddGroundContacts(const idClipModel *clipModel)
void LinkClip(void)
void ClipRotation(trace_t &results, const idRotation &rotation, const idClipModel *model) const
void SetLinearVelocity(const idVec3 &newLinearVelocity, int id=0)
int GetTime(void) const
void RestoreState(void)
void SetPushed(int deltaTime)
idList< contactInfo_t > contacts
Definition: Physics_Base.h:149
bool IsGroundEntity(int entityNum) const
void AddContactEntitiesForContacts(void)
int GetRestStartTime(void) const
Definition: Matrix.h:333
idVec3 gravityNormal
Definition: Physics_Base.h:148
int GetContents(int id=-1) const
int GetLinearEndTime(void) const
void SetClipMask(int mask, int id=-1)
void Restore(idRestoreGame *savefile)
void SetAngularVelocity(const idVec3 &newAngularVelocity, int id=0)
int GetClipMask(int id=-1) const
const idVec3 & GetOrigin(int id=0) const
const idVec3 & GetPushedLinearVelocity(const int id=0) const
void ClearContacts(void)
void SetContents(int contents, int id=-1)
idVec3 gravityVector
Definition: Physics_Base.h:147
int ClipContents(const idClipModel *model) const
bool IsPushable(void) const
bool HasGroundContacts(void) const
bool Evaluate(int timeStepMSec, int endTimeMSec)
void SetMaster(idEntity *master, const bool orientated=true)
void ActivateContactEntities(void)
void SetGravity(const idVec3 &newGravity)
void ReadFromSnapshot(const idBitMsgDelta &msg)
const idVec3 & GetAngularVelocity(int id=0) const
idList< contactEntity_t > contactEntities
Definition: Physics_Base.h:150
const idVec3 & GetPushedAngularVelocity(const int id=0) const
const trace_t * GetBlockingInfo(void) const
void Translate(const idVec3 &translation, int id=-1)
bool IsAtRest(void) const