[Interest] Qt3D depth buffer picking

Davide Davelli davellidavide at gmail.com
Mon Feb 26 15:55:20 CET 2018


Hello,
I'm trying to implement a mesh viewer using the Qt3D framework and I cannot
find a way get the "3D position" of the mouse cursor by picking the depth
buffer.

How can I do something like this?:

/// get 3d world point from clicked position
QVector3D Forensic3DWindow::getMouse3DPoint(const QPoint& point2d)
{
float depth = 1;
float x = point2d.x();
float y = height() - 1 - point2d.y();
        glReadPixels(x, y , 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);

if (depth < 1)
{
     int viewport[4];
     glGetIntegerv(GL_VIEWPORT, viewport);
     // the following does the same as gluUnProject:
     QVector3D point = QVector3D(2 * (x - viewport[0]) / viewport[2] - 1, 2
* (height() - 1 - y -                 viewport[1]) / viewport[3] - 1, 2 *
depth - 1);
     QMatrix4x4 world = camera()->projectionMatrix() *
camera()->viewMatrix();
     return world.inverted().map(point);
}
return QVector3D();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180226/2566d1e7/attachment.html>


More information about the Interest mailing list