Skip to content

Instantly share code, notes, and snippets.

@Ni55aN
Created March 4, 2018 16:04
Show Gist options
  • Save Ni55aN/d30cdfeec9fb9bc13a43711b497b7e54 to your computer and use it in GitHub Desktop.
Save Ni55aN/d30cdfeec9fb9bc13a43711b497b7e54 to your computer and use it in GitHub Desktop.
import * as THREE from 'three';
export class RealZoom {
constructor({ width, height }, diag) {
var diagPX = Math.sqrt(width ** 2 + height ** 2);
var screenWidthInch = width / diagPX * diag;
var screenWidthCM = 2.54 * screenWidthInch;
var viewWidthPX = window.innerWidth;
this.viewWidthCM = viewWidthPX / width * screenWidthCM;
}
getDelta(camera) {
var vFOV = THREE.Math.degToRad( camera.fov );
var worldViewHeight = 2 * Math.tan(vFOV / 2) * camera.position.length();
var viewWidthUnit = worldViewHeight * camera.aspect;
var viewWidthMM = this.viewWidthCM * 10;
return viewWidthMM / viewWidthUnit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment