Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js - Width of view

Tags:

Is there a way to find out the width of a rendered portion of the scene?

For example, if we have a mesh of width 100, but rendered with a certain level of zoom...how can I calculate the width of the portion of the mesh that is being rendered in the screen?

like image 320
Leprosy Avatar asked Nov 12 '12 20:11

Leprosy


1 Answers

You have to be precise here.

You can calculate the visible rectangular region given the camera's field-of-view, camera.fov, and a given distance, dist, from the camera.

Since the object presumably has depth, you have to pick one plane through the mesh, and do the calculation at that distance.

Here is how to calculate the visible height and width for a given distance dist from the camera.

var vFOV = THREE.MathUtils.degToRad( camera.fov ); // convert vertical fov to radians

var height = 2 * Math.tan( vFOV / 2 ) * dist; // visible height

var width = height * camera.aspect;           // visible width

three.js r.117

like image 70
WestLangley Avatar answered Oct 14 '22 05:10

WestLangley