Opengl: set the square to the screen, given the value of Z

Short version of the question:

I'll put a quad. I know the width and height of the screen in the coordinates of the window, I know the Z-coordinates of the quad in 3D. I know FT, I know this aspect. The square will be placed along the Z axis, My camera does not move (fits in 0, 0, 0). I want to know the width and height of four-dimensional COORDINATES that will exactly fit my screen.

Long version of the question:

I would like to put a square along the Z axis at the indicated offset Z, I would like to know the width and height of the ATV that will accurately fill the entire screen.

I used to have mail on gamedev.net that uses a formula similar to the following:

* dist = Z * tan (FOV / 2) *

Now I can never find a message! Although it is similar, it is still different, because I remember in this working formula, they use screenWidth and screenHeight, which are the width and height of the screen in the window coordinates.

I am not very familiar with concepts such as truncation, fov and aspect, so I can not independently develop a formula. Also, I'm sure I don't need gluUnproject (I tried, but the results are gone). These are not some gl calls, it's just a mathematical formula that can find out the width and height in three-dimensional space that can fill the entire screen, the IF Z offset, the width in the window coordinates and the height in the window coordinates.

+4
source share
1 answer

Assuming FOV is measured in the YZ plane, then:

Height = Z * tan(fov/2)

width = height * aspect_ratio

+4
source

Source: https://habr.com/ru/post/1334155/


All Articles