What I am trying to do is reposition the camera by adjusting its position.y
property so that the model "moves" towards the top of the viewport (i.e. camera.position.y -= N) as the user scrolls down the page. In other words, what I am trying to do is figure out how to calculate the value by which I must adjust camera.position.y
so that the bottom of the model is sitting right above the top of the viewport without actually moving the camera manually and then hardcoding this value.
We can create a new THREE.Box3().setFromObject(model)
object, which provides the outerbounds of the model. Then, there is the distanceToPoint
method, but what is the "point" of the top of the viewport i.e. the max frustum value?
The camera.fov
value is 7
, but this means the viewing angle of the frustum is 7
degrees.
If 7
were instead a camera.position.y
unit instead of degrees, fov - Math.abs(boundingBox.min.y))
would return the distance from the top of the viewport or the max frustum value to the bottom of the model.
I have no idea how to calculate how far down I need to move the camera so that the model is moved towards the top of the viewport so that the model is completely out of view and not a single pixel more out of view. How can I calculate the distance from the top of the viewport or max frustum value to the bottom of the model in camera.position.y units? Does anybody know how to calculate this?