diff options
author | ccolin | 2021-01-04 01:29:44 +0100 |
---|---|---|
committer | ccolin | 2021-01-04 01:29:44 +0100 |
commit | da37a84d5f8b2eeb1c41cba033abebdce12f148a (patch) | |
tree | 006652c81dbad1b62306e64958408c8339099c64 /src/opengl_widget.cc | |
parent | d5080935ff99e5f5e03cc05377413ee38287deec (diff) |
add drone names when guides are enabled
Diffstat (limited to 'src/opengl_widget.cc')
-rw-r--r-- | src/opengl_widget.cc | 18 |
1 files changed, 17 insertions, 1 deletions
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; +} |