WIP Starfield moving center

This commit is contained in:
Patrick Haßel 2023-01-14 17:50:58 +01:00
parent cd93a92e2b
commit 9fe739f5c1

View File

@ -9,13 +9,16 @@ private:
Vector center; Vector center;
Vector centerNext;
Vector stars[20]; Vector stars[20];
public: public:
explicit Starfield(Display &display) : explicit Starfield(Display &display) :
Mode(display), Mode(display),
center(width / 2.0, height / 2.0) { center(width / 2.0, height / 2.0),
centerNext(center.x, center.y) {
for (auto &star: stars) { for (auto &star: stars) {
star.x = random(width); star.x = random(width);
star.y = random(height); star.y = random(height);
@ -29,6 +32,7 @@ public:
protected: protected:
void step(microseconds_t microseconds) override { void step(microseconds_t microseconds) override {
stepCenter();
for (auto &star: stars) { for (auto &star: stars) {
const Vector velocity = star.minus(center).multiply((double) microseconds / 200000.0); const Vector velocity = star.minus(center).multiply((double) microseconds / 200000.0);
star = star.plus(velocity); star = star.plus(velocity);
@ -41,6 +45,25 @@ protected:
markDirty(); markDirty();
} }
void stepCenter() {
// TODO moving center overtakes moving stars (less stars in direction of moving center)
// Vector diff = centerNext.minus(center);
// if (diff.length < 0.01) {
// centerNext = Vector(random(width), random(height));
// } else {
// if (diff.x >= 0) {
// center.x += min(0.1, diff.x);
// } else {
// center.x += max(-0.1, diff.x);
// }
// if (diff.y >= 0) {
// center.y += min(0.1, diff.y);
// } else {
// center.y += max(-0.1, diff.y);
// }
// }
}
void draw(Display &display) override { void draw(Display &display) override {
display.clear(); display.clear();
for (auto &star: stars) { for (auto &star: stars) {