Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement