ScummVM API documentation
Body2D.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_BODY_H
29 #define HPL_BODY_H
30 
31 #include "hpl1/engine/math/MathTypes.h"
32 
33 #include "common/list.h"
34 #include "hpl1/engine/scene/Entity2D.h"
35 #include "common/stablemap.h"
36 
37 namespace hpl {
38 
39 class cMesh2D;
40 class cNode2D;
41 class cCollider2D;
42 class cCollisionMesh2D;
43 
44 class cBody2D;
45 
46 typedef Common::List<cBody2D *> tBody2DList;
47 typedef tBody2DList::iterator tBody2DListIt;
48 
49 class cBody2D : public iEntity2D {
50 public:
51  cBody2D(const tString &asName, cMesh2D *apMesh, cVector2f avSize, cCollider2D *apCollider, int alID);
52  ~cBody2D();
53 
54  const cRect2f &GetBoundingBox();
55  bool UpdateBoundingBox();
56 
57  void Move(float afValue);
58 
59  void UpdateLogic(float afTimeStep);
60 
61  tString GetEntityType() { return "Body"; };
62 
63  cVector3f &GetPosition() { return mvPosition; }
64  cVector3f &GetLastPosition() { return mvLastPosition; }
65  void ResetLastPosition() { mvLastPosition = mvPosition; }
66 
67  float GetVelocity();
68  float GetMaxVelocity() { return mfMaxVel; }
69  float GetAcceleration() { return mfAcc; }
70  float GetGravity() { return mfGravity; }
71  float GetMaxGravityVel() { return mfMaxGravityVel; }
72  bool GetCollidable() { return mbCollidable; }
73  bool GetCollides() { return mbCollides; }
74  float GetAirFriction() { return mfAirFriction; }
75  float GetGroundFriction() { return mfGroundFriction; }
76  const cVector2f &GetSize() { return mvSize; }
77 
78  const cVector3f &GetMovement() { return mvMovement; }
79 
80  void SetMaxVelocity(float afMaxVel) { mfMaxVel = afMaxVel; }
81  void SetAcceleration(float afAcc) { mfAcc = afAcc; }
82  void SetGravity(float afGravity) { mfGravity = afGravity; }
83  void SetMaxGravityVel(float afMaxGravityVel) { mfMaxGravityVel = afMaxGravityVel; }
84  void SetCollidable(bool abCollidable) { mbCollidable = abCollidable; }
85  void SetCollides(bool abCollides) { mbCollides = abCollides; }
86  void SetAirFriction(float afAirFriction) { mfAirFriction = afAirFriction; }
87  void SetGroundFriction(float afGroundFriction) { mfGroundFriction = afGroundFriction; }
88 
89  void AddForce(float afAngle, float afStrength);
90  void AddForce(const cVector2f &avForce);
91 
92  void SetForce(float afAngle, float afStrength);
93  void SetForce(const cVector2f &avForce);
94 
95  const cVector2f &GetForce() const { return mvForce; }
96 
101  void SetCollideFlag(tFlag alFlag) { mlCollideFlag = alFlag; }
102  tFlag GetCollideFlag() { return mlCollideFlag; }
103 
108  void SetAttachToGround(bool abX) { mbAttachToGround = abX; }
109  bool GetAttachToGround() { return mbAttachToGround; }
110 
115  void SetAttachBodies(bool abX) { mbAttachBodies = abX; }
116  bool GetAttachBodies() { return mbAttachBodies; }
117 
118  void AttachBody(cBody2D *apBody);
119  void DetachBody(cBody2D *apBody);
120  void SetParentBody(cBody2D *apBody);
121 
127  void SetCollideType(tFlag alFlag) { mlCollideType = alFlag; }
128  tFlag GetCollideType() { return mlCollideType; }
129 
130  void AttachNode(cNode2D *apNode) { mpNode = apNode; }
131  void DetachNode() { mpNode = NULL; }
132 
133  int GetID() { return mlID; }
134 
135  bool OnGround() { return mbOnGround; }
136 
137  void UpdateCollisionMesh();
138  cCollisionMesh2D *GetCollisionMesh();
139 
140 private:
141  float mfMaxVel;
142  float mfAcc;
143  float mfGravity;
144  float mfMaxGravityVel;
145  float mfAirFriction;
146  float mfGroundFriction;
147 
148  bool mbCollides;
149  bool mbCollidable;
150  bool mbMoved;
151 
152  cVector3f mvMovement;
153 
154  bool mbAttachToGround;
155  bool mbAttachBodies;
156  tBody2DList mlstAttachedBodies;
157  cBody2D *mpParentBody;
158 
159  int mlID;
160 
161  tFlag mlCollideFlag;
162  tFlag mlCollideType;
163 
164  cMesh2D *mpMesh;
165  cCollider2D *mpCollider;
166  cNode2D *mpNode;
167 
168  cCollisionMesh2D *mpCollMesh;
169  cCollisionMesh2D *mpBaseCollMesh;
170 
171  bool mbOnGround;
172  bool mbGroundFrictionX;
173  bool mbGroundFrictionY;
174 
175  cVector2f mvForce;
176  cVector2f mvSize;
177 
178  cVector2l mvCollideCount;
179  cVector2f mvLastCollidePos;
180 
181  void AddPosXY(cVector2f avPosAdd);
182 };
183 
184 } // namespace hpl
185 
186 #endif // HPL_BODY_H
Definition: AI.h:36
Definition: str.h:59
void SetCollideFlag(tFlag alFlag)
Definition: Body2D.h:101
Definition: Body2D.h:49
void SetAttachToGround(bool abX)
Definition: Body2D.h:108
Definition: Collider2D.h:48
Definition: Node2D.h:37
Definition: Mesh2d.h:68
void SetAttachBodies(bool abX)
Definition: Body2D.h:115
ListInternal::Iterator< t_T > iterator
Definition: list.h:52
void SetCollideType(tFlag alFlag)
Definition: Body2D.h:127
Definition: Mesh2d.h:51
Definition: Entity2D.h:39