Get the coordinate of a model point from the screen

69 views Asked by At

There is a some 2D object, it is located in the coordinate range -1 to 1. In world space it is also located in these coordinates (but z is shifted by -3 units). My matrixes:

m_model.translate({0.0,0.0, -3.0});
m_view({0.0, 0.0, 0.0});
m_projection.perspective(38.0, 1.0 * 640 / 480, 0.1, 100.0);

When I click on the right edge of my circle, I want to get its coordinate, x = 1.0, since its radius = 1.0. But converting the coordinates of the screen point to NDC I get the value = 0.75...

float pt_x = (p.x()/640)*2.0f - 1.0f;
float pt_y = -(p.y()/480)*2.0f+1.0f;

click on bound

I understand that it is necessary to carry out transformations with coordinates, view and projection matrices, but so far I have not been able to get the correct result. Tnanks :)

0

There are 0 answers