From da37a84d5f8b2eeb1c41cba033abebdce12f148a Mon Sep 17 00:00:00 2001 From: ccolin Date: Mon, 4 Jan 2021 01:29:44 +0100 Subject: add drone names when guides are enabled --- src/opengl_widget.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/opengl_widget.cc') diff --git a/src/opengl_widget.cc b/src/opengl_widget.cc index 2100af0..a4d9c8c 100644 --- a/src/opengl_widget.cc +++ b/src/opengl_widget.cc @@ -176,7 +176,7 @@ void OpenGLWidget::resizeGL(int w, int h) { void OpenGLWidget::paintGL() { - glEnable(GL_CULL_FACE); // i shouldn't have to do this every frame, should i? + glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); QMatrix4x4 trans; @@ -258,3 +258,19 @@ QOpenGLShaderProgram *OpenGLWidget::getMainProgram() { QOpenGLShaderProgram *OpenGLWidget::getLineProgram() { return &line_program; } + + +bool OpenGLWidget::project(const QVector3D &p, QPoint &point) const { + QMatrix4x4 trans; + trans.translate(0, 0, -cam_dist); + QMatrix4x4 view = trans * rot; + QVector3D projected = proj * view * p; + if (projected.x() < -1 || projected.x() > 1 + || projected.y() < -1 || projected.y() > 1 + || projected.z() < -1 || projected.z() > 1) { + return false; + } + point.setX((projected.x() / 2 + .5) * (float) width()); + point.setY(((projected.y() / 2 - .5) * -1) * (float) height()); + return true; +} -- cgit v1.2.3-70-g09d2