calculateTbRadius method

dynamic calculateTbRadius(
  1. Camera camera
)
  • Calculate the trackball radius so that gizmo's diamater will be 2/3 of the minimum side of the camera frustum
    • @param {Camera} camera
      • @returns {Number} The trackball radius

Implementation

calculateTbRadius(Camera camera) {
  var distance = camera.position.distanceTo(this._gizmos.position);

  if (camera is PerspectiveCamera) {
    var halfFovV =
        MathUtils.DEG2RAD * camera.fov * 0.5; //vertical fov/2 in radians
    var halfFovH = Math.atan(
        (camera.aspect) * Math.tan(halfFovV)); //horizontal fov/2 in radians
    return Math.tan(Math.min(halfFovV, halfFovH)) *
        distance *
        this.radiusFactor;
  } else if (camera is OrthographicCamera) {
    return Math.min(camera.top, camera.right) * this.radiusFactor;
  }
}