Skip to content

Commit

Permalink
fix: cursorzoom+ortho maxdist
Browse files Browse the repository at this point in the history
  • Loading branch information
drcmda committed Dec 2, 2021
1 parent 243c196 commit bfbd8c9
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/controls/TrackballControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand All @@ -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()
}
}
}

Expand All @@ -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))

Expand Down

0 comments on commit bfbd8c9

Please sign in to comment.