开发者

In OpenGL, How can I determine the bounds of the view at a given depth

开发者 https://www.devze.com 2023-03-19 23:47 出处:网络
I\'m playing around with OpenGL and I\'ve got a question that I haven\'t been able to find an answer to or at least haven\'t found the right way to ask search engines. I have a a pretty simple setup.

I'm playing around with OpenGL and I've got a question that I haven't been able to find an answer to or at least haven't found the right way to ask search engines. I have a a pretty simple setup. An 800x600 viewport and a projection matrix with a 45 degree field of view and near and far pl开发者_如何学Canes of 1.0 and 200.0. For the sake of discussion, the modelview matrix is the identity matrix.

What I'm trying to determine is the bounds of the view at a given depth. For example, (0,0,0) is the center of the screen. And I'm looking in the -Z direction.

I want to know, if I draw geometry on a plane 100 units into the screen (0,0,-100), what are the bounds of the view? How far in the x and y direction can I draw in this plane and the geometry still be visible.

More generically, Given a plane parallel to the near and far plane (and between them), what are the visible bounds of that plane?

Also, if what I'm trying to determine has a common name or is a common operation, what's it called? That way I can track down more reading material


Your view angle is 45 degrees, you have a plane at a distance of a away from the camera, with an unkown height h. The whole thing looks like this:

In OpenGL, How can I determine the bounds of the view at a given depth

Note that the angle here is half of your field of view.

Dusting off the highschool maths books, we get:

tan(angle) = h/a

Rearrange for h and subsitute the half field of view:

h = tan(FieldOfView / 2) * a;

This is how much your plane extends upwards along the Y axis.

Since screens aren't square, the width of your plane is different to the height. More exactly, the width is the aspect ratio times the height. I.e. w = h * aspectRatio

I hope this answers your question.

0

精彩评论

暂无评论...
验证码 换一张
取 消