### Two small helpers for doing multiscreen 3D

My current work project involves displaying a panoramic 3D scenery "seamlessly" across a multi-screen/multi-machine setup. The system needs to support a flexible number of viewports and screen dimensions, so each client will have to be coded with a flexible view frustum in mind: Say, if there're 6 machines used, each box will have to render 60 degrees of the panorama...

Now the issue at hand is that Processing, Shockwave3D and many other 3D engines based on OpenGL usually specify their view angle (FOV) in the vertical direction, not horizontally (as I always assumed since it's far more natural). That's not very helpful in my situation above as I need to figure out the horizontal orientation of each machine's camera/viewport:

Machine #1 camera rotation @ 30 (renders 0-60 degrees)

Machine #2 camera rotation @ 90 (renders 60-120 degrees)

etc.

Since most displays are not squared, but rectangular, the horizontal FOV will be larger than the vertical, but exactly how much? Of course there're ways to easily compute this horizontal angle, only googling for a solution did take me quite a while - and of course I found it where I'd thought I would - on Paul Bourke's site (incidentally, one of my favourite websites)

So here's a tiny code snippet to convert FOV bothways, in case you'll ever run into similar situations:

Now the issue at hand is that Processing, Shockwave3D and many other 3D engines based on OpenGL usually specify their view angle (FOV) in the vertical direction, not horizontally (as I always assumed since it's far more natural). That's not very helpful in my situation above as I need to figure out the horizontal orientation of each machine's camera/viewport:

Machine #1 camera rotation @ 30 (renders 0-60 degrees)

Machine #2 camera rotation @ 90 (renders 60-120 degrees)

etc.

Since most displays are not squared, but rectangular, the horizontal FOV will be larger than the vertical, but exactly how much? Of course there're ways to easily compute this horizontal angle, only googling for a solution did take me quite a while - and of course I found it where I'd thought I would - on Paul Bourke's site (incidentally, one of my favourite websites)

So here's a tiny code snippet to convert FOV bothways, in case you'll ever run into similar situations:

/**

* computes horizontal FOV from window size and vertical FOV

* @param fov vertical FOV (in degrees)

* @return horizontal FOV (in degrees)

*/

float apertureV2H(float fovV) {

fovV=radians(fovV);

return degrees(2*atan(width*tan(fovV/2)/height));

}

/**

* computes vertical FOV from window size and horizontal FOV

* @param fov horizontal FOV (in degrees)

* @return vertical FOV (in degrees)

*/

float apertureH2V(float fovH) {

fovH=radians(fovH);

return degrees(2*atan(height*tan(fovH/2)/width));

}

Tags: 3d fov programming math processing.org panorama opengl

<< Home