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