update method

dynamic update()

Implementation

update() {
  var position = scope.object.position;
  offset.copy(position).sub(scope.target);

  // rotate offset to "y-axis-is-up" space
  offset.applyQuaternion(quat);

  // angle from z-axis around y-axis
  spherical.setFromVector3(offset);

  if (scope.autoRotate && state == State.none) {
    rotateLeft(getAutoRotationAngle());
  }

  if (scope.enableDamping) {
    spherical.theta += sphericalDelta.theta * scope.dampingFactor;
    spherical.phi += sphericalDelta.phi * scope.dampingFactor;
  } else {
    spherical.theta += sphericalDelta.theta;
    spherical.phi += sphericalDelta.phi;
  }

  // restrict theta to be between desired limits

  var min = scope.minAzimuthAngle;
  var max = scope.maxAzimuthAngle;

  if (isFinite(min) && isFinite(max)) {
    if (min < -Math.pi) {
      min += twoPI;
    } else if (min > Math.pi) {
      min -= twoPI;
    }

    if (max < -Math.pi) {
      max += twoPI;
    } else if (max > Math.pi) {
      max -= twoPI;
    }

    if (min <= max) {
      spherical.theta = Math.max(min, Math.min(max, spherical.theta));
    } else {
      spherical.theta =
          (spherical.theta > (min + max) / 2) ? Math.max(min, spherical.theta) : Math.min(max, spherical.theta);
    }
  }

  // restrict phi to be between desired limits
  spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));

  spherical.makeSafe();

  spherical.radius *= scale;

  // restrict radius to be between desired limits
  spherical.radius = Math.max(scope.minDistance, Math.min(scope.maxDistance, spherical.radius));

  // move target to panned location

  if (scope.enableDamping == true) {
    scope.target.addScaledVector(panOffset, scope.dampingFactor);
  } else {
    scope.target.add(panOffset);
  }

  offset.setFromSpherical(spherical);

  // rotate offset back to "camera-up-vector-is-up" space
  offset.applyQuaternion(quatInverse);
  position.copy(scope.target).add(offset);

  scope.object.lookAt(scope.target);

  if (scope.enableDamping == true) {
    sphericalDelta.theta *= (1 - scope.dampingFactor);
    sphericalDelta.phi *= (1 - scope.dampingFactor);

    panOffset.multiplyScalar(1 - scope.dampingFactor);
  } else {
    sphericalDelta.set(0, 0, 0);

    panOffset.set(0, 0, 0);
  }

  scale = 1;

  // update condition is:
  // min(camera displacement, camera rotation in radians)^2 > EPS
  // using small-angle approximation cos(x/2) = 1 - x^2 / 8

  if (zoomChanged ||
      lastPosition.distanceToSquared(scope.object.position) > eps ||
      8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > eps) {
    scope.dispatchEvent(_changeEvent);

    lastPosition.copy(scope.object.position);
    lastQuaternion.copy(scope.object.quaternion);
    zoomChanged = false;

    return true;
  }

  return false;
}