From bfbd8c92ba5ca5e46daec5e030151847b586cbac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=94?= Date: Thu, 2 Dec 2021 14:21:08 +0100 Subject: [PATCH] fix: cursorzoom+ortho maxdist --- src/controls/TrackballControls.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/controls/TrackballControls.ts b/src/controls/TrackballControls.ts index 0c2adf7..ce5a8e1 100644 --- a/src/controls/TrackballControls.ts +++ b/src/controls/TrackballControls.ts @@ -179,12 +179,17 @@ class TrackballControls extends EventDispatcher { } else { factor = 1.0 + (this._zoomEnd.y - this._zoomStart.y) * this.zoomSpeed - if (factor !== 1.0 && factor > 0.0) { + if (Math.abs(factor - 1.0) > this.EPS && factor > 0.0) { if ((this.object as PerspectiveCamera).isPerspectiveCamera) { + if (factor > 1.0 && this._eye.length() >= this.maxDistance - this.EPS) { + factor = 1.0 + } this._eye.multiplyScalar(factor) } else if ((this.object as OrthographicCamera).isOrthographicCamera) { + if (factor > 1.0 && this.object.zoom < this.maxDistance * this.maxDistance) { + factor = 1.0 + } this.object.zoom /= factor - this.object.updateProjectionMatrix() } else { console.warn('THREE.TrackballControls: Unsupported camera type') } @@ -206,6 +211,11 @@ class TrackballControls extends EventDispatcher { //adjust target point so that "point" stays in place this.target.lerpVectors(worldPos, this.target, factor) } + + // Update the projection matrix after all properties are changed + if ((this.object as OrthographicCamera).isOrthographicCamera) { + this.object.updateProjectionMatrix() + } } } @@ -217,18 +227,18 @@ class TrackballControls extends EventDispatcher { if (!this.domElement) return this.mouseChange.copy(this._panEnd).sub(this._panStart) - if (this.mouseChange.lengthSq()) { + if (this.mouseChange.lengthSq() > this.EPS) { if ((this.object as OrthographicCamera).isOrthographicCamera) { const orthoObject = this.object as OrthographicCamera - const scale_x = (orthoObject.right - orthoObject.left) / this.object.zoom / this.domElement.clientWidth - const scale_y = (orthoObject.top - orthoObject.bottom) / this.object.zoom / this.domElement.clientWidth + const scale_x = (orthoObject.right - orthoObject.left) / this.object.zoom + const scale_y = (orthoObject.top - orthoObject.bottom) / this.object.zoom this.mouseChange.x *= scale_x this.mouseChange.y *= scale_y + } else { + this.mouseChange.multiplyScalar(this._eye.length() * this.panSpeed) } - this.mouseChange.multiplyScalar(this._eye.length() * this.panSpeed) - this.pan.copy(this._eye).cross(this.object.up).setLength(this.mouseChange.x) this.pan.add(this.objectUp.copy(this.object.up).setLength(this.mouseChange.y))