From 0c28d9dc80e634ebfbabed5ad446b6a4f82056e3 Mon Sep 17 00:00:00 2001 From: ccolin Date: Mon, 4 Jan 2021 14:49:26 +0100 Subject: add speeding violation reporting --- src/drone.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/drone.cc') 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; } -- cgit v1.2.3-70-g09d2