rotateCamera method

dynamic rotateCamera()

Implementation

rotateCamera() {
  moveDirection.set(_moveCurr.x - _movePrev.x, _moveCurr.y - _movePrev.y, 0);
  var angle = moveDirection.length();

  if (angle != 0) {
    _eye.copy(scope.object.position).sub(scope.target);

    eyeDirection.copy(_eye).normalize();
    objectUpDirection.copy(scope.object.up).normalize();
    objectSidewaysDirection
        .crossVectors(objectUpDirection, eyeDirection)
        .normalize();

    objectUpDirection.setLength(_moveCurr.y - _movePrev.y);
    objectSidewaysDirection.setLength(_moveCurr.x - _movePrev.x);

    moveDirection.copy(objectUpDirection.add(objectSidewaysDirection));

    axis.crossVectors(moveDirection, _eye).normalize();

    angle *= scope.rotateSpeed;
    quaternion.setFromAxisAngle(axis, angle);

    _eye.applyQuaternion(quaternion);
    scope.object.up.applyQuaternion(quaternion);

    _lastAxis.copy(axis);
    _lastAngle = angle;
  } else if (!scope.staticMoving && _lastAngle != 0) {
    _lastAngle *= Math.sqrt(1.0 - scope.dynamicDampingFactor);
    _eye.copy(scope.object.position).sub(scope.target);
    quaternion.setFromAxisAngle(_lastAxis, _lastAngle);
    _eye.applyQuaternion(quaternion);
    scope.object.up.applyQuaternion(quaternion);
  }

  _movePrev.copy(_moveCurr);
}