doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Physics_Actor.cpp
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 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "../Game_local.h"
33 
36 
37 /*
38 ================
39 idPhysics_Actor::idPhysics_Actor
40 ================
41 */
43  clipModel = NULL;
44  SetClipModelAxis();
45  mass = 100.0f;
46  invMass = 1.0f / mass;
47  masterEntity = NULL;
48  masterYaw = 0.0f;
49  masterDeltaYaw = 0.0f;
50  groundEntityPtr = NULL;
51 }
52 
53 /*
54 ================
55 idPhysics_Actor::~idPhysics_Actor
56 ================
57 */
59  if ( clipModel ) {
60  delete clipModel;
61  clipModel = NULL;
62  }
63 }
64 
65 /*
66 ================
67 idPhysics_Actor::Save
68 ================
69 */
70 void idPhysics_Actor::Save( idSaveGame *savefile ) const {
71 
72  savefile->WriteClipModel( clipModel );
73  savefile->WriteMat3( clipModelAxis );
74 
75  savefile->WriteFloat( mass );
76  savefile->WriteFloat( invMass );
77 
78  savefile->WriteObject( masterEntity );
79  savefile->WriteFloat( masterYaw );
80  savefile->WriteFloat( masterDeltaYaw );
81 
82  groundEntityPtr.Save( savefile );
83 }
84 
85 /*
86 ================
87 idPhysics_Actor::Restore
88 ================
89 */
91 
92  savefile->ReadClipModel( clipModel );
93  savefile->ReadMat3( clipModelAxis );
94 
95  savefile->ReadFloat( mass );
96  savefile->ReadFloat( invMass );
97 
98  savefile->ReadObject( reinterpret_cast<idClass *&>( masterEntity ) );
99  savefile->ReadFloat( masterYaw );
100  savefile->ReadFloat( masterDeltaYaw );
101 
102  groundEntityPtr.Restore( savefile );
103 }
104 
105 /*
106 ================
107 idPhysics_Actor::SetClipModelAxis
108 ================
109 */
111  // align clip model to gravity direction
112  if ( ( gravityNormal[2] == -1.0f ) || ( gravityNormal == vec3_zero ) ) {
114  }
115  else {
117  clipModelAxis[2].NormalVectors( clipModelAxis[0], clipModelAxis[1] );
118  clipModelAxis[1] = -clipModelAxis[1];
119  }
120 
121  if ( clipModel ) {
123  }
124 }
125 
126 /*
127 ================
128 idPhysics_Actor::GetGravityAxis
129 ================
130 */
132  return clipModelAxis;
133 }
134 
135 /*
136 ================
137 idPhysics_Actor::GetMasterDeltaYaw
138 ================
139 */
141  return masterDeltaYaw;
142 }
143 
144 /*
145 ================
146 idPhysics_Actor::GetGroundEntity
147 ================
148 */
150  return groundEntityPtr.GetEntity();
151 }
152 
153 /*
154 ================
155 idPhysics_Actor::SetClipModel
156 ================
157 */
158 void idPhysics_Actor::SetClipModel( idClipModel *model, const float density, int id, bool freeOld ) {
159  assert( self );
160  assert( model ); // a clip model is required
161  assert( model->IsTraceModel() ); // and it should be a trace model
162  assert( density > 0.0f ); // density should be valid
163 
164  if ( clipModel && clipModel != model && freeOld ) {
165  delete clipModel;
166  }
167  clipModel = model;
169 }
170 
171 /*
172 ================
173 idPhysics_Actor::GetClipModel
174 ================
175 */
177  return clipModel;
178 }
179 
180 /*
181 ================
182 idPhysics_Actor::GetNumClipModels
183 ================
184 */
186  return 1;
187 }
188 
189 /*
190 ================
191 idPhysics_Actor::SetMass
192 ================
193 */
194 void idPhysics_Actor::SetMass( float _mass, int id ) {
195  assert( _mass > 0.0f );
196  mass = _mass;
197  invMass = 1.0f / _mass;
198 }
199 
200 /*
201 ================
202 idPhysics_Actor::GetMass
203 ================
204 */
205 float idPhysics_Actor::GetMass( int id ) const {
206  return mass;
207 }
208 
209 /*
210 ================
211 idPhysics_Actor::SetClipMask
212 ================
213 */
214 void idPhysics_Actor::SetContents( int contents, int id ) {
215  clipModel->SetContents( contents );
216 }
217 
218 /*
219 ================
220 idPhysics_Actor::SetClipMask
221 ================
222 */
223 int idPhysics_Actor::GetContents( int id ) const {
224  return clipModel->GetContents();
225 }
226 
227 /*
228 ================
229 idPhysics_Actor::GetBounds
230 ================
231 */
232 const idBounds &idPhysics_Actor::GetBounds( int id ) const {
233  return clipModel->GetBounds();
234 }
235 
236 /*
237 ================
238 idPhysics_Actor::GetAbsBounds
239 ================
240 */
241 const idBounds &idPhysics_Actor::GetAbsBounds( int id ) const {
242  return clipModel->GetAbsBounds();
243 }
244 
245 /*
246 ================
247 idPhysics_Actor::IsPushable
248 ================
249 */
250 bool idPhysics_Actor::IsPushable( void ) const {
251  return ( masterEntity == NULL );
252 }
253 
254 /*
255 ================
256 idPhysics_Actor::GetOrigin
257 ================
258 */
259 const idVec3 &idPhysics_Actor::GetOrigin( int id ) const {
260  return clipModel->GetOrigin();
261 }
262 
263 /*
264 ================
265 idPhysics_Player::GetAxis
266 ================
267 */
268 const idMat3 &idPhysics_Actor::GetAxis( int id ) const {
269  return clipModel->GetAxis();
270 }
271 
272 /*
273 ================
274 idPhysics_Actor::SetGravity
275 ================
276 */
277 void idPhysics_Actor::SetGravity( const idVec3 &newGravity ) {
278  if ( newGravity != gravityVector ) {
279  idPhysics_Base::SetGravity( newGravity );
281  }
282 }
283 
284 /*
285 ================
286 idPhysics_Actor::ClipTranslation
287 ================
288 */
289 void idPhysics_Actor::ClipTranslation( trace_t &results, const idVec3 &translation, const idClipModel *model ) const {
290  if ( model ) {
291  gameLocal.clip.TranslationModel( results, clipModel->GetOrigin(), clipModel->GetOrigin() + translation,
292  clipModel, clipModel->GetAxis(), clipMask,
293  model->Handle(), model->GetOrigin(), model->GetAxis() );
294  }
295  else {
296  gameLocal.clip.Translation( results, clipModel->GetOrigin(), clipModel->GetOrigin() + translation,
297  clipModel, clipModel->GetAxis(), clipMask, self );
298  }
299 }
300 
301 /*
302 ================
303 idPhysics_Actor::ClipRotation
304 ================
305 */
306 void idPhysics_Actor::ClipRotation( trace_t &results, const idRotation &rotation, const idClipModel *model ) const {
307  if ( model ) {
308  gameLocal.clip.RotationModel( results, clipModel->GetOrigin(), rotation,
309  clipModel, clipModel->GetAxis(), clipMask,
310  model->Handle(), model->GetOrigin(), model->GetAxis() );
311  }
312  else {
313  gameLocal.clip.Rotation( results, clipModel->GetOrigin(), rotation,
314  clipModel, clipModel->GetAxis(), clipMask, self );
315  }
316 }
317 
318 /*
319 ================
320 idPhysics_Actor::ClipContents
321 ================
322 */
323 int idPhysics_Actor::ClipContents( const idClipModel *model ) const {
324  if ( model ) {
326  model->Handle(), model->GetOrigin(), model->GetAxis() );
327  }
328  else {
330  }
331 }
332 
333 /*
334 ================
335 idPhysics_Actor::DisableClip
336 ================
337 */
339  clipModel->Disable();
340 }
341 
342 /*
343 ================
344 idPhysics_Actor::EnableClip
345 ================
346 */
348  clipModel->Enable();
349 }
350 
351 /*
352 ================
353 idPhysics_Actor::UnlinkClip
354 ================
355 */
357  clipModel->Unlink();
358 }
359 
360 /*
361 ================
362 idPhysics_Actor::LinkClip
363 ================
364 */
367 }
368 
369 /*
370 ================
371 idPhysics_Actor::EvaluateContacts
372 ================
373 */
375 
376  // get all the ground contacts
377  ClearContacts();
380 
381  return ( contacts.Num() != 0 );
382 }
void SetClipModel(idClipModel *model, float density, int id=0, bool freeOld=true)
int GetContents(void) const
Definition: Clip.h:170
int GetContents(int id=-1) const
assert(prefInfo.fullscreenBtn)
void Link(idClip &clp)
Definition: Clip.cpp:545
void Restore(idRestoreGame *savefile)
Definition: Game_local.h:661
void WriteObject(const idClass *obj)
Definition: SaveGame.cpp:329
idClip clip
Definition: Game_local.h:296
void SetContents(int newContents)
Definition: Clip.h:166
bool EvaluateContacts(void)
type * GetEntity(void) const
Definition: Game_local.h:695
void SetMass(float mass, int id=-1)
void Save(idSaveGame *savefile) const
void LinkClip(void)
const idMat3 & GetAxis(void) const
Definition: Clip.h:210
void DisableClip(void)
Definition: Vector.h:316
const idVec3 & GetOrigin(void) const
Definition: Clip.h:206
void ClipRotation(trace_t &results, const idRotation &rotation, const idClipModel *model) const
void Identity(void)
Definition: Matrix.h:591
void WriteClipModel(const class idClipModel *clipModel)
Definition: SaveGame.cpp:744
const idVec3 & GetOrigin(int id=0) const
void SetContents(int contents, int id=-1)
idEntity * self
Definition: Physics_Base.h:145
idClipModel * GetClipModel(int id=0) const
bool IsPushable(void) const
void SetClipModelAxis(void)
void UnlinkClip(void)
void ReadFloat(float &value)
Definition: SaveGame.cpp:967
#define vec3_zero
Definition: Vector.h:390
void ClipTranslation(trace_t &results, const idVec3 &translation, const idClipModel *model) const
void WriteFloat(const float value)
Definition: SaveGame.cpp:213
idEntity * masterEntity
idMat3 clipModelAxis
Definition: Physics_Actor.h:98
cmHandle_t Handle(void) const
Definition: Clip.cpp:457
#define NULL
Definition: Lib.h:88
const idBounds & GetBounds(void) const
Definition: Clip.h:198
bool IsTraceModel(void) const
Definition: Clip.h:218
void AddGroundContacts(const idClipModel *clipModel)
idGameLocal gameLocal
Definition: Game_local.cpp:64
#define END_CLASS
Definition: Class.h:54
const idBounds & GetAbsBounds(int id=-1) const
const idMat3 & GetAxis(int id=0) const
float GetMasterDeltaYaw(void) const
void WriteMat3(const idMat3 &mat)
Definition: SaveGame.cpp:309
idList< contactInfo_t > contacts
Definition: Physics_Base.h:149
int ClipContents(const idClipModel *model) const
void ReadMat3(idMat3 &mat)
Definition: SaveGame.cpp:1064
void AddContactEntitiesForContacts(void)
void ReadClipModel(idClipModel *&clipModel)
Definition: SaveGame.cpp:1519
Definition: Matrix.h:333
idVec3 gravityNormal
Definition: Physics_Base.h:148
idEntity * GetGroundEntity(void) const
void SetGravity(const idVec3 &newGravity)
void Enable(void)
Definition: Clip.h:150
tuple f
Definition: idal.py:89
int Num(void) const
Definition: List.h:265
bool Rotation(trace_t &results, const idVec3 &start, const idRotation &rotation, const idClipModel *mdl, const idMat3 &trmAxis, int contentMask, const idEntity *passEntity)
Definition: Clip.cpp:1130
int Contents(const idVec3 &start, const idClipModel *mdl, const idMat3 &trmAxis, int contentMask, const idEntity *passEntity)
Definition: Clip.cpp:1429
void RotationModel(trace_t &results, const idVec3 &start, const idRotation &rotation, const idClipModel *mdl, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)
Definition: Clip.cpp:1506
int ContentsModel(const idVec3 &start, const idClipModel *mdl, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)
Definition: Clip.cpp:1532
#define CLASS_DECLARATION(nameofsuperclass, nameofclass)
Definition: Class.h:110
void Save(idSaveGame *savefile) const
Definition: Game_local.h:656
float GetMass(int id=-1) const
idEntityPtr< idEntity > groundEntityPtr
void ClearContacts(void)
void TranslationModel(trace_t &results, const idVec3 &start, const idVec3 &end, const idClipModel *mdl, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)
Definition: Clip.cpp:1493
idVec3 gravityVector
Definition: Physics_Base.h:147
const idBounds & GetAbsBounds(void) const
Definition: Clip.h:202
idClipModel * clipModel
Definition: Physics_Actor.h:97
const idMat3 & GetGravityAxis(void) const
void Restore(idRestoreGame *savefile)
void Disable(void)
Definition: Clip.h:154
void SetGravity(const idVec3 &newGravity)
bool Translation(trace_t &results, const idVec3 &start, const idVec3 &end, const idClipModel *mdl, const idMat3 &trmAxis, int contentMask, const idEntity *passEntity)
Definition: Clip.cpp:1056
void Unlink(void)
Definition: Clip.cpp:491
const idBounds & GetBounds(int id=-1) const
void ReadObject(idClass *&obj)
Definition: SaveGame.cpp:1083
void EnableClip(void)
int GetNumClipModels(void) const