-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculating the FOV for the Perspective camera #1239
Comments
The visible height = 2 * Math.tan( ( vFOV / 2 ) ) * dist; The visible aspect = window_width / window_height;
hFOV = 2 * Math.atan( Math.tan( vFOV / 2 ) * aspect );
width = 2 * Math.tan( ( hFOV / 2 ) ) * dist; The field-of-view parameter for the camera in THREE.js is the vertical one. Use the two sets of equations to calculate the required vFOV twice, and select the larger answer. |
Thank you so much for replying :) I created a Fiddle http://jsfiddle.net/dmYgr/6/ Agains thank you so much. From your post I can already sense you're more of a genius than me ;) |
Use the first equation and solve for |
My scene is 800 * 600. How do I use these numbers in your formula. height = 2 * Math.tan( ( vFOV / 2 ) ) * dist; <-- You're telling me to start here, but what number should replace vFOV? |
Use the first equation and solve for vFOV = 2 * Math.atan( height / ( 2 * distance ) ); then use that as the |
var renderWidth = 800;
var renderHeight = 600;
var cameraPosition = 1000; var vFOV = 2 * Math.atan( renderWidth / ( 2 * cameraPosition ) );
var height = 2 * Math.tan( ( vFOV / 2 ) ) * cameraPosition;
var aspect = renderWidth / renderHeight;
var hFOV = 2 * Math.atan( Math.tan( vFOV / 2 ) * aspect );
var width = 2 * Math.tan( ( hFOV / 2 ) ) * cameraPosition; Result: var vFOV = 2 * Math.atan( renderHeight / ( 2 * cameraPosition ) );
var height = 2 * Math.tan( ( vFOV / 2 ) ) * cameraPosition;
var aspect = renderWidth / renderHeight;
var hFOV = 2 * Math.atan( Math.tan( vFOV / 2 ) * aspect );
var width = 2 * Math.tan( ( hFOV / 2 ) ) * cameraPosition; vFOV = 0.5829135889557342 which is also not a valid FOV Can you fill in the example for me and show an example that does give a valid FOV number? |
In your fiddle, height = height of your plane mesh = 500. distance = camera.z - plane.z = 1000 - 100 = 900. vFOV = 2 * Math.atan( height / ( 2 * distance ) ) = 0.5419 radians, or 31.04 degrees. |
2 * Math.atan( 500 / ( 2 * 900 ) ) = 0.5418937006768411 according to my browser (google chrome) |
Sorry, I neglected to show the conversion from radians to degrees. I updated my previous post. |
Thank you SO Much! :D |
@Tobiasartz :-) |
West Langley. You are a king. Thank you. |
This was super helpful !! Thanks @WestLangley ! |
Thank you @WestLangley !! var distance = 1000;
var FOV = 2 * Math.atan( window.innerHeight / ( 2 * distance ) ) * 180 / Math.PI;
var camera = new THREE.PerspectiveCamera( FOV, window.innerWidth/window.innerHeight, 0.1, distance );
camera.position.z = distance; |
@Emanuele-Spatola Your formula does not make sense. |
I updated Tobiasartz's fiddle with that formula and it seems to work: |
Have you ever placed a camera 1000 pixels in front of your subject? |
You might place a real camera 10 feet away to look at a scene 10 feet wide. Similarly you could place a virtual camera 1000px away to view a scene 1000px wide. |
I use this when I know the height, width of scene and distance of camera...
This way situations like height > width also get handled ... |
Since I have no previous experience with 3D I run in to some problems that might be common knowledge to you 3D pro's ;).
I have a wide variety of scene sizes (800x600, 1200x100 etc.).
What formula can I use to make sure that an object with a z position of 0 and a width and height that is the same as the scene fills up the entire scene.
E.g.: Object Mesh A is 1200x100 and is on Z position 0. The scene is 1200x100 as well. The camera is on z position 1500. What is the FOV to make the object fill the scene?
Something along the line of ((A / B ) * C) is what I'm looking for :D.
Infinite amount of kudos to whoever is brilliant enough to answer my question :)
The text was updated successfully, but these errors were encountered: