PDA

View Full Version : how far translate to deep



pionek
11-25-2009, 04: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.

AdrianPi
11-25-2009, 08: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.

pionek
11-26-2009, 08: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.

AdrianPi
11-26-2009, 12:15 PM
Then do

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