equal
deleted
inserted
replaced
|
1 #ifndef PHYSICS_HH |
|
2 #define PHYSICS_HH |
|
3 |
|
4 #include "Vector.hh" |
|
5 |
|
6 #include <ClanLib/core.h> |
|
7 |
|
8 const uint16_t PHYSICS_TICK_MS = 10; |
|
9 |
|
10 // forward-declare |
|
11 class PhysicsObject; |
|
12 |
|
13 class PhysicsWorld { |
|
14 friend class PhysicsObject; |
|
15 |
|
16 private: |
|
17 CL_Timer tick_timer; |
|
18 |
|
19 protected: |
|
20 std::vector<PhysicsObject*> objects; |
|
21 Vector gravity; |
|
22 Vector dimensions; |
|
23 |
|
24 CL_SlotContainer slots; |
|
25 |
|
26 PhysicsWorld (Vector gravity, Vector dimensions); |
|
27 |
|
28 public: |
|
29 void addObject (PhysicsObject *object); |
|
30 |
|
31 void tick (void); |
|
32 }; |
|
33 |
|
34 class PhysicsObject { |
|
35 protected: |
|
36 PhysicsWorld &world; |
|
37 float mass; |
|
38 Vector position; |
|
39 Vector velocity; |
|
40 |
|
41 PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity); |
|
42 |
|
43 virtual void applyForce (Vector force, uint16_t dt); |
|
44 void updatePhysics (Vector position, Vector velocity); |
|
45 |
|
46 private: |
|
47 void updatePosition (void); |
|
48 |
|
49 public: |
|
50 Vector getPosition (void); |
|
51 |
|
52 void tick (void); |
|
53 }; |
|
54 |
|
55 #endif |