PDA

View Full Version : perspective in window



dlswimmer
12-21-2004, 09:40 AM
hey guys... I'm having issues trying something out. I don't know if it is just my dumb mistake or just this long day at work. I have set my perspective fov to 45 degrees. I have the aspect ratio set with the window height and width. Now what I am trying to do is to get the coordinates in opengl to match that in my window. I don't want the axis to match or anything, I just want the height and width to match the window. The window is 1024x664. Again, the fov is 45 degrees. I am using gluLookAt and have 0,0 for the placement. The thing I am trying to figure out is the distance back I have to be to have the same dimensions. I thought it would be some simple math, like view_z = width/2 / tan(45/2) , but it is not coming out right. Can anyone tell me what I have to put in for the view_z to get the right dimensions. Thank you very much.

dlswimmer
12-21-2004, 09:58 AM
alright, here was my thinking so tell me if I am wrong. The 45 degree fov creates a cone. If this was split right down the Z-plane, this would create a half cone at 22.5 degrees. I could take a cross section of this, which would be a right triangle. I could then take the side opposite the angle and the tangent to that angle (22.5) and using the trusty tan(x) = O/A ~ A = O/tan(x) where the adjacent side is the distance back. Now the Opposite side would be the width, since this is larger than the height. I thought that this would be correct, but it does not give me the correct dimensions. I created some boxes to get a rough idea of the dimensions and the opengl dimensions come out to be something like 1170x780 where I need them to be 664x1024

dlswimmer
12-22-2004, 06:02 AM
of course I would have to adjust by my aspect ratio... I looked at the info for the gluperspective and I understood it, I just didn't realize that I had to do that math for the z value.