Skip to content

Instantly share code, notes, and snippets.

@graphoarty
Created February 21, 2019 19:30
Show Gist options
  • Save graphoarty/735ce51f4a105668b3bb33596d26e8ff to your computer and use it in GitHub Desktop.
Save graphoarty/735ce51f4a105668b3bb33596d26e8ff to your computer and use it in GitHub Desktop.
// Add an event listener that fires the function onWindowResize on resize
window.addEventListener('resize', onWindowResize, false);
function onWindowResize() {
// Adjust the camera aspect ratio to the camera to suit the new height and width of the window
camera.aspect = window.innerWidth / window.innerHeight;
// Updates the camera's projection matrix. (docs)
camera.updateProjectionMatrix();
// Sets the size of the rendering viewport in which the camera fit in perfectly
renderer.setSize(window.innerWidth, window.innerHeight);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment