ScummVM API documentation
CharacterBody.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_CHARACTER_BODY_H
29#define HPL_CHARACTER_BODY_H
30
31#include "hpl1/engine/math/MathTypes.h"
32#include "hpl1/engine/physics/PhysicsWorld.h"
33
34namespace hpl {
35
36class iPhysicsWorld;
37class iCollideShape;
38class iPhysicsBody;
39class cCamera3D;
40class iCharacterBody;
41class iEntity3D;
42
43enum eCharDir {
44 eCharDir_Forward = 0,
45 eCharDir_Right = 1,
46 eCharDir_LastEnum = 2
47};
48
50public:
51 virtual ~iCharacterBodyCallback() = default;
52 virtual void OnHitGround(iCharacterBody *apCharBody, const cVector3f &avVel) = 0;
53 virtual void OnGravityCollide(iCharacterBody *apCharBody, iPhysicsBody *apCollideBody,
54 cCollideData *apCollideData) = 0;
55};
56
57//------------------------------------------------
58
60public:
62
63 void Clear();
64 bool OnIntersect(iPhysicsBody *pBody, cPhysicsRayParams *apParams);
65
66 float mfMinDist;
67 bool mbCollide;
68};
69
70//------------------------------------------------
71
73public:
75
76 void OnCollision(iPhysicsBody *apBody, cCollideData *apCollideData);
77
78 iCharacterBody *mpCharBody;
79};
80
81//------------------------------------------------
82
84public:
86
87 void OnCollision(iPhysicsBody *apBody, cCollideData *apCollideData);
88
89 iCharacterBody *mpCharBody;
90};
91
92//-----------------------------------
93
94kSaveData_BaseClass(iCharacterBody) {
95 kSaveData_ClassInit(iCharacterBody) public : tString msName;
96
97 float mfMass;
98 bool mbGravityActive;
99 float mfMaxGravitySpeed;
100
101 bool mbActive;
102
103 bool mbCollideCharacter;
104
105 cVector3f mvPosition;
106 cVector3f mvLastPosition;
107 float mfMaxPosMoveSpeed[2];
108 float mfMaxNegMoveSpeed[2];
109 float mfMoveSpeed[2];
110 float mfMoveAcc[2];
111 float mfMoveDeacc[2];
112 bool mbMoving[2];
113
114 float mfPitch;
115 float mfYaw;
116
117 bool mbOnGround;
118
119 float mfMaxPushMass;
120 float mfPushForce;
121 bool mbPushIn2D;
122
123 cVector3f mvForce;
124 cVector3f mvVelolcity;
125
126 cVector3f mvSize;
127
128 cMatrixf m_mtxMove;
129
130 int mlEntityId;
131 cMatrixf m_mtxEntityOffset;
132 int mlEntitySmoothPosNum;
133
134 float mfMaxStepHeight;
135 float mfStepClimbSpeed;
136 float mfClimbForwardMul;
137 float mfClimbHeightAdd;
138 bool mbClimbing;
139
140 float mfGroundFriction;
141 float mfAirFriction;
142
143 int mlBodyId;
144
145 cContainerList<int> mvExtraBodyIds;
146
147 virtual iSaveObject *CreateSaveObject(cSaveObjectHandler * apSaveObjectHandler, cGame * apGame);
148 virtual int GetSaveCreatePrio();
149};
150
151//------------------------------------------------
152
154 typedef iSaveObject super;
155 friend class cSaveData_iCharacterBody;
156 friend class cCharacterBodyCollideGravity;
157
158public:
159 iCharacterBody(const tString &asName, iPhysicsWorld *apWorld, const cVector3f avSize);
160 virtual ~iCharacterBody();
161
162 const tString &GetName() { return msName; }
163
165 // Properties
166
167 float GetMass();
168 void SetMass(float afMass);
169
170 void SetActive(bool abX);
171 bool IsActive() { return mbActive; }
172
173 cVector3f GetSize();
174
175 void SetCollideCharacter(bool abX);
176 bool GetCollideCharacter() { return mbCollideCharacter; }
177
178 void SetTestCollision(bool abX) { mbTestCollision = abX; }
179 bool GetTestCollision() { return mbTestCollision; }
180
181 void SetMaxPositiveMoveSpeed(eCharDir aDir, float afX);
182 float GetMaxPositiveMoveSpeed(eCharDir aDir);
183 void SetMaxNegativeMoveSpeed(eCharDir aDir, float afX);
184 float GetMaxNegativeMoveSpeed(eCharDir aDir);
185
186 void SetMoveSpeed(eCharDir aDir, float afX);
187 float GetMoveSpeed(eCharDir aDir);
188 void SetMoveAcc(eCharDir aDir, float afX);
189 float GetMoveAcc(eCharDir aDir);
190 void SetMoveDeacc(eCharDir aDir, float afX);
191 float GetMoveDeacc(eCharDir aDir);
192
193 cVector3f GetVelocity(float afFrameTime);
194
195 void SetPosition(const cVector3f &avPos, bool abSmooth = false);
196 const cVector3f &GetPosition();
197 const cVector3f &GetLastPosition();
198 void SetFeetPosition(const cVector3f &avPos, bool abSmooth = false);
199 cVector3f GetFeetPosition();
200
201 void SetYaw(float afX);
202 void AddYaw(float afX);
203 float GetYaw();
204 void SetPitch(float afX);
205 void AddPitch(float afX);
206 float GetPitch();
207
208 cVector3f GetForward();
209 cVector3f GetRight();
210 cVector3f GetUp();
211
212 cMatrixf &GetMoveMatrix();
213
214 void SetGravityActive(bool abX);
215 bool GravityIsActive();
216 void SetMaxGravitySpeed(float afX);
217 float GetMaxGravitySpeed();
218
219 bool GetCustomGravityActive();
220 void SetCustomGravityActive(bool abX);
221 void SetCustomGravity(const cVector3f &avCustomGravity);
222 cVector3f GetCustomGravity();
223
224 void SetMaxPushMass(float afX) { mfMaxPushMass = afX; }
225 void SetPushForce(float afX) { mfPushForce = afX; }
226 float GetMaxPushMass() { return mfMaxPushMass; }
227 float GetPushForce() { return mfPushForce; }
228
229 bool GetPushIn2D() { return mbPushIn2D; }
230 void SetPushIn2D(bool abX) { mbPushIn2D = abX; }
231
232 void AddForceVelocity(const cVector3f &avVel) { mvVelolcity += avVel; }
233 void SetForceVelocity(const cVector3f &avVel) { mvVelolcity = avVel; }
234 cVector3f GetForceVelocity() { return mvVelolcity; }
235
236 int AddExtraSize(const cVector3f &avSize);
237 void SetActiveSize(int alNum);
238
240 // Actions
241 void SetForce(const cVector3f &avForce);
242 void AddForce(const cVector3f &avForce);
243 cVector3f GetForce();
244
245 void Move(eCharDir aDir, float afMul, float afTimeStep);
246
247 void Update(float afTimeStep);
248
250 // Other
251 void SetCamera(cCamera3D *apCam);
252 cCamera3D *GetCamera();
253 void SetCameraPosAdd(const cVector3f &avAdd);
254 cVector3f GetCameraPosAdd();
255 void SetCameraSmoothPosNum(int alNum) { mlCameraSmoothPosNum = alNum; }
256 int GetCameraSmoothPosNum() { return mlCameraSmoothPosNum; }
257
258 void SetEntity(iEntity3D *apEntity);
259 iEntity3D *GetEntity();
260
261 void SetEntityOffset(const cMatrixf &a_mtxOffset);
262 const cMatrixf &GetEntityOffset();
263
264 void SetEntityPostOffset(const cMatrixf &a_mtxOffset);
265 const cMatrixf &GetEntityPostOffset();
266
267 void SetEntitySmoothPosNum(int alNum) { mlEntitySmoothPosNum = alNum; }
268 int GetEntitySmoothPosNum() { return mlEntitySmoothPosNum; }
269
270 void SetUserData(void *apUserData) { mpUserData = apUserData; }
271 void *GetUserData() { return mpUserData; }
272
273 void SetCallback(iCharacterBodyCallback *apCallback) { mpCallback = apCallback; }
274
275 void SetEnableNearbyBodies(bool abX) { mbEnableNearbyBodies = abX; }
276 bool GetEnableNearbyBodies() { return mbEnableNearbyBodies; }
277
278 iPhysicsBody *GetBody() { return mpBody; }
279 iCollideShape *GetShape();
280
281 iPhysicsBody *GetExtraBody(size_t alIdx) { return mvExtraBodies[alIdx]; }
282
283 bool IsOnGround();
284
285 float GetMaxStepSize() { return mfMaxStepHeight; }
286 void SetMaxStepSize(float afSize) { mfMaxStepHeight = afSize; }
287
288 void SetStepClimbSpeed(float afX) { mfStepClimbSpeed = afX; }
289 float GetStepClimbSpeed() { return mfStepClimbSpeed; }
290
291 void SetAccurateClimbing(bool abX) { mbAccurateClimbing = abX; }
292 bool GetAccurateClimbing() { return mbAccurateClimbing; }
293
294 void SetClimbForwardMul(float afX) { mfClimbForwardMul = afX; }
295 float GetClimbForwardMul() { return mfClimbForwardMul; }
296
297 void SetClimbHeightAdd(float afX) { mfClimbHeightAdd = afX; }
298 float GetClimbHeightAdd() { return mfClimbHeightAdd; }
299
300 void SetGroundFriction(float afX) { mfGroundFriction = afX; }
301 float GetGroundFriction() { return mfGroundFriction; }
302
303 void SetAirFriction(float afX) { mfAirFriction = afX; }
304 float GetAirFriction() { return mfAirFriction; }
305
306 bool IsClimbing() { return mbClimbing; }
307
308 void SetAttachedBody(iPhysicsBody *apBody);
309 iPhysicsBody *GetAttachedBody() { return mpAttachedBody; }
310
311 // O=nly sue when you know what you are doing, Update calls these
312 void UpdateMoveMarix();
313
314 void UpdateCamera();
315 void UpdateEntity();
316
317 void UpdateAttachment();
318
319 // SaveObject implementation
321 virtual void SaveToSaveData(iSaveData *apSaveData);
322 virtual void LoadFromSaveData(iSaveData *apSaveData);
323 virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame);
324
325protected:
326 tString msName;
327
328 float mfMass;
329
330 bool mbActive;
331
332 bool mbCollideCharacter;
333
334 bool mbTestCollision;
335
336 bool mbGravityActive;
337 float mfMaxGravitySpeed;
338 bool mbCustomGravity;
339 cVector3f mvCustomGravity;
340
341 cVector3f mvPosition;
342 cVector3f mvLastPosition;
343
344 float mfMaxPosMoveSpeed[2];
345 float mfMaxNegMoveSpeed[2];
346
347 float mfMoveSpeed[2];
348 float mfMoveAcc[2];
349 float mfMoveDeacc[2];
350 bool mbMoving[2];
351
352 float mfPitch;
353 float mfYaw;
354
355 bool mbOnGround;
356
357 float mfMaxPushMass;
358 float mfPushForce;
359 bool mbPushIn2D;
360
361 float mfCheckStepClimbCount;
362 float mfCheckStepClimbInterval;
363
364 cVector3f mvForce;
365 cVector3f mvVelolcity;
366
367 cVector3f mvSize;
368
369 cMatrixf m_mtxMove;
370
371 cCamera3D *mpCamera;
372 cVector3f mvCameraPosAdd;
373 int mlCameraSmoothPosNum;
374 tVector3fList mlstCameraPos;
375
376 iEntity3D *mpEntity;
377 cMatrixf m_mtxEntityOffset;
378 cMatrixf m_mtxEntityPostOffset;
379 int mlEntitySmoothPosNum;
380 tVector3fList mlstEntityPos;
381
382 float mfGroundFriction;
383 float mfAirFriction;
384
385 void *mpUserData;
386
387 iPhysicsBody *mpAttachedBody;
388 cMatrixf m_mtxAttachedPrevMatrix;
389 bool mbAttachmentJustAdded;
390
391 iCharacterBodyCallback *mpCallback;
392
393 cCharacterBodyRay *mpRayCallback;
394
395 cCharacterBodyCollideGravity *mpCollideCallbackGravity;
396 cCharacterBodyCollidePush *mpCollideCallbackPush;
397
398 float mfMaxStepHeight;
399 float mfStepClimbSpeed;
400 float mfClimbForwardMul;
401 float mfClimbHeightAdd;
402 bool mbClimbing;
403 bool mbAccurateClimbing;
404
405 bool mbEnableNearbyBodies;
406
407 iPhysicsBody *mpBody;
408 iPhysicsWorld *mpWorld;
409
410 Common::Array<iPhysicsBody *> mvExtraBodies;
411};
412
413} // namespace hpl
414
415#endif // HPL_CHARACTER_BODY_H
Definition: str.h:59
Definition: Camera3D.h:53
Definition: CharacterBody.h:72
Definition: CharacterBody.h:83
Definition: CharacterBody.h:59
Definition: CollideData.h:46
Definition: Container.h:219
Definition: Game.h:91
Definition: SaveGame.h:183
Definition: CharacterBody.h:49
Definition: CharacterBody.h:153
virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame)
virtual void SaveToSaveData(iSaveData *apSaveData)
virtual iSaveData * CreateSaveData()
virtual void LoadFromSaveData(iSaveData *apSaveData)
Definition: CollideShape.h:50
Definition: Entity3D.h:81
Definition: PhysicsBody.h:117
Definition: PhysicsWorld.h:100
Definition: PhysicsWorld.h:107
Definition: PhysicsWorld.h:115
Definition: SaveGame.h:111
Definition: SaveGame.h:130
Definition: PhysicsWorld.h:92