How to Get World space coordinate from screen coordinates

  c++, glm-math, opengl

How can we translate the Screen Space coordinate to World space coordinate.

  1. in the below image the circle is drawn at position 0.0 , 0.0 , 0.0

enter image description here

Now if we move it to position -200 in x axis.

enter image description here

if we get the screen space vales by clicking on the centre point of the circle than the given values are (435 , 563)

From these values how can we get the value in world space which should be (-200.0 , 0.0 , 0.0 )

i tried following

 // Get View and Projection matrix
 glm::mat VP_Matrix = Projection * View;
 // Invert the matrix
 VP_Matrix = glm::Invert(VP_Matrix)
// Multiply it by Screen Space coordinate
glm::vec4 point = ( screen.x , screen.y , 0.0 , 1.0);
glm::vec4 finalPoint = VP_Matrix * point;


 // Final points 
 finalPoint.x /= finalPoint.w;
 finalPoint.y /= finalPoint.w;

But not able to get the correct points.

Source: Windows Questions C++

LEAVE A COMMENT