In my first topic I asked for help with gluUnproject.

My current code is almost finished, but it still have one bug, that's camera rotation.

I tried it explain in following picture:
Click image for larger version. 

Name:	camera.jpg 
Views:	488 
Size:	9.9 KB 
ID:	1108

By my words: On 0 degrees is corrupted world coordinate Z, on -90 degrees is Z fine but X coordinate became corrupted

Source code:

Code :
        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();