]> git.localhorst.tv Git - space.git/blob - src/entity/Ship.h
force based movement
[space.git] / src / entity / Ship.h
1 #ifndef SPACE_SHIP_H_
2 #define SPACE_SHIP_H_
3
4 #include "../graphics/Vector.h"
5
6 #include <cmath>
7
8
9 namespace space {
10
11 class Ship {
12
13 public:
14         constexpr Ship() { }
15
16 public:
17         float mass = 1;
18         float linForce = 1;
19         float revForce = 1;
20         float rotForce = 1;
21
22         Vector<int> area;
23
24         Vector<float> pos;
25         Vector<float> vel;
26         Vector<float> Dir() const {
27                 return Vector<float>::FromPolar(1, orient);
28         }
29         Vector<float> Acc() const {
30                 float force = (linThrottle < 0 ? revForce : linForce);
31                 return Dir() * force / mass * linThrottle;
32         }
33
34         float orient = 0;
35         float rotVel = 0;
36         float RotAcc() const {
37                 return rotForce / mass * rotThrottle;
38         }
39
40         float linThrottle = 0;
41         float rotThrottle = 0;
42
43 public:
44         void Update(float delta) {
45                 rotVel += RotAcc() * delta;
46                 orient += rotVel * delta;
47                 vel += Acc() * delta;
48                 pos += vel * delta;
49         }
50
51 };
52
53 }
54
55 #endif