#ifndef SPACE_SHIP_H_
#define SPACE_SHIP_H_
+#include "../graphics/const.h"
#include "../graphics/Vector.h"
#include <cmath>
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;
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;
}