Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Threejs Fit plane to screen
var cameraZ = camera.position.z;
var planeZ = 5;
var distance = cameraZ - planeZ;
var aspect = viewWidth / viewHeight;
var vFov = camera.fov * Math.PI / 180;
var planeHeightAtDistance = 2 * Math.tan(vFov / 2) * distance;
var planeWidthAtDistance = planeHeightAtDistance * aspect;
// or
let dist = camera.position.z - mesh.position.z;
let height = ... // desired height to fit
camera.fov = 2 * Math.atan(height / (2 * dist)) * (180 / Math.PI);
camera.updateProjectionMatrix();
// Basically solving an AAS triangle https://www.mathsisfun.com/algebra/trig-solving-aas-triangles.html
https://i.stack.imgur.com/PgSn3.jpg
@vlucendo

This comment has been minimized.

Copy link

@vlucendo vlucendo commented Oct 23, 2018

Very handy, I was looking for this 👍

@vin-ni

This comment has been minimized.

Copy link

@vin-ni vin-ni commented Jul 10, 2019

thank you!

@nicoptere

This comment has been minimized.

Copy link

@nicoptere nicoptere commented Jul 18, 2019

thanks poussin ! 🥇

@seriusokhatsky

This comment has been minimized.

Copy link

@seriusokhatsky seriusokhatsky commented Aug 23, 2019

Thank you!

@kevinboudot

This comment has been minimized.

Copy link

@kevinboudot kevinboudot commented Sep 6, 2019

Merci copain ! <3

@thibka

This comment has been minimized.

Copy link

@thibka thibka commented Aug 23, 2020

Thanks!

@halfmagic

This comment has been minimized.

Copy link

@halfmagic halfmagic commented Sep 7, 2020

Great, thank you!

@mikatalk

This comment has been minimized.

Copy link

@mikatalk mikatalk commented Oct 10, 2020

Excellent, merci! 🌟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.