ScummVM API documentation
PhysicsController.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/*
23 * Copyright (C) 2006-2010 - Frictional Games
24 *
25 * This file is part of HPL1 Engine.
26 */
27
28#ifndef HPL_PHYSICS_CONTROLLER_H
29#define HPL_PHYSICS_CONTROLLER_H
30
31#include "hpl1/engine/math/MathTypes.h"
32#include "hpl1/engine/math/PidController.h"
33#include "hpl1/engine/math/Spring.h"
34
35#include "hpl1/engine/game/SaveGame.h"
36
37namespace hpl {
38
39//-------------------------------------------
40
41enum ePhysicsControllerType {
42 ePhysicsControllerType_Pid,
43 ePhysicsControllerType_Spring,
44 ePhysicsControllerType_LastEnum
45};
46
47//-------------------------------------------
48
49enum ePhysicsControllerInput {
50 ePhysicsControllerInput_JointAngle,
51 ePhysicsControllerInput_JointDist,
52 ePhysicsControllerInput_LinearSpeed,
53 ePhysicsControllerInput_AngularSpeed,
54 ePhysicsControllerInput_LastEnum
55};
56
57//-------------------------------------------
58
59enum ePhysicsControllerOutput {
60 ePhysicsControllerOutput_Force,
61 ePhysicsControllerOutput_Torque,
62 ePhysicsControllerOutput_LastEnum
63};
64
65//-------------------------------------------
66
67enum ePhysicsControllerAxis {
68 ePhysicsControllerAxis_X,
69 ePhysicsControllerAxis_Y,
70 ePhysicsControllerAxis_Z,
71 ePhysicsControllerAxis_LastEnum
72};
73
74//-------------------------------------------
75
76enum ePhysicsControllerEnd {
77 ePhysicsControllerEnd_Null,
78 ePhysicsControllerEnd_OnDest,
79 ePhysicsControllerEnd_OnMin,
80 ePhysicsControllerEnd_OnMax,
81 ePhysicsControllerEnd_LastEnum
82};
83
84//-------------------------------------------
85
86kSaveData_BaseClass(iPhysicsController) {
87 kSaveData_ClassInit(iPhysicsController) public : tString msName;
88
89 int mlBodyId;
90 int mlJointId;
91
92 float mfA;
93 float mfB;
94 float mfC;
95 float mfDestValue;
96 float mfMaxOutput;
97
98 bool mbMulMassWithOutput;
99
100 int mType;
101 int mInputType;
102 int mInputAxis;
103 int mOutputType;
104 int mOutputAxis;
105 int mEndType;
106
107 tString msNextController;
108
109 bool mbActive;
110 bool mbPaused;
111
112 iSaveObject *CreateSaveObject(cSaveObjectHandler * apSaveObjectHandler, cGame * apGame) { return NULL; }
113 int GetSaveCreatePrio() { return 0; }
114};
115
116//-------------------------------------------
117
118class iPhysicsWorld;
119class iPhysicsJoint;
120class iPhysicsBody;
121
123 typedef iSaveObject super;
124
125public:
126 iPhysicsController(const tString &asName, iPhysicsWorld *apWorld);
127 virtual ~iPhysicsController();
128
129 void Update(float afTimeStep);
130
131 const tString &GetName() { return msName; }
132
133 void SetJoint(iPhysicsJoint *apJoint) { mpJoint = apJoint; }
134 iPhysicsJoint *GetJoint() { return mpJoint; }
135 void SetBody(iPhysicsBody *apBody) { mpBody = apBody; }
136 iPhysicsBody *GetBody() { return mpBody; }
137
138 bool IsActive() { return mbActive; }
139 void SetActive(bool abX);
140
141 /*
142 * p in Pid and k in springs
143 */
144 void SetA(float afA) { mfA = afA; }
145 /*
146 * i in Pid and b in springs
147 */
148 void SetB(float afB) { mfB = afB; }
149 /*
150 * d in Pid and not used in springs
151 */
152 void SetC(float afC) { mfC = afC; }
153
154 void SetPidIntegralSize(int alSize);
155
156 void SetType(ePhysicsControllerType aType) { mType = aType; }
157
158 void SetDestValue(float afX) { mfDestValue = afX; }
159 float GetDestValue() { return mfDestValue; }
160
161 void SetMaxOutput(float afX) { mfMaxOutput = afX; }
162
163 void SetInputType(ePhysicsControllerInput aInput, ePhysicsControllerAxis aAxis) {
164 mInputType = aInput;
165 mInputAxis = aAxis;
166 }
167
168 void SetOutputType(ePhysicsControllerOutput aOutput, ePhysicsControllerAxis aAxis) {
169 mOutputType = aOutput;
170 mOutputAxis = aAxis;
171 }
172 void SetMulMassWithOutput(bool abX) { mbMulMassWithOutput = abX; }
173
174 void SetEndType(ePhysicsControllerEnd aEnd) { mEndType = aEnd; }
175 ePhysicsControllerEnd GetEndType() { return mEndType; }
176
177 void SetNextController(const tString &asName) { msNextController = asName; }
178 const tString &GetNextController() { return msNextController; }
179
180 void SetLogInfo(bool abX) { mbLogInfo = abX; }
181
182 void SetPaused(bool abX) { mbPaused = abX; }
183
184 static bool mbUseInputMatrixFix;
185
186 // SaveObject implementation
188 virtual void SaveToSaveData(iSaveData *apSaveData);
189 virtual void LoadFromSaveData(iSaveData *apSaveData);
190 virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame);
191
192protected:
193 cVector3f GetInputValue(ePhysicsControllerInput aInput);
194 float GetOutputValue(float afError, float afInput, float afTimeStep);
195 void AddOutputValue(ePhysicsControllerOutput aOutput, ePhysicsControllerAxis aAxis,
196 float afVal);
197 float GetAxisValue(ePhysicsControllerAxis aAxis, const cVector3f &avVec);
198
199 iPhysicsWorld *mpWorld;
200 tString msName;
201
202 iPhysicsBody *mpBody;
203 iPhysicsJoint *mpJoint;
204
205 float mfA, mfB, mfC;
206
207 float mfDestValue;
208 float mfMaxOutput;
209
210 bool mbMulMassWithOutput;
211
212 ePhysicsControllerType mType;
213
214 ePhysicsControllerInput mInputType;
215 ePhysicsControllerAxis mInputAxis;
216
217 ePhysicsControllerOutput mOutputType;
218 ePhysicsControllerAxis mOutputAxis;
219
220 ePhysicsControllerEnd mEndType;
221
222 tString msNextController;
223
224 cPidControllerf mPidController;
225
226 bool mbActive;
227 bool mbPaused;
228
229 bool mbLogInfo;
230};
231
232} // namespace hpl
233
234#endif // HPL_PHYSICS_CONTROLLER_H
Definition: str.h:59
Definition: Game.h:91
Definition: SaveGame.h:183
Definition: PhysicsBody.h:117
Definition: PhysicsController.h:122
virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame)
virtual void LoadFromSaveData(iSaveData *apSaveData)
virtual iSaveData * CreateSaveData()
virtual void SaveToSaveData(iSaveData *apSaveData)
Definition: PhysicsJoint.h:135
Definition: PhysicsWorld.h:115
Definition: SaveGame.h:111
Definition: SaveGame.h:130