onWheel method
dynamic
onWheel(
- dynamic event
Implementation
onWheel(event) {
if (this.enabled && this.enableZoom) {
var modifier = null;
if (event.ctrlKey || event.metaKey) {
modifier = 'CTRL';
} else if (event.shiftKey) {
modifier = 'SHIFT';
}
var mouseOp = this.getOpFromAction('WHEEL', modifier);
if (mouseOp != null) {
event.preventDefault();
this.dispatchEvent(_startEvent);
var notchDeltaY = 125; //distance of one notch of mouse wheel
var sgn = event.deltaY / notchDeltaY;
double size = 1;
if (sgn > 0) {
size = 1 / this.scaleFactor;
} else if (sgn < 0) {
size = this.scaleFactor;
}
switch (mouseOp) {
case 'ZOOM':
this.updateTbState(STATE2.SCALE, true);
if (sgn > 0) {
size = 1 / (Math.pow(this.scaleFactor, sgn));
} else if (sgn < 0) {
size = Math.pow(this.scaleFactor, -sgn) + 0.0;
}
if (this.cursorZoom && this.enablePan) {
var scalePoint;
if (this.camera is OrthographicCamera) {
scalePoint = this
.unprojectOnTbPlane(this.camera, event.clientX,
event.clientY, this.domElement)
.applyQuaternion(this.camera.quaternion)
.multiplyScalar(1 / this.camera.zoom)
.add(this._gizmos.position);
} else if (this.camera is PerspectiveCamera) {
scalePoint = this
.unprojectOnTbPlane(this.camera, event.clientX,
event.clientY, this.domElement)
.applyQuaternion(this.camera.quaternion)
.add(this._gizmos.position);
}
this.applyTransformMatrix(this.scale(size, scalePoint));
} else {
this.applyTransformMatrix(
this.scale(size, this._gizmos.position));
}
if (this._grid != null) {
this.disposeGrid();
this.drawGrid();
}
this.updateTbState(STATE2.IDLE, false);
this.dispatchEvent(_changeEvent);
this.dispatchEvent(_endEvent);
break;
case 'FOV':
if (this.camera is PerspectiveCamera) {
this.updateTbState(STATE2.FOV, true);
//Vertigo effect
// fov / 2
// |\
// | \
// | \
// x | \
// | \
// | \
// | _ _ _\
// y
//check for iOs shift shortcut
if (event.deltaX != 0) {
sgn = event.deltaX / notchDeltaY;
size = 1;
if (sgn > 0) {
size = 1 / (Math.pow(this.scaleFactor, sgn));
} else if (sgn < 0) {
size = Math.pow(this.scaleFactor, -sgn) + 0.0;
}
}
this._v3_1.setFromMatrixPosition(this._cameraMatrixState);
var x = this._v3_1.distanceTo(this._gizmos.position);
var xNew = x /
size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
//check min and max distance
xNew = MathUtils.clamp(xNew, this.minDistance, this.maxDistance);
var y = x * Math.tan(MathUtils.DEG2RAD * this.camera.fov * 0.5);
//calculate new fov
var newFov = MathUtils.RAD2DEG * (Math.atan(y / xNew) * 2);
//check min and max fov
if (newFov > this.maxFov) {
newFov = this.maxFov;
} else if (newFov < this.minFov) {
newFov = this.minFov;
}
var newDistance = y / Math.tan(MathUtils.DEG2RAD * (newFov / 2));
size = x / newDistance;
this.setFov(newFov);
this.applyTransformMatrix(
this.scale(size, this._gizmos.position, false));
}
if (this._grid != null) {
this.disposeGrid();
this.drawGrid();
}
this.updateTbState(STATE2.IDLE, false);
this.dispatchEvent(_changeEvent);
this.dispatchEvent(_endEvent);
break;
}
}
}
}