Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Own gluUnProject with QMatrix4x4 and Camera
Forum Updated to NodeBB v4.3 + New Features

Own gluUnProject with QMatrix4x4 and Camera

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    glararan
    wrote on last edited by
    #1

    Hello,

    I found example to create own gluUnProject, because gluUnProject not working for me, returning NaN values.
    So I'm trying to get terrain coords from camera QMatrix4x4, but it returns incorrets values.

    Im using in camera these properties:
    viewMatrix, projectionMatrix and viewProjectionMatrix.

    I tried to figure it out with this code:
    @ QMatrix4x4 inverted = m_camera->projectionMatrix() * m_camera->viewMatrix();
    inverted = inverted.inverted();

        float posZ;
    
        // m_funcs = QOpenGLFuncions_4_0_Core
        m_funcs->glReadPixels(mouse_position.x(), mouse_position.y(), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &posZ);
    
        QVector4D clickedPointOnScreen(mouse_position.x(), mouse_position.y(), posZ, 1.0f);
        QVector4D clickedPointIn3DOrgn = inverted * clickedPointOnScreen;
    
        terrain_pos = clickedPointIn3DOrgn.toVector3D();
    
        qDebug()  << terrain_pos;@
    

    I'm with camera on position: 250.0f, 10.0f, 250.0f
    And I'm getting: QVector3D(415.715, 99.3959, 6.45992) (cursor is in center of QGLWidget screen, i calculated coords). It should be QVector3D(250.0f, 10.0f, 260f+-)

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved