author | Tero Marttila <terom@fixme.fi> |
Mon, 26 Jan 2009 23:03:47 +0200 | |
changeset 431 | c6d7272a164b |
parent 428 | 712b943195a6 |
permissions | -rw-r--r-- |
197 | 1 |
#ifndef PHYSICS_OBJECT_HH |
2 |
#define PHYSICS_OBJECT_HH |
|
3 |
||
4 |
||
5 |
// Forward declares |
|
6 |
class PhysicsObject; |
|
7 |
struct Derivative; |
|
8 |
||
9 |
#include "PhysicsWorld.hh" |
|
10 |
#include "Vector.hh" |
|
205 | 11 |
#include "Timer.hh" |
197 | 12 |
#include "Config.hh" |
13 |
||
423
947ab54de4b7
fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents:
322
diff
changeset
|
14 |
#include <utility> |
947ab54de4b7
fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents:
322
diff
changeset
|
15 |
#include <queue> |
947ab54de4b7
fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents:
322
diff
changeset
|
16 |
|
197 | 17 |
// Type definitions |
18 |
typedef Vector Force; |
|
320 | 19 |
|
20 |
/** Specifies possible object types. */ |
|
265 | 21 |
enum ObjectType { PLAYER, PROJECTILE, ROPE }; |
197 | 22 |
|
320 | 23 |
/** Specifies possible facing directions for objects. */ |
264 | 24 |
enum FacingDirection { |
25 |
FACING_LEFT, |
|
26 |
FACING_RIGHT |
|
27 |
}; |
|
197 | 28 |
|
29 |
/** |
|
321 | 30 |
* PhysicsObject class. Represents an object in the physics simulation. |
197 | 31 |
*/ |
32 |
class PhysicsObject { |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
33 |
protected: |
320 | 34 |
/** Reference to PhysicsWorld. */ |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
35 |
PhysicsWorld &world; |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
36 |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
37 |
private: |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
38 |
/** Position */ |
197 | 39 |
Vector position; |
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
40 |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
41 |
/** Position at previous tick */ |
285 | 42 |
Vector previousPosition; |
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
43 |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
44 |
/** Velocity */ |
197 | 45 |
Vector velocity; |
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
46 |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
47 |
/** Mass */ |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
48 |
float mass; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
49 |
|
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
50 |
/** Object's shape, polygon vertices */ |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
51 |
std::vector<Vector> shape; |
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
52 |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
53 |
/** Force queue, emptied on every physics tick */ |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
54 |
std::queue<std::pair<Force, TimeMS> > forceq; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
55 |
|
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
56 |
|
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
57 |
protected: |
320 | 58 |
/** Tells if the object is "on the ground" */ |
59 |
bool inAir; |
|
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
60 |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
61 |
/** Object elasticity */ |
197 | 62 |
float collision_elasticity; |
63 |
||
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
64 |
/** Aim angle in radians */ |
320 | 65 |
float aim; |
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
66 |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
67 |
/** Player facing */ |
320 | 68 |
FacingDirection facing; |
197 | 69 |
|
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
70 |
/** Specifies if the object should be simulated */ |
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
71 |
bool alive; |
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
72 |
|
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
73 |
/** True if !alive, and the object can be delete'd */ |
225 | 74 |
bool shouldDelete; |
265 | 75 |
|
320 | 76 |
/** Type of the object */ |
265 | 77 |
ObjectType type; |
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
78 |
|
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
79 |
/** Pivot object for this object */ |
228 | 80 |
PhysicsObject *pivot; |
81 |
||
320 | 82 |
/** |
83 |
* Class constructor |
|
84 |
* |
|
85 |
* @param world Reference to PhysicsWorld |
|
86 |
* @param mass Object mass |
|
87 |
* @param position Object position |
|
88 |
* @param velocity Object velocity |
|
89 |
* @param type Object type |
|
90 |
* @param collision_elasticity Object elasticity |
|
91 |
* @param enabled Is the object currently part of the simulation |
|
92 |
*/ |
|
279
e36f5e1a1c8d
let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents:
273
diff
changeset
|
93 |
PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity, ObjectType type, |
e36f5e1a1c8d
let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents:
273
diff
changeset
|
94 |
float collision_elasticity, bool enabled = true); |
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
95 |
|
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
96 |
/** |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
97 |
* Virtual destructor |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
98 |
*/ |
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
99 |
virtual ~PhysicsObject (void); |
197 | 100 |
|
101 |
/** |
|
320 | 102 |
* Apply a force to the object. The force is applied to the object |
103 |
* on the next physics tick. |
|
197 | 104 |
* |
105 |
* @param force Force vector |
|
106 |
*/ |
|
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
107 |
void applyForce (Force force, TimeMS dt = PHYSICS_TICK_MS); |
197 | 108 |
|
109 |
/** |
|
320 | 110 |
* Change player aim. This function takes care that aim angle |
111 |
* stays inside limits. |
|
197 | 112 |
* |
320 | 113 |
* @param da Aim angle change in radians |
197 | 114 |
*/ |
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
115 |
void changeAim (float da); |
197 | 116 |
|
117 |
/** |
|
118 |
* Set player facing. |
|
119 |
* |
|
120 |
* @param facingRight True if player is facing right. |
|
121 |
*/ |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
122 |
void setFacing (FacingDirection facing) { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
123 |
this->facing = facing; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
124 |
} |
197 | 125 |
|
126 |
/** |
|
127 |
* Makes the player jump in the air. |
|
320 | 128 |
* |
197 | 129 |
* @param direction -1: jump left, 0: jump up, 1: jump right |
130 |
*/ |
|
299 | 131 |
void jump (int direction); |
197 | 132 |
|
133 |
/** |
|
320 | 134 |
* Handle object bounce. |
197 | 135 |
* |
136 |
* @param normal Normal vector relative to which to bounce |
|
137 |
*/ |
|
299 | 138 |
void bounce (Vector normal); |
197 | 139 |
|
140 |
/** |
|
141 |
* Called on network clients to sync state from server |
|
142 |
* |
|
143 |
* @param position New position |
|
144 |
* @param velocity New velocity |
|
145 |
* @param inAir New inAir value |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
197
diff
changeset
|
146 |
* @param facingRight New facingRight value |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
197
diff
changeset
|
147 |
* @param aim New aim |
197 | 148 |
*/ |
299 | 149 |
virtual void updatePhysics (Vector position, Vector velocity, bool inAir, FacingDirection facing, float aim); |
197 | 150 |
|
225 | 151 |
/** |
320 | 152 |
* Put the object in the physics simulation. When the object is in |
153 |
* the physics simulation it's movements will be calculated. |
|
225 | 154 |
*/ |
155 |
void enable (void); |
|
156 |
||
157 |
/** |
|
320 | 158 |
* Remove object from the objects physics simulation. When the |
159 |
* object isn't in the physics simulation it won't be deleted but |
|
160 |
* its movements will not be calculated. |
|
225 | 161 |
*/ |
162 |
void disable (void); |
|
163 |
||
197 | 164 |
private: |
165 |
/** |
|
166 |
* Handle player movement and apply forces. |
|
320 | 167 |
* |
168 |
* @param dt Time intervall |
|
197 | 169 |
*/ |
299 | 170 |
void updatePosition (TimeMS dt); |
197 | 171 |
|
172 |
/** |
|
173 |
* Use RK4 to integrate the effects of force over a time interwall. |
|
174 |
* |
|
175 |
* @param force Force to integrate |
|
176 |
* @param dt Time intervall |
|
320 | 177 |
* @param posAfterTick Reference to object postition after integration. |
178 |
* @param velAfterTick Reference to object velocity after integration. |
|
197 | 179 |
*/ |
299 | 180 |
void integrate (Force force, TimeMS dt, Vector &posAfterTick, Vector &velAfterTick); |
197 | 181 |
|
182 |
/** |
|
183 |
* Evaluate the value of the derivative at given time |
|
184 |
* |
|
185 |
* @param force Force |
|
186 |
* @param dt Time |
|
187 |
* @param d Previous derivative |
|
320 | 188 |
* @return Derivative |
197 | 189 |
*/ |
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
190 |
Derivative evaluate (Force force, TimeMS dt, const Derivative &d, const Vector &posAfterTick, const Vector &velAfterTick); |
197 | 191 |
|
192 |
/** |
|
193 |
* Return object acceleration with given force. |
|
194 |
* |
|
195 |
* @param force Force |
|
196 |
* @return Acceleration |
|
197 |
*/ |
|
299 | 198 |
Vector acceleration (const Force &force); |
197 | 199 |
|
249 | 200 |
/** |
197 | 201 |
* Handle ground movement. |
202 |
* |
|
203 |
* @param right Boolean describing the movement direction. |
|
204 |
* @return New position |
|
205 |
*/ |
|
299 | 206 |
void walk (TimeMS, bool right); |
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
207 |
|
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
208 |
/* |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
209 |
* Undocumented private method |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
210 |
*/ |
299 | 211 |
Vector walk_one_step (float, bool); |
197 | 212 |
|
288 | 213 |
public: |
249 | 214 |
/** |
215 |
* Define object behaviour on collisions. |
|
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
216 |
* |
320 | 217 |
* @param collisionPoint Point of collision. |
218 |
* @param other The other object we have collided with. |
|
197 | 219 |
*/ |
288 | 220 |
virtual void onCollision (Vector collisionPoint, PhysicsObject *other = NULL); |
272 | 221 |
|
249 | 222 |
/** |
320 | 223 |
* Get object type. |
224 |
* |
|
225 |
* @return Object type |
|
287 | 226 |
*/ |
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
227 |
ObjectType getType (void) const { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
228 |
return type; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
229 |
} |
287 | 230 |
|
231 |
/** |
|
249 | 232 |
* Checks if it is possible for the object to be in the given |
233 |
* location. |
|
320 | 234 |
* |
235 |
* @param loc Location |
|
197 | 236 |
*/ |
299 | 237 |
bool possibleLocation (Vector loc); |
197 | 238 |
|
239 |
/** |
|
240 |
* Get current object position. |
|
241 |
* |
|
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
242 |
* @return position vector |
197 | 243 |
*/ |
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
244 |
Vector getPosition (void) const { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
245 |
return position; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
246 |
} |
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
252
diff
changeset
|
247 |
|
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
252
diff
changeset
|
248 |
/** |
285 | 249 |
* Get previous object position. |
250 |
* |
|
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
251 |
* @return position vector |
285 | 252 |
*/ |
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
253 |
Vector getPreviousPosition (void) const { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
254 |
return previousPosition; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
255 |
} |
285 | 256 |
|
257 |
/** |
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
252
diff
changeset
|
258 |
* Get current object screen coordinates |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
252
diff
changeset
|
259 |
* |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
252
diff
changeset
|
260 |
* @return PixelCoordinate position |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
252
diff
changeset
|
261 |
*/ |
257
549783d71e51
add a handful of consts to PhysicsObject and modify draw to use getCoordinate, and replace old skin.png with new skin.png
terom
parents:
255
diff
changeset
|
262 |
PixelCoordinate getCoordinate (void) const; |
197 | 263 |
|
264 |
/** |
|
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
265 |
* Get current object velocity. |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
266 |
* |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
267 |
* @return Velocity vector |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
268 |
*/ |
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
269 |
Vector getVelocity (void) const { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
270 |
return velocity; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
271 |
} |
197 | 272 |
|
273 |
/** |
|
274 |
* Return object facing. |
|
275 |
* |
|
276 |
* @return Object facing (true if facing right) |
|
277 |
*/ |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
278 |
FacingDirection getFacing (void) const { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
279 |
return facing; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
280 |
} |
197 | 281 |
|
282 |
/** |
|
283 |
* Return object aim angle. |
|
284 |
* |
|
285 |
* @return Object aim angle |
|
286 |
*/ |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
287 |
float getAim (void) const { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
288 |
return aim; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
289 |
} |
197 | 290 |
|
291 |
/** |
|
320 | 292 |
* Get object direction. |
293 |
* |
|
294 |
* @return Unit vector to facing+aim |
|
235 | 295 |
*/ |
257
549783d71e51
add a handful of consts to PhysicsObject and modify draw to use getCoordinate, and replace old skin.png with new skin.png
terom
parents:
255
diff
changeset
|
296 |
Vector getDirection (void) const; |
235 | 297 |
|
298 |
/** |
|
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
299 |
* Mark object as destroyed, it will be delete'd later |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
300 |
*/ |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
301 |
void destroy (void); |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
302 |
|
320 | 303 |
/** |
304 |
* Check if the object is alive. |
|
305 |
* |
|
306 |
* @return Is the object alive? |
|
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
307 |
*/ |
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
308 |
bool isAlive (void) const { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
309 |
return alive; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
310 |
} |
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
311 |
|
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
312 |
/** |
320 | 313 |
* Tells the state of the object. |
314 |
* |
|
315 |
* @return True if object has been destroyed. |
|
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
316 |
*/ |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
317 |
bool removeIfDestroyed (void); |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
318 |
|
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
319 |
/** |
320 | 320 |
* Set object pivot. |
321 |
* |
|
322 |
* @param pivot Pivot object |
|
228 | 323 |
*/ |
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
324 |
void setPivot (PhysicsObject *pivot) { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
325 |
this->pivot = pivot; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
326 |
} |
228 | 327 |
|
328 |
/** |
|
322 | 329 |
* Return the pivot object pointer. |
330 |
*/ |
|
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
331 |
PhysicsObject *getPivot (void) { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
332 |
return pivot; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
333 |
} |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
334 |
|
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
335 |
/** |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
336 |
* Compute the force that this object (as a pivot) exerts on the given object |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
337 |
* |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
338 |
* @param bob Othe object |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
339 |
* @return Force |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
340 |
*/ |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
341 |
virtual Vector getPivotForce (void); |
322 | 342 |
|
343 |
/** |
|
268
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
344 |
* Checks if object collides with other objects |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
345 |
* |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
346 |
* @param obj Other PhysicsObject |
320 | 347 |
* @return Did we collide? |
268
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
348 |
*/ |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
349 |
bool collides (const PhysicsObject &obj); |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
350 |
|
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
351 |
/** |
197 | 352 |
* Update object in physics simulation. |
320 | 353 |
* |
354 |
* @param tick_length Length of the physics tick |
|
197 | 355 |
*/ |
221 | 356 |
virtual void tick (TimeMS tick_length); |
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
357 |
|
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
358 |
protected: |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
359 |
/** |
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
360 |
* Set object shape. |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
361 |
* |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
362 |
* XXX: constructor |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
363 |
* |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
364 |
* @param shape Vector containing polygon points |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
365 |
*/ |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
366 |
void setShape(std::vector<Vector> shape) { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
367 |
this->shape = shape; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
368 |
} |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
369 |
|
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
370 |
/** |
427
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
371 |
* Update object position, also updating our previous position |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
372 |
* |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
373 |
* @param pos new position |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
374 |
*/ |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
375 |
void setPosition (Vector pos); |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
376 |
|
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
377 |
/** |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
378 |
* Update current object velocity. |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
379 |
* |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
380 |
* @param velocity new velocity |
01e77fe8c040
fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents:
423
diff
changeset
|
381 |
*/ |
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
382 |
void setVelocity (Vector velocity) { |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
383 |
this->velocity = velocity; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
384 |
} |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
385 |
|
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
386 |
/** |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
387 |
* Reset state and disable, ready to be resume()'d again in a different place |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
388 |
*/ |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
389 |
void reset (void); |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
390 |
|
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
391 |
/** |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
392 |
* Resume after a reset() at the given position with a zero velocity |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
393 |
*/ |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
394 |
void resume (Vector position); |
197 | 395 |
}; |
396 |
||
320 | 397 |
/** Helper struct for the integration */ |
197 | 398 |
struct Derivative { |
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
399 |
/** |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
400 |
* Velocity |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
401 |
*/ |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
402 |
Vector dx; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
403 |
|
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
404 |
/** |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
405 |
* Acceleration |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
406 |
*/ |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
407 |
Vector dv; |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
408 |
|
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
409 |
Derivative () : dx(), dv() { } |
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
427
diff
changeset
|
410 |
Derivative (Vector dx, Vector dv) : dx(dx), dv(dv) { } |
197 | 411 |
}; |
412 |
||
268
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
413 |
/** |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
414 |
* Returns the "sign" of the cross product between given points. In |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
415 |
* practice the sign of the return value tels on which side of the |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
416 |
* line drawn between p1 and p2 the point p3 is. |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
417 |
* |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
418 |
* @param p1 Line start point |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
419 |
* @param p2 Line end point |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
420 |
* @param p3 Point |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
421 |
* @return Variable, the sign of which tells on which side of the line p3 is. |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
422 |
*/ |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
423 |
int8_t crossProduct(const Vector &p1, const Vector &p2, const Vector &p3); |
0b96b88af335
Added collision detection method to PhysicsObject. Not tested.
saiam
parents:
265
diff
changeset
|
424 |
|
197 | 425 |
#endif |