如何在Three.js中并行使用相机上的视图偏移和缩放属性

我正在尝试使用PerspectiveCamera对Three.js场景进行编程。画布将显示整个摄像机视图的子区域,并且还将具有缩放比例。我已经仔细检查过我的偏移量数字是否正确以及缩放系数是否合理。

完全垂直适合时

current zoom 1 
x 714.4099378881989 y 0 w 3755.1801242236024 h 3888

当缩放为1时,偏移量可以完美工作,但是当缩放系数更改时,一切都会偏离轨道。缩放> 1也可以按预期工作,没有视图偏移,并以视锥体的中心为目标。我正在使用trackballControls,但由于我是通过编程方式设置所有值,因此它们不应该在这里使用。

PerspectiveCamera类中的三个是相关的相机更新功能

    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 );

    },

我的最初反应是fov用于全视图,但应针对子视图进行调整,或者应该将缩放除以从子视图大小得出的某些因子,但是我不确定从哪里开始

williamlee3399 回答:如何在Three.js中并行使用相机上的视图偏移和缩放属性

想通了。

我正在执行更新功能

    this.zoom = zoom;

    this.setViewOffset(
      full.w,full.h,offset.x,offset.y,offset.w,offset.h
    );

    this.controls.update();

但是我需要做的是更改缩放比例,使其相对于偏移量

this.zoom = zoom * (offset.h / full.h)

本文链接:https://www.f2er.com/3099009.html

大家都在问