Here is a method you can put in CameraBase or CameraPerspBase (only testing with perspective camera so far)
public void RotateAround(Vector2 viewportPoint, float angle)
{
Quaternion twistRot = Quaternion.AngleAxis(angle, GetRotateAroundVector());
Vector2 screenPoint = cam.ViewportToScreenPoint(viewportPoint);
Vector3 worldPointFingersCenter = ClampInCameraBoundaries(HeightScreenDepth.Convert(screenPoint));
Vector3 vecFingersCenterToCamera = (finalPosition - worldPointFingersCenter);
float vecFingersCenterToCameraDistance = vecFingersCenterToCamera.magnitude * 1f;
vecFingersCenterToCamera = vecFingersCenterToCamera.normalized * vecFingersCenterToCameraDistance;
Vector3 targetPosition = worldPointFingersCenter + vecFingersCenterToCamera;
Vector3 offsetFromFingerCenter = worldPointFingersCenter - worldPointFingersDelta;
finalPosition = twistRot * (targetPosition - worldPointFingersCenter) + offsetFromFingerCenter;
finalRotation = twistRot * finalRotation;
currentPitch = NormalizeAngle(finalRotation.eulerAngles.x);
currentYaw = (finalRotation.eulerAngles.y);
Vector3 newWorldPointCameraCenter = CalculateOffset(finalPosition, finalRotation);
Vector3 newWorldPointCameraCenterClamped = ClampInCameraBoundaries(newWorldPointCameraCenter);
finalOffset = newWorldPointCameraCenterClamped;
finalPosition = CalculatePosition(finalOffset, finalRotation, finalDistance);
ApplyToCamera();
}
Then you can call it from the CustomControlDemo.cs like so:
if (Input.GetKey(KeyCode.Space))
{
cam.RotateAround(new Vector2(0.5f, 0.75f), 30f * Time.deltaTime);
}
This will rotate the camera around the viewport point (0.5;0.75) as an example.