doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Force_Constant.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 idForce_Constant::idForce_Constant
40 ================
41 */
43  force = vec3_zero;
44  physics = NULL;
45  id = 0;
46  point = vec3_zero;
47 }
48 
49 /*
50 ================
51 idForce_Constant::~idForce_Constant
52 ================
53 */
55 }
56 
57 /*
58 ================
59 idForce_Constant::Save
60 ================
61 */
62 void idForce_Constant::Save( idSaveGame *savefile ) const {
63  savefile->WriteVec3( force );
64  savefile->WriteInt( id );
65  savefile->WriteVec3( point );
66 }
67 
68 /*
69 ================
70 idForce_Constant::Restore
71 ================
72 */
74  // Owner needs to call SetPhysics!!
75  savefile->ReadVec3( force );
76  savefile->ReadInt( id );
77  savefile->ReadVec3( point );
78 }
79 
80 /*
81 ================
82 idForce_Constant::SetPosition
83 ================
84 */
85 void idForce_Constant::SetPosition( idPhysics *physics, int id, const idVec3 &point ) {
86  this->physics = physics;
87  this->id = id;
88  this->point = point;
89 }
90 
91 /*
92 ================
93 idForce_Constant::SetForce
94 ================
95 */
96 void idForce_Constant::SetForce( const idVec3 &force ) {
97  this->force = force;
98 }
99 
100 /*
101 ================
102 idForce_Constant::SetPhysics
103 ================
104 */
106  this->physics = physics;
107 }
108 
109 /*
110 ================
111 idForce_Constant::Evaluate
112 ================
113 */
114 void idForce_Constant::Evaluate( int time ) {
115  idVec3 p;
116 
117  if ( !physics ) {
118  return;
119  }
120 
121  p = physics->GetOrigin( id ) + point * physics->GetAxis( id );
122 
123  physics->AddForce( id, p, force );
124 }
125 
126 /*
127 ================
128 idForce_Constant::RemovePhysics
129 ================
130 */
132  if ( physics == phys ) {
133  physics = NULL;
134  }
135 }
virtual const idVec3 & GetOrigin(int id=0) const =0
void Save(idSaveGame *savefile) const
idPhysics * physics
void Restore(idRestoreGame *savefile)
Definition: Force.h:45
Definition: Vector.h:316
void WriteVec3(const idVec3 &vec)
Definition: SaveGame.cpp:253
virtual void AddForce(const int id, const idVec3 &point, const idVec3 &force)=0
#define vec3_zero
Definition: Vector.h:390
#define NULL
Definition: Lib.h:88
virtual void RemovePhysics(const idPhysics *phys)
virtual const idMat3 & GetAxis(int id=0) const =0
#define END_CLASS
Definition: Class.h:54
void SetPosition(idPhysics *physics, int id, const idVec3 &point)
void WriteInt(const int value)
Definition: SaveGame.cpp:168
void SetForce(const idVec3 &force)
virtual void Evaluate(int time)
#define CLASS_DECLARATION(nameofsuperclass, nameofclass)
Definition: Class.h:110
void ReadVec3(idVec3 &vec)
Definition: SaveGame.cpp:1011
virtual ~idForce_Constant(void)
GLfloat GLfloat p
Definition: glext.h:4674
void SetPhysics(idPhysics *physics)
void ReadInt(int &value)
Definition: SaveGame.cpp:922