Calculate camera zoom required for object to fit in screen height

前端 未结 1 1686
情歌与酒
情歌与酒 2020-12-06 15:36

In Three.js I\'m using this formulas to calculate visible width & height

var vFOV = camera.fov * Math.PI / 180;        // convert vertical fov to radians         


        
相关标签:
1条回答
  • 2020-12-06 16:30

    I am doing the following which is based on the boundingSphere radius:

    geometry.computeBoundingSphere();
    radius = geometry.boundingSphere.radius;
    distanceFactor = Math.abs( aspect * radius / Math.sin( fov/2 );
    

    This is based on this stuff right here and I hope i interpreted it the right way: http://www.flipcode.com/forums/thread/4172

    This distanceFactor is the factor you need to move the camera along its viewing direction to fit it correctly. At the moment i am not sure if it is by height or width but maybe it helps you figure it out. :)

    0 讨论(0)
提交回复
热议问题