Skip to content

Instantly share code, notes, and snippets.

@manthrax
Created November 29, 2021 12:58
Show Gist options
  • Save manthrax/aa0012cd870421465a4902d0006e88b4 to your computer and use it in GitHub Desktop.
Save manthrax/aa0012cd870421465a4902d0006e88b4 to your computer and use it in GitHub Desktop.
threejs update horizontal fov projectionmatrix
const DEG2RAD = Math.PI / 180;
let updateProjectionMatrixHorizontalFOV = (camera)=>{
const near = camera.near;
/*
let top = near * Math.tan( DEG2RAD * 0.5 * camera.fov ) / camera.zoom;
let height = 2 * top;
let width = camera.aspect * height;
let left = - 0.5 * width;
*/
let left = -near * Math.tan( DEG2RAD * 0.5 * camera.fov ) / camera.zoom;
let width = -2 * left;
let height = width / camera.aspect ;
let top = 0.5 * height;
const view = camera.view;
if ( camera.view !== null && camera.view.enabled ) {
const fullWidth = view.fullWidth,
fullHeight = view.fullHeight;
left += view.offsetX * width / fullWidth;
top -= view.offsetY * height / fullHeight;
width *= view.width / fullWidth;
height *= view.height / fullHeight;
}
const skew = camera.filmOffset;
if ( skew !== 0 ) left += near * skew / camera.getFilmWidth();
camera.projectionMatrix.makePerspective( left, left + width, top, top - height, near, camera.far );
camera.projectionMatrixInverse.copy( camera.projectionMatrix ).invert();
}
/// instead of: perspectiveCamera.updateProjectionMatrix();
//Call:
updateProjectionMatrixHorizontalFOV(perspectiveCamera)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment