three.js camera

/*
 * Resize camera and change camera distance from 3D object
 * Ref: https://github.com/mrdoob/three.js/issues/1239
 */
function onCanvasResized( w, h )
{
  camera.aspect = w / h
  camera.updateProjectionMatrix()

  // Change camera distance for width of a 3D object in full screen
  const aspect = camera.aspect
  const height = GLOBAL_DATA.width / aspect
  const fov = camera.fov
  const dist = height / ( 2 * Math.tan( fov * Math.PI / 360 ) );
  camera.position.z = dist

  renderer.setSize(w, h)
}
/*
 * Resize camera, change camera distance from 3D object and set y camera position
 * Ref: https://github.com/mrdoob/three.js/issues/1239
 */
function onCanvasResized( w, h )
{
  camera.aspect = w / h
  camera.updateProjectionMatrix()

  // Change camera distance for width of a 3D object in full screen
  const aspect = camera.aspect
  const height = GLOBAL_DATA.width / aspect
  const a = 2 * Math.tan( camera.fov * Math.PI / 360 )
  const dist = height / a
  camera.position.z = dist

  // Get height for 3D objects
  const objH = a * dist / 2
  camera.position.y = -objH
  console.log( camera.position, height, objH )

  renderer.setSize(w, h)
}