#ifndef SPACE_SHIP_H_
#define SPACE_SHIP_H_
+#include "../graphics/const.h"
+#include "../graphics/Vector.h"
+
+#include <cmath>
+
namespace space {
class Ship {
-private:
+public:
+ constexpr Ship() { }
+
+public:
+ float mass = 1;
+ float linForce = 1;
+ float revForce = 1;
+ float rotForce = 1;
+
+ Vector<float> pos;
+ Vector<float> vel;
+ Vector<float> Dir() const {
+ return Vector<float>::FromPolar(1, orient);
+ }
+ float MaxFwdAcc() const {
+ return linForce / mass;
+ }
+ float MaxRevAcc() const {
+ return revForce / mass;
+ }
+ float MaxLinAcc() const {
+ return (linThrottle < 0 ? MaxRevAcc() : MaxFwdAcc());
+ }
+ Vector<float> Acc() const {
+ return Dir() * MaxLinAcc() * linThrottle;
+ }
+
+ float orient = 0;
+ float rotVel = 0;
+ float MaxRotAcc() const {
+ return rotForce / mass;
+ }
+ float RotAcc() const {
+ return MaxRotAcc() * rotThrottle;
+ }
+
+ float linThrottle = 0;
+ float rotThrottle = 0;
+
+public:
+ void Update(float delta) {
+ rotVel += RotAcc() * delta;
+ orient += rotVel * delta;
+ while (orient < 0) orient += PI2;
+ while (orient > PI2) orient -= PI2;
+ vel += Acc() * delta;
+ pos += vel * delta;
+ }
};