rotateWithPoint static method

dynamic rotateWithPoint(
  1. dynamic obj,
  2. dynamic anchorPoint, {
  3. dynamic angleX = 0.0,
  4. dynamic angleY = 0.0,
  5. dynamic angleZ = 0.0,
})

Implementation

static rotateWithPoint(obj, anchorPoint, {angleX = 0.0, angleY = 0.0, angleZ = 0.0}) {
  /// step 1: calculate move direction and move distance:
  var moveDir =
      Vector3(anchorPoint.x - obj.position.x, anchorPoint.y - obj.position.y, anchorPoint.z - obj.position.z);
  moveDir.normalize();
  var moveDist = obj.position.distanceTo(anchorPoint);

  /// step 2: move camera to anchor point
  obj.translateOnAxis(moveDir, moveDist);

  /// step 3: rotate camera
  // obj.rotateX(angleX);
  // obj.rotateY(angleY);
  // obj.rotateZ(angleZ);
  obj.rotation.z = angleZ;

  /// step4: move camera along the opposite direction
  moveDir.multiplyScalar(-1);
  obj.translateOnAxis(moveDir, moveDist);
}