Perspective camera . If the camera is in the center and is viewing a cube, define
dist = distance from the camera to the front surface (important!) of the cube
and
height = cube height.
If you set the camera field of view as follows
fov = 2 * Math.atan( height / ( 2 * dist ) ) * ( 180 / Math.PI );
then the height of the cube will correspond to the visible height.
Spelling camera . If the camera is in the center and is viewing a cube, define
aspect = aspect ratio of your window (i.e. width / height)
and
height = cube height.
Then create a camera as follows:
camera = new THREE.OrthographicCamera( -aspect * height/2, aspect * height/2, height/2, -height/2, near, far );
The height of the cube will correspond to the visible height.
In any case, if the camera is not centered or otherwise views the cube at an angle, the problem becomes more complex.
In addition, if the window is narrower than tall, then the width is a deterrent, and the problem is more complicated.
Westlangley
source share