Hello,
I have big problem, I don’t know why gluUnProject returning NaN values, so I trying to build own gluUnProject, but is failing.
Target platform: Crossplatform
Framework: Qt5
Library: QOpenGL, not QGL!
OpenGL ver: 4.0+
Current OS: Windows 8
So I’m trying to get terrain coords from my own camera class with QMatrix4×4, but it returns incorrets 3D values.
Im using in camera these properties:
viewMatrix, projectionMatrix and viewProjectionMatrix.
I tried to figure it out with this code:
[ol]
[li][FONT=arial] QMatrix4x4 inverted [COLOR=#363534]= m_camera->projectionMatrix() * (m_camera->viewMatrix() * m_modelMatrix);[/li][li] inverted = inverted.inverted();[/li][li] float posZ;[/li][li] [COLOR=green]// m_funcs = QOpenGLFuncions_4_0_Core[/COLOR][/li][li] m_funcs->glReadPixels(mouse_position.x(), mouse_position.y(), 1, 1,GL_DEPTH_COMPONENT, GL_FLOAT, &posZ);[/li][li] QVector4D clickedPointOnScreen(mouse_position.x(),mouse_position.y(), posZ, 1.0f);[/li][li] QVector4D clickedPointIn3DOrgn = inverted * clickedPointOnScreen;[/li][li] terrain_pos = clickedPointIn3DOrgn.toVector3D();[/li][li] [b]qDebug/b << terrain_pos;[/li][/ol]
[/FONT][/COLOR]
I’m with camera on position: 250.0f, 10.0f, 250.0f
And I’m getting in result: QVector3D(414.76, 105.6, 6.37669) (cursor is in center of QGLWidget screen [935, 475], i calculated coords). It should be QVector3D(250.0f, 10.0f, 260f±)
To calculated coords: I have fullHD = 1920x1080, but QGLWidget is only 1870x950
To QGLWidget: I’m using it because QtGui cannot have controls which I needed (making editor)
Edit: Camera is perspective mode!
Edit2: posZ is often 0.9xxx, maximum 1