View Full Version : how far translate to deep

11-25-2009, 03:55 PM
Hi, my question is simple but I can't find answer anywere.

I draw rectangle with rWidth that (0, 0) is in the center. How far translate it to deep along Z axis so as to left and right border of rect touch exactly screen border with sWidth?

I find this: sWidth/sin(45) but this isn't precise (bit deeply). Is there any formula on this?

Im using OpenGL ES on win mobile.

11-25-2009, 07:41 PM
Tangent is opposite over adjacent.
Thus, adjacent is opposite over tangent.

So, the distance (adjacent) is rectwidth/2 (opposite) over tan(fov/2). Following your naming:

d = (rWidth/2) / tan(fov/2)

Where fov is the field of view of your camera.

11-26-2009, 07:33 AM
Yeah, Im stu...

It works for me with height, because my gluPerspective function was calculated on fov in horizontal along y axis.
Im actualy changing to fovx, thanks a lot.

11-26-2009, 11:15 AM
Then do

d = (rWidth/2) / (tan(fov/2)*aspect)