简体   繁体   English

Opengl:给定 Z 的值,将四边形拟合到屏幕上

[英]Opengl: fit a quad to screen, given the value of Z

Short Version of the question:问题的简短版本:

I will put a quad.我会放一个四边形。 I know the width and height of the screen in window coordinates, i know the Z-coordinates of the quad in 3D.我知道窗口坐标中屏幕的宽度和高度,我知道 3D 中四边形的 Z 坐标。 I know the FOVY, I know the aspect.我知道FOVY,我知道方面。 The quad will be put along Z-axis, My camera doesn't move (placed at 0, 0, 0).四边形将沿 Z 轴放置,我的相机不会移动(放置在 0、0、0)。 I want to find out the width and height of the quad IN 3D COORDINATES that will fit exactly onto my screen.我想找出恰好适合我的屏幕的四边形 IN 3D COORDINATES 的宽度和高度。

Long Version of the question:问题的长版:

I would like to put a quad along the Z-axis at the specified offset Z , I would like to find out the width and height of the quad that will exactly fill the entire screen.我想在指定的偏移Z处沿 Z 轴放置一个四边形,我想找出将完全填充整个屏幕的四边形的宽度和高度。

I used to have a post on gamedev.net that uses a formula similar to the following:我曾经在 gamedev.net 上发表过一篇文章,其中使用了类似于以下的公式:

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

Now I can never find the post!现在我再也找不到那个帖子了! Though it's similar, it is still different, because I remembered in that working formula, they do make use of screenWidth and screenHeight, which are the width and height of the screen in window coordinates.虽然相似,但还是有所不同,因为我记得在那个工作公式中,它们确实使用了 screenWidth 和 screenHeight,它们是窗口坐标中屏幕的宽度和高度。

I am not really familiar with concepts like frustum, fov and aspect so that's why I can't work out the formula on my own.我对视锥体、fov 和方面等概念并不十分熟悉,所以这就是我无法自己计算公式的原因。 Besides, I am sure I don't need gluUnproject (I tried it, but the results are way off).此外,我确定我不需要 gluUnproject (我试过了,但结果还差得很远)。 It's not some gl calls, it's just a math formula that can find out the width and height in 3D space that can fill the entire screen, IF Z offset, width in window coordinates, and height in window coordinates, are known.这不是一些gl调用,它只是一个数学公式,可以找出可以填充整个屏幕的3D空间中的宽度和高度,IF Z偏移,窗口坐标中的宽度和窗口坐标中的高度是已知的。

假设 FOV 在 YZ 平面上测量,则:

Height = Z * tan(fov/2)

width = height * aspect_ratio

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM