X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fentity%2FShip.h;h=a373302904d760597e11228c7f7753586ea2ceba;hb=1cb5ed22d7772abe6f9893be90f26f46dbde39f7;hp=8bcc4bcb6dfecb1f41ea4b658cfe4f6d3f0feeac;hpb=96ab5904b059e00e78b26a6527790c8dc951e324;p=space.git diff --git a/src/entity/Ship.h b/src/entity/Ship.h index 8bcc4bc..a373302 100644 --- a/src/entity/Ship.h +++ b/src/entity/Ship.h @@ -1,12 +1,64 @@ #ifndef SPACE_SHIP_H_ #define SPACE_SHIP_H_ +#include "../graphics/const.h" +#include "../graphics/Vector.h" + +#include + namespace space { class Ship { -private: +public: + constexpr Ship() { } + +public: + float mass = 1; + float linForce = 1; + float revForce = 1; + float rotForce = 1; + + Vector pos; + Vector vel; + Vector Dir() const { + return Vector::FromPolar(1, orient); + } + float MaxFwdAcc() const { + return linForce / mass; + } + float MaxRevAcc() const { + return revForce / mass; + } + float MaxLinAcc() const { + return (linThrottle < 0 ? MaxRevAcc() : MaxFwdAcc()); + } + Vector 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; + } };