Is in QtOpenGL gluUnProject
-
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?
-
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.
-
Ok, my camera is based on QMatrix4x4.
Im using in camera these properties:
viewMatrix, projectionMatrix and viewProjectionMatrixI 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) -
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 :)