ThreeJS : Calculate FOV for mesh in Orthographical Camera

1.3k views Asked by At

So I've tried to solve this issue for a couple of hours now and can't get it to work.

I have created a mesh and viewing from above in Orthographical view.

the dimensions of the mesh is: 400 * 500 the height( is it needed?) is 300

it is placed at point 0, 0, 0

the camera is positioned on 0, 5000, 0 facing straight down on 0, 0, 0

Now the only thing I need to know is how to calculate the fov

_CoreManager.GetCamera().setFov(X);

so that the camera can see the whole mesh from above + 100 units on each side so the user can see where the mesh has its bounds.

Tried this, either I did something wrong or it doesn't work for ortho, https://github.com/mrdoob/three.js/issues/1239

Thank you :)

UPDATE:

I tried a new way which I thought made sense but nope...

http://forums.cgsociety.org/archive/index.php/t-725538.html

var dist = _Camera.position.y - _mesh.position.y;
var width = _mesh.geometry.parameters.width;

var halfHorizontalFOV = Math.atan((width / 2) / dist);
halfHorizontalFOV = Algorithms.ConvertRadiansToDegrees(halfHorizontalFOV);

gives me degrees that are way off what it should be.

1

There are 1 answers

0
Yenza On BEST ANSWER

Solved my problem using the Orthograpical fix:

https://github.com/mrdoob/three.js/commit/fb07c9bc192c0eaedb9df187b35f69c37716c1aa

var zoom = orthoWidth / meshWidth;
_Camera.setZoom(zoom);