I'm currently working on programming a three.js scene using a PerspectiveCamera
. The goal is to display a specific sub-region of the entire camera view within the canvas, with the ability to zoom in. I have meticulously reviewed my offset values and confirmed that the zoom factor aligns logically.
When fully vertically fitted, the parameters are as follows:
current zoom 1
x 714.4099378881989 y 0 w 3755.1801242236024 h 3888
Initially, everything functions correctly when the zoom is set to 1. However, once the zoom factor is modified, the alignment goes awry. Surprisingly, increasing the zoom beyond 1 works seamlessly without any offsets, focusing on the frustum's center. Despite utilizing TrackballControls
, they should not affect this scenario since all values are being configured through code.
The relevant function responsible for updating the camera in the PerspectiveCamera
class is as follows:
updateProjectionMatrix: function () {
var near = this.near,
top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
height = 2 * top,
width = this.aspect * height,
left = - 0.5 * width,
view = this.view;
if ( this.view !== null && this.view.enabled ) {
var fullWidth = view.fullWidth,
fullHeight = view.fullHeight;
left += view.offsetX * width / fullWidth;
top -= view.offsetY * height / fullHeight;
width *= view.width / fullWidth;
height *= view.height / fullHeight;
}
var skew = this.filmOffset;
if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
this.projectionMatrixInverse.getInverse( this.projectionMatrix );
},
Upon initial analysis, it seems like the field of view (fov) pertains to the complete view rather than adjusting for sub-views. Alternatively, it might be necessary to divide the zoom by a factor based on the sub-view dimensions, but I am unsure where to commence in resolving this issue.