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. Is in QtOpenGL gluUnProject
Forum Updated to NodeBB v4.3 + New Features

Is in QtOpenGL gluUnProject

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 5.1k 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

    Hi,

    As topic say I'm asking for gluUnProject function for OpenGL. I can't found it in 4_0 Core and I can't found it in newest release.

    Is this function just in basic OpenGL or is implented in Qt?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Indeed. With modern OpenGL you are responsible for managing matrices. Luckily Qt provides QMatrix4x4 which you can use to construct a projection matrix and it's inverse.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • G Offline
        G Offline
        glararan
        wrote on last edited by
        #3

        Ok, my camera is based on QMatrix4x4.

        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->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;@
        

        But it returns small values :/
        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)

        1 Reply Last reply
        0
        • MicPianoM Offline
          MicPianoM Offline
          MicPiano
          wrote on last edited by MicPiano
          #4

          Hi, I know this is kinda old topic. But I will still reply anyway.
          I was doing the same thing in the past few days and found out that the near-z of the perspective matrix will affect the result.
          Vector3D::unProject() already does the inverting for you.
          When you un-project a value from screen coordinates, it automatically changes the coordinates into the near-z plane.
          if you #include <GL/glu.h> you will find the mythical gluUnproject() function :)

          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