]> git.localhorst.tv Git - space.git/blobdiff - src/entity/Ship.h
added autopilot that sucks
[space.git] / src / entity / Ship.h
index a21f4b18e6855c849d0dad0351bbf600d76c3102..a373302904d760597e11228c7f7753586ea2ceba 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef SPACE_SHIP_H_
 #define SPACE_SHIP_H_
 
+#include "../graphics/const.h"
 #include "../graphics/Vector.h"
 
 #include <cmath>
@@ -19,22 +20,31 @@ public:
        float revForce = 1;
        float rotForce = 1;
 
-       Vector<int> area;
-
        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 {
-               float force = (linThrottle < 0 ? revForce : linForce);
-               return Dir() * force / mass * linThrottle;
+               return Dir() * MaxLinAcc() * linThrottle;
        }
 
        float orient = 0;
        float rotVel = 0;
+       float MaxRotAcc() const {
+               return rotForce / mass;
+       }
        float RotAcc() const {
-               return rotForce / mass * rotThrottle;
+               return MaxRotAcc() * rotThrottle;
        }
 
        float linThrottle = 0;
@@ -44,6 +54,8 @@ 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;
        }