diff options
Diffstat (limited to 'src/drone.cc')
-rw-r--r-- | src/drone.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/drone.cc b/src/drone.cc index 2c0fad8..50bc5e7 100644 --- a/src/drone.cc +++ b/src/drone.cc @@ -31,6 +31,10 @@ Drone::Drone(const QJsonObject &json) for (const QJsonValue &o : ja) { waypoints.append(Waypoint(o.toObject())); } + for (int i = 0; i < waypoints.size() - 1; i++) { + waypoints[i].computed_speed = (waypoints[i + 1].pos - waypoints[i].pos).length() + / (waypoints[i + 1].frame - waypoints[i].frame); + } setTo(0); } @@ -55,10 +59,13 @@ void Drone::setTo(int frame) { } if (next > -1 && prev == -1) { pos = next_wp->pos; + speed = next_wp->computed_speed; } else if (prev > -1 && next == -1) { pos = prev_wp->pos; + speed = prev_wp->computed_speed; } else { pos = lerp(prev_wp->pos, next_wp->pos, (double) (frame-prev) / (next-prev)); + speed = prev_wp->computed_speed; } } @@ -73,6 +80,11 @@ int Drone::getId() const { } +double Drone::getSpeed() const { + return speed; +} + + const OpenGLMesh *Drone::getMesh() const { return mesh; } |