aboutsummaryrefslogtreecommitdiff
path: root/src/drone_controller.cc
diff options
context:
space:
mode:
authorccolin2021-01-03 13:27:01 +0100
committerccolin2021-01-03 13:27:20 +0100
commit7e0554bf65b9be61f3b73625d762a5043ad2af0f (patch)
tree09d8f976d428aa3676f7a9574da2689e30477361 /src/drone_controller.cc
parent928d45c3fbfb6b00d8e0b79b63934ebd080b9456 (diff)
collision sphere previsualization
Diffstat (limited to 'src/drone_controller.cc')
-rw-r--r--src/drone_controller.cc36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc
index 0be9844..514a166 100644
--- a/src/drone_controller.cc
+++ b/src/drone_controller.cc
@@ -1,14 +1,34 @@
#include "drone_controller.hh"
#include "opengl_widget.hh"
+#include "load_obj.hh"
#include <QJsonArray>
#include <QDebug>
#include <QOpenGLShaderProgram>
-DroneController::DroneController(const QJsonObject &json)
- :framerate(json["framerate"].toInt()) {
+const unsigned char DroneController::sphere_neutral[] = {
+ 166, 166, 166
+};
+
+OpenGLMesh *DroneController::sphere = nullptr;
+
+DroneController::DroneController(const QJsonObject &json)
+ :framerate(json["framerate"].toInt()),
+ sphere_timer(this) {
+ sphere_timer.setSingleShot(true);
+ connect(&sphere_timer, &QTimer::timeout, [&]() {
+ draw_spheres = false;
+ OpenGLWidget::instance->update();
+ });
+ if (sphere == nullptr) {
+ OpenGLWidget::instance->makeCurrent();
+ sphere = new OpenGLMesh(load_obj(":/mdl/sphere.obj", LOAD_OBJ_NORMALS | LOAD_OBJ_UVS),
+ new QOpenGLTexture(QImage(sphere_neutral, 1, 1, QImage::Format_RGB888)),
+ OpenGLWidget::instance->getMainProgram());
+ OpenGLWidget::instance->makeCurrent();
+ }
QJsonArray ja = json["drones"].toArray();
drones.reserve(ja.size());
for (const QJsonValue &o : ja) {
@@ -29,6 +49,10 @@ void DroneController::draw(QOpenGLExtraFunctions *f) const {
QMatrix4x4 mat;
mat.translate(d.getPos());
d.getMesh()->draw(f, mat);
+ if (draw_spheres) {
+ mat.scale(sphere_radius);
+ sphere->draw(f, mat);
+ }
}
}
@@ -111,6 +135,14 @@ void DroneController::computeCollisions(double sphere_radius) {
}
+void DroneController::displaySpheres(double sphere_radius) {
+ draw_spheres = true;
+ this->sphere_radius = sphere_radius;
+ sphere_timer.start(1000);
+ OpenGLWidget::instance->update();
+}
+
+
bool DroneController::collides(const Drone &a, const Drone &b, double sqDist) {
return (b.getPos() - a.getPos()).lengthSquared() < sqDist;
}