Opengl world coords change on camera rotation
-
Hi,
I build own gluUnProject, but I have big trouble with camera, when I rotate camera, world coords are changed and are incorrect.
When I just start app, my Z coordinate is incorrect, when I turn camera to left by 90 degrees, Z is in normal, but X is corrupted.
@ QMatrix4x4 viewMatrix = m_camera->viewMatrix();
QMatrix4x4 modelViewMatrix = viewMatrix * m_modelMatrix;
QMatrix4x4 modelViewProject = m_camera->projectionMatrix() * modelViewMatrix;
QMatrix4x4 inverted = m_viewportMatrix * modelViewProject;inverted = inverted.inverted(); float posZ; int posY = (int)m_viewportSize.y() - (int)mouse_position.y() - 1; m_funcs->glReadPixels((int)mouse_position.x(), posY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &posZ); QVector4D clickedPointOnScreen(mouse_position.x(), (float)posY, posZ, 1.0f); QVector4D clickedPointIn3DOrgn = inverted * clickedPointOnScreen; clickedPointIn3DOrgn = clickedPointIn3DOrgn / clickedPointIn3DOrgn.w(); terrain_pos = clickedPointIn3DOrgn.toVector3DAffine();@