author | saiam |
Sat, 29 Nov 2008 20:59:50 +0000 | |
changeset 136 | 3a15a5937f7a |
parent 135 | d5624d698a78 |
child 138 | cc326b64ae20 |
permissions | -rw-r--r-- |
42 | 1 |
#ifndef PHYSICS_HH |
2 |
#define PHYSICS_HH |
|
3 |
||
72 | 4 |
#include <vector> |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
79
diff
changeset
|
5 |
#include <queue> |
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
48
diff
changeset
|
6 |
#include <ClanLib/core.h> |
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
48
diff
changeset
|
7 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
8 |
#include "Vector.hh" |
136
3a15a5937f7a
Moved constants to one header Config.hh, we probably should use somekind of resourcemanager. But do we have time for that? :)
saiam
parents:
135
diff
changeset
|
9 |
#include "Config.hh" |
78 | 10 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
11 |
// Forward declares |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
12 |
class PhysicsWorld; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
13 |
class PhysicsObject; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
14 |
class PlayerObject; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
15 |
class ProjectileObject; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
16 |
class Shape; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
17 |
struct Derivative; |
42 | 18 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
19 |
// Type definitions |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
20 |
typedef uint16_t TimeMS; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
21 |
typedef Vector Force; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
22 |
|
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
23 |
// TODO: Random definitions. Should these be somewhere else? |
72 | 24 |
enum TerrainType {EMPTY, DIRT, ROCK}; |
71 | 25 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
26 |
// Yeah?!?!?! Atleast this could be documented. Contains vectors |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
27 |
// presenting all the 8 directions in a square grid? |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
28 |
const Vector DIRECTIONS[] = { Vector(0,-1), Vector(1,-1), Vector(1,0), |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
29 |
Vector(1,1), Vector(0,1), Vector(-1,1), |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
30 |
Vector(-1,0), Vector(-1,-1) }; |
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
48
diff
changeset
|
31 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
32 |
|
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
33 |
/** |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
34 |
* PhysicsWorld class. PhysicsWorld contains PhysicsObjects that are |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
35 |
* simulated in the PhysicsWorld. |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
36 |
*/ |
42 | 37 |
class PhysicsWorld { |
60 | 38 |
friend class PhysicsObject; |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
39 |
|
70 | 40 |
private: |
41 |
CL_Timer tick_timer; |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
42 |
uint32_t tick_counter; |
105 | 43 |
|
70 | 44 |
protected: |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
45 |
//std::vector<PlayerObject*> players; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
46 |
//std::vector<ProjectileObject*> projectiles; |
70 | 47 |
std::vector<PhysicsObject*> objects; |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
48 |
|
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
49 |
// Contains connections between signals and slots |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
50 |
CL_SlotContainer slots; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
51 |
|
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
52 |
PhysicsWorld(Vector gravity, Vector dimensions); |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
53 |
|
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
54 |
// TODO: Should these be somewhere else? |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
55 |
Vector dimensions; |
70 | 56 |
Vector gravity; |
86 | 57 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
58 |
// TODO: Should this be it's own class? |
72 | 59 |
std::vector<std::vector<TerrainType> > terrain; |
71 | 60 |
|
86 | 61 |
public: |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
62 |
// TODO: Replace addObject with these? |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
63 |
//void addPlayerObject(PlayerObject *object); |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
64 |
//void addProjectileObject(ProjectileObject *object); |
70 | 65 |
|
123 | 66 |
/** |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
67 |
* Add object to the PhysicsWorld. |
123 | 68 |
* |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
69 |
* @param object Pointer to the PhysicsObject to add. |
123 | 70 |
*/ |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
71 |
void addObject(PhysicsObject *object); |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
72 |
|
123 | 73 |
/** |
74 |
* Advance one time step in physics simulation. |
|
75 |
*/ |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
76 |
void tick(); |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
77 |
|
123 | 78 |
/** |
79 |
* Get current tick in physics simulation. |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
80 |
* |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
81 |
* @return tick Current simulation tick. |
123 | 82 |
*/ |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
83 |
uint32_t getTick(); |
105 | 84 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
85 |
// ?!!?!?!?!?!?! |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
86 |
// TODO: If there were a terrain class, these could it's members. |
123 | 87 |
/** |
88 |
* Generate random terrain. |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
89 |
* |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
90 |
* @param seed Random generator seed. |
123 | 91 |
*/ |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
92 |
void generateTerrain(int seed); |
123 | 93 |
/** |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
94 |
* Remove ground from the terrain. Removes a circle. |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
95 |
* |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
96 |
* @param x Circle x-coordinate |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
97 |
* @param y Circle y-coordinate |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
98 |
* @param r Circle radius |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
99 |
*/ |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
100 |
void removeGround(int x, int y, float r); |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
101 |
/** |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
102 |
* Remove ground from the terrain. Removes a circle. |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
103 |
* |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
104 |
* @param pos Circle location |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
105 |
* @param r Circle radius |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
106 |
*/ |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
107 |
void removeGround(Vector pos, float r); |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
108 |
/** |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
109 |
* Return normal for the wall that has been hit. |
123 | 110 |
* |
111 |
* @param hitPoint The point of the wall that has been hit. |
|
112 |
* @param prevPoint The point from where we were coming. |
|
113 |
*/ |
|
98 | 114 |
Vector getNormal(Vector hitPoint, Vector prevPoint); |
123 | 115 |
/** |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
116 |
* Return terrain type in given position. |
123 | 117 |
* |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
118 |
* @param x X-coordinate |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
119 |
* @param y Y-coordinate |
123 | 120 |
*/ |
112 | 121 |
TerrainType getType(int x, int y) const; |
123 | 122 |
/** |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
123 |
* Return terrain type in given position. |
123 | 124 |
* |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
125 |
* @param pos Coordinate vector |
123 | 126 |
*/ |
77
98dc9008d15f
changed collision detection, remove old if content with new
nireco
parents:
75
diff
changeset
|
127 |
TerrainType getType(Vector pos) const; |
112 | 128 |
|
42 | 129 |
}; |
130 |
||
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
131 |
/** |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
132 |
* PhysicObject class. A basic PhysicsObject class. |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
133 |
*/ |
42 | 134 |
class PhysicsObject { |
70 | 135 |
protected: |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
136 |
// This probably shouldn't be done this way. |
70 | 137 |
PhysicsWorld &world; |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
138 |
|
70 | 139 |
Vector position; |
140 |
Vector velocity; |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
141 |
float mass; |
128
890ac82cdcc0
Documenting more, cleaning variables. This code needs some serious
saiam
parents:
123
diff
changeset
|
142 |
bool inAir; // Is the object "on the ground" |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
79
diff
changeset
|
143 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
144 |
// Attributes for players |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
145 |
float aim; // Aim direction (half circle) |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
146 |
bool facingRight; // Player facing |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
147 |
|
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
148 |
PhysicsObject(PhysicsWorld &world, float mass, Vector position, |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
149 |
Vector velocity); |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
150 |
~PhysicsObject() {} |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
151 |
|
108 | 152 |
|
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
95
diff
changeset
|
153 |
/** |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
154 |
* Add force to the force queue to be applied on next tick. |
108 | 155 |
* |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
156 |
* @param force Force vector |
108 | 157 |
*/ |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
158 |
void applyForce(Force force); |
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
95
diff
changeset
|
159 |
|
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
95
diff
changeset
|
160 |
/** |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
161 |
* Change player aim |
129 | 162 |
* |
163 |
* @param da Aim angle change |
|
108 | 164 |
*/ |
165 |
void changeAim(float da); |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
166 |
|
108 | 167 |
/** |
168 |
* Set player facing. |
|
129 | 169 |
* |
170 |
* @param facingRight True if player is facing right. |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
171 |
*/ |
129 | 172 |
void setFacing(bool facingRight); |
108 | 173 |
|
174 |
/** |
|
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
95
diff
changeset
|
175 |
* Handle ground-jumping |
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
95
diff
changeset
|
176 |
*/ |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
177 |
void jump(); |
98 | 178 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
179 |
/** |
98 | 180 |
* Handle ground-bounce |
129 | 181 |
* |
182 |
* @param normal Normal vector relative to which to bounce |
|
98 | 183 |
*/ |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
184 |
void bounce(Vector normal); |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
185 |
|
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
186 |
/** |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
187 |
* Called on network clients to sync state from server |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
188 |
* |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
189 |
* @param position New position |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
190 |
* @param velocity New velocity |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
191 |
* @param inAir New inAir value |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
192 |
*/ |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
193 |
void updatePhysics(Vector position, Vector velocity, bool inAir); |
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
95
diff
changeset
|
194 |
|
70 | 195 |
private: |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
196 |
// TODO: I'd be tempted to use some already made ClanLib structure |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
197 |
// here. |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
198 |
// Shape of the object. Edge points of the shape polygon. |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
199 |
std::vector<Vector> shape; |
129 | 200 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
201 |
// TODO: Should these operations be moved to PhysicsWorld? |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
202 |
// Force queue that is emptied on every tick |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
203 |
std::queue<Force> forceq; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
204 |
// Helper variables for integration |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
205 |
Vector posAfterTick; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
206 |
Vector velAfterTick; |
69 | 207 |
|
70 | 208 |
/** |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
209 |
* Handle player movement and apply forces. |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
210 |
*/ |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
211 |
void updatePosition(); |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
212 |
|
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
213 |
// TODO: Should these be moved to PhysicsWorld? |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
214 |
/** |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
215 |
* Use RK4 to integrate the effects of force over a time interwall. |
129 | 216 |
* |
217 |
* @param force Force to integrate |
|
218 |
* @param dt Time intervall |
|
70 | 219 |
*/ |
85 | 220 |
void integrate(Force force, TimeMS dt); |
129 | 221 |
|
222 |
/** |
|
223 |
* Evaluate the value of the derivative at given time |
|
224 |
* |
|
225 |
* @param force Force |
|
226 |
* @param dt Time |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
227 |
* @param d Previous derivative |
129 | 228 |
*/ |
85 | 229 |
Derivative evaluate(Force force, TimeMS dt, Derivative &d); |
129 | 230 |
|
231 |
/** |
|
232 |
* Return object acceleration with given force. |
|
233 |
* |
|
234 |
* @param force Force |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
235 |
* @return Acceleration |
129 | 236 |
*/ |
85 | 237 |
Vector acceleration(const Force &force); |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
79
diff
changeset
|
238 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
239 |
// TODO: If integration is moved to PhysicsWorld then this should |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
240 |
// also move there. |
134 | 241 |
/** |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
242 |
* Handle ground movement. |
134 | 243 |
* |
244 |
* @param right Boolean describing the movement direction. |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
245 |
* @return New position |
134 | 246 |
*/ |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
247 |
Vector walk(bool right); |
134 | 248 |
|
129 | 249 |
/* |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
250 |
* Handle collision. TODO: This is not used. It probably should |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
251 |
* be? |
129 | 252 |
*/ |
116 | 253 |
virtual void onCollision() {} |
254 |
||
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
255 |
/* |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
256 |
* TODO: This probably does some kind of collision |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
257 |
* detection. Could be named/documented better. |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
258 |
*/ |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
259 |
bool possibleLocation(Vector loc); |
132
957c3c184ea0
Changed some variables that were protected to private from PhysicsObject
saiam
parents:
131
diff
changeset
|
260 |
|
70 | 261 |
public: |
129 | 262 |
/** |
263 |
* Get current object position. |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
264 |
* |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
265 |
* @return Position vector |
129 | 266 |
*/ |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
267 |
Vector getPosition(); |
129 | 268 |
|
269 |
/** |
|
270 |
* Return object shape. |
|
271 |
* |
|
272 |
* @return Polygon points |
|
273 |
*/ |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
274 |
std::vector<Vector>& getShape(); |
129 | 275 |
|
276 |
/** |
|
277 |
* Set object shape. |
|
278 |
* |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
279 |
* @param shape Vector containing polygon poinst |
129 | 280 |
*/ |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
281 |
void setShape(std::vector<Vector> shape); |
108 | 282 |
|
129 | 283 |
/** |
284 |
* Return object facing. |
|
285 |
* |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
286 |
* @return Object facing (true if facing right) |
129 | 287 |
*/ |
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
288 |
bool getFacing(); |
129 | 289 |
|
290 |
/** |
|
291 |
* Return object aim angle. |
|
292 |
* |
|
293 |
* @return Object aim angle |
|
294 |
*/ |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
295 |
float getAim(); |
108 | 296 |
|
129 | 297 |
/** |
298 |
* Update object in physics simulation. |
|
299 |
*/ |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
300 |
void tick(); |
42 | 301 |
}; |
302 |
||
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
303 |
// TODO: This could probably be moved somewhere else or removed |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
304 |
// completely. |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
79
diff
changeset
|
305 |
struct Derivative { |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
79
diff
changeset
|
306 |
Vector dx; // Velocity |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
79
diff
changeset
|
307 |
Vector dv; // Acceleration |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
79
diff
changeset
|
308 |
}; |
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
79
diff
changeset
|
309 |
|
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
79
diff
changeset
|
310 |
|
135
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
311 |
// TODO: These are drafts |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
312 |
/** |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
313 |
* PlayerObject class. Represents a player in the physics engine. |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
314 |
*/ |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
315 |
//class PlayerObject : public PhysicsObject { |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
316 |
|
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
317 |
//}; |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
318 |
|
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
319 |
/** |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
320 |
* ProjectileObject class. Represents different projectiles in the |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
321 |
* physics (i.e. not players) in the physics engine. |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
322 |
*/ |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
323 |
//class ProjectileObject : public PhysicsObject { |
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
324 |
|
d5624d698a78
Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents:
134
diff
changeset
|
325 |
//}; |
83
cbba9729e92b
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents:
79
diff
changeset
|
326 |
|
42 | 327 |
#endif |