GEJM  1.0.0.0
a 2D platformer made by students
Physics.h
1 #ifndef PHYSICS_H
2 #define PHYSICS_H
3 
4 #include "Creature.h"
5 #include <list>
6 #include <SDL_timer.h>
7 
11 struct State
12 {
13  double x; // position
14  double v; // velocity
15 };
16 
20 struct Derivative
21 {
22  double dx; // dx/dt = velocity
23  double dv; // dv/dt = acceleration
24 };
25 
29 class Physics
30 {
31 public:
38  Physics(int boundaryWidth, int boundaryHeight);
39 
43  Physics(Physics const&) = delete;
44 
48  ~Physics();
49 
55  double update(std::list<Object*>& objectList);
56 
60  Physics& operator=(Physics const&) = delete;
61 
62 private:
66  double t;
67 
71  const double dt;
72 
76  double currentTime;
77 
81  double accumulator;
82 
86  int boundaryWidth;
87 
91  int boundaryHeight;
92 
101  void integrate(State& state, double t, double dt, bool isY);
102 
112  Derivative evaluate(State const& initial, double t, double dt, Derivative const& d, bool isY);
113 
121  double acceleration(const State &state, double t);
122 
128  void checkCollision(std::list<Object*>& objectList);
129 };
130 
131 #endif // PHYSICS_H
Definition: Physics.h:29
Definition: Physics.h:11
Definition: Physics.h:20