PDA

View Full Version : Horizontal/Vertical FOV GLM Projection matrix.



niklasbanan
09-07-2015, 03:16 PM
Hey!

I suppose that in every new game that has an FOV(Field of view) slider in it adjusts the horizontal angle. The GLM perspective(fovy, aspect, near, far) matrix accepts an angle that is vertical.
How can I adjust the horizontal angle? Does the projection matrix calculate the relationship between the vertical/horizontal? example: if I set the vertical angle to 65 degrees, how many degrees is the horizontal angle? I know how to calculate from vertical to horizontal and from horizontal to vertical, https://en.wikipedia.org/wiki/Field_of_view_in_video_games.
If I let the user to adjust the horizontal angle with a slider and then convert it afterwards to vertical with the formula described at wikipedia, will this result in a correct relationship if I use the GLM perspective function with the converted horizontal angle?


Thanks

GClements
09-07-2015, 03:59 PM
I suppose that in every new game that has an FOV(Field of view) slider in it adjusts the horizontal angle. The GLM perspective(fovy, aspect, near, far) matrix accepts an angle that is vertical.
How can I adjust the horizontal angle?
First, look at the definition given in the gluPerspective reference page (https://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml). glm::perspective() is intended as a drop-in replacement for that function.

Second, swap x and y. I.e. replace f=cot(fovy/2) with f=cot(fovx/2), change aspect=x/y to aspect=y/x, and change the scale factors from (f/aspect,f) to (f,f/aspect).

If you want to avoid constructing the matrix yourself, you can just use glm::perspective() with fovy and aspect using the above definitions, then just swap the [0][0] and [1][1] elements afterwards.

niklasbanan
09-08-2015, 02:20 PM
Thx!

I will try this solution when I get back home!

Thx again.