]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/d3xp/physics/Force_Constant.cpp
hello world
[icculus/iodoom3.git] / neo / d3xp / physics / Force_Constant.cpp
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
34 CLASS_DECLARATION( idForce, idForce_Constant )
35 END_CLASS
36
37 /*
38 ================
39 idForce_Constant::idForce_Constant
40 ================
41 */
42 idForce_Constant::idForce_Constant( void ) {
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 */
54 idForce_Constant::~idForce_Constant( void ) {
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 */
73 void idForce_Constant::Restore( idRestoreGame *savefile ) {
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 */
105 void idForce_Constant::SetPhysics( idPhysics *physics ) {
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 */
131 void idForce_Constant::RemovePhysics( const idPhysics *phys ) {
132         if ( physics == phys ) {
133                 physics = NULL;
134         }
135 }