#include "drone_controller.hh" #include #include Waypoint::Waypoint(unsigned frame, QVector3D pos) :frame(frame), pos(pos) {} Waypoint::Waypoint(const QJsonObject &json) :Waypoint(json["frame"].toInt(), QVector3D(json["position"]["lng_X"].toInt(), json["position"]["alt_Y"].toInt(), json["position"]["lat_Z"].toInt())) {} Drone::Drone(const QJsonObject &json) { QJsonArray ja = json["waypoints"].toArray(); waypoints.reserve(ja.size()); for (const QJsonValue &o : ja) { waypoints.append(Waypoint(o.toObject())); } } const QVector Drone::getWaypoints() const { return waypoints; } DroneController::DroneController(const QJsonObject &json) :framerate(json["framerate"].toInt()) { // TODO: REMOVE!! framerate = 1; QJsonArray ja = json["drones"].toArray(); drones.reserve(ja.size()); for (const QJsonValue &o : ja) { drones.append(Drone(o.toObject())); } for (const Drone &d : drones) { for (const Waypoint &wp : d.getWaypoints()) { if (wp.frame > duration) duration = wp.frame; } } connect(&timer, &QTimer::timeout, this, &DroneController::step); pause(); } DroneController::~DroneController() { } int DroneController::getDuration() const { return duration; } void DroneController::step() { qDebug("frame %d (%d%%)", frame, (int) ((double) frame / duration * 100)); emit frameChanged(frame); if (frame == duration) { pause(); } else { frame++; } } void DroneController::play() { if (!paused) return; paused = false; timer.start(1000. / framerate); qDebug() << "playing"; emit playing(); } void DroneController::pause() { if (paused) return; paused = true; timer.stop(); qDebug() << "pausing"; emit pausing(); } void DroneController::suspend() { if (!paused) { pause(); paused = false; } } void DroneController::resume() { if (!paused) { paused = true; play(); } } void DroneController::seek(int frame) { if (this->frame == frame) return; this->frame = frame; step(); }