onSinglePanMove method

dynamic onSinglePanMove(
  1. dynamic event,
  2. dynamic opState
)

Implementation

onSinglePanMove(event, opState) {
  if (this.enabled) {
    var restart = opState != this._state;
    this.setCenter(event.clientX, event.clientY);

    switch (opState) {
      case STATE2.PAN:
        if (this.enablePan) {
          if (restart) {
            //switch to pan operation

            this.dispatchEvent(_endEvent);
            this.dispatchEvent(_startEvent);

            this.updateTbState(opState, true);
            this._startCursorPosition.copy(this.unprojectOnTbPlane(
                this.camera, _center.x, _center.y, this.domElement));
            if (this.enableGrid) {
              this.drawGrid();
            }

            this.activateGizmos(false);
          } else {
            //continue with pan operation
            this._currentCursorPosition.copy(this.unprojectOnTbPlane(
                this.camera, _center.x, _center.y, this.domElement));
            this.applyTransformMatrix(this
                .pan(this._startCursorPosition, this._currentCursorPosition));
          }
        }

        break;

      case STATE2.ROTATE:
        if (this.enableRotate) {
          if (restart) {
            //switch to rotate operation

            this.dispatchEvent(_endEvent);
            this.dispatchEvent(_startEvent);

            this.updateTbState(opState, true);
            this._startCursorPosition.copy(this.unprojectOnTbSurface(
                this.camera,
                _center.x,
                _center.y,
                this.listenableKey,
                this._tbRadius));

            if (this.enableGrid) {
              this.disposeGrid();
            }

            this.activateGizmos(true);
          } else {
            //continue with rotate operation
            this._currentCursorPosition.copy(this.unprojectOnTbSurface(
                this.camera,
                _center.x,
                _center.y,
                this.listenableKey,
                this._tbRadius));

            var distance = this
                ._startCursorPosition
                .distanceTo(this._currentCursorPosition);
            var angle = this
                ._startCursorPosition
                .angleTo(this._currentCursorPosition);
            var amount = Math.max(
                distance / this._tbRadius, angle); //effective rotation angle

            this.applyTransformMatrix(this.rotate(
                this.calculateRotationAxis(
                    this._startCursorPosition, this._currentCursorPosition),
                amount));

            if (this.enableAnimations) {
              this._timePrev = this._timeCurrent;
              this._timeCurrent = DateTime.now().millisecondsSinceEpoch;
              this._anglePrev = this._angleCurrent;
              this._angleCurrent = amount;
              this._cursorPosPrev.copy(this._cursorPosCurr);
              this._cursorPosCurr.copy(this._currentCursorPosition);
              this._wPrev = this._wCurr;
              this._wCurr = this.calculateAngularSpeed(this._anglePrev,
                  this._angleCurrent, this._timePrev, this._timeCurrent);
            }
          }
        }

        break;

      case STATE2.SCALE:
        if (this.enableZoom) {
          if (restart) {
            //switch to zoom operation

            this.dispatchEvent(_endEvent);
            this.dispatchEvent(_startEvent);

            this.updateTbState(opState, true);
            this._startCursorPosition.setY(
                this.getCursorNDC(_center.x, _center.y, this.domElement).y *
                    0.5);
            this._currentCursorPosition.copy(this._startCursorPosition);

            if (this.enableGrid) {
              this.disposeGrid();
            }

            this.activateGizmos(false);
          } else {
            //continue with zoom operation
            var screenNotches =
                8; //how many wheel notches corresponds to a full screen pan
            this._currentCursorPosition.setY(
                this.getCursorNDC(_center.x, _center.y, this.domElement).y *
                    0.5);

            var movement =
                this._currentCursorPosition.y - this._startCursorPosition.y;

            num size = 1;

            if (movement < 0) {
              size =
                  1 / (Math.pow(this.scaleFactor, -movement * screenNotches));
            } else if (movement > 0) {
              size = Math.pow(this.scaleFactor, movement * screenNotches);
            }

            this.applyTransformMatrix(
                this.scale(size, this._gizmos.position));
          }
        }

        break;

      case STATE2.FOV:
        if (this.enableZoom && this.camera is PerspectiveCamera) {
          if (restart) {
            //switch to fov operation

            this.dispatchEvent(_endEvent);
            this.dispatchEvent(_startEvent);

            this.updateTbState(opState, true);
            this._startCursorPosition.setY(
                this.getCursorNDC(_center.x, _center.y, this.domElement).y *
                    0.5);
            this._currentCursorPosition.copy(this._startCursorPosition);

            if (this.enableGrid) {
              this.disposeGrid();
            }

            this.activateGizmos(false);
          } else {
            //continue with fov operation
            var screenNotches =
                8; //how many wheel notches corresponds to a full screen pan
            this._currentCursorPosition.setY(
                this.getCursorNDC(_center.x, _center.y, this.domElement).y *
                    0.5);

            var movement =
                this._currentCursorPosition.y - this._startCursorPosition.y;

            num size = 1;

            if (movement < 0) {
              size =
                  1 / (Math.pow(this.scaleFactor, -movement * screenNotches));
            } else if (movement > 0) {
              size = Math.pow(this.scaleFactor, movement * screenNotches);
            }

            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._fovState * 0.5);

            //calculate new fov
            var newFov = MathUtils.RAD2DEG * (Math.atan(y / xNew) * 2);

            //check min and max fov
            newFov = MathUtils.clamp(newFov, this.minFov, this.maxFov);

            var newDistance = y / Math.tan(MathUtils.DEG2RAD * (newFov / 2));
            size = x / newDistance;
            this._v3_2.setFromMatrixPosition(this._gizmoMatrixState);

            this.setFov(newFov);
            this.applyTransformMatrix(this.scale(size, this._v3_2, false));

            //adjusting distance
            _offset
                .copy(this._gizmos.position)
                .sub(this.camera.position)
                .normalize()
                .multiplyScalar(newDistance / x);
            this._m4_1.makeTranslation(_offset.x, _offset.y, _offset.z);
          }
        }

        break;
    }

    this.dispatchEvent(_changeEvent);
  }
}