/// <summary> /// Perform a zoom with the given pinch /// </summary> protected void DoPinchZoom(PinchInfo pinch) { float currentDistance = (pinch.touch1.currentPosition - pinch.touch2.currentPosition).magnitude; float prevDistance = (pinch.touch1.previousPosition - pinch.touch2.previousPosition).magnitude; float zoomChange = prevDistance / currentDistance; float prevZoomDist = cameraRig.zoomDist; cameraRig.SetZoom(zoomChange * cameraRig.rawZoomDist); // Calculate actual zoom change after clamping zoomChange = cameraRig.zoomDist / prevZoomDist; // First get floor position of middle of gesture Vector2 averageScreenPos = (pinch.touch1.currentPosition + pinch.touch2.currentPosition) * 0.5f; Ray ray = cameraRig.cachedCamera.ScreenPointToRay(averageScreenPos); Vector3 worldPos = Vector3.zero; float dist; if (cameraRig.floorPlane.Raycast(ray, out dist)) { worldPos = ray.GetPoint(dist); } // Vector from our current look pos to this point Vector3 offsetValue = worldPos - cameraRig.lookPosition; // Pan towards or away from our zoom center PanCamera(offsetValue * (1 - zoomChange)); }
/// <summary> /// Perform a zoom with the given pinch /// </summary> protected void DoPinchZoom(PinchInfo pinch) { float currentDistance = (pinch.touch1.currentPosition - pinch.touch2.currentPosition).magnitude; float prevDistance = (pinch.touch1.previousPosition - pinch.touch2.previousPosition).magnitude; float zoomChange = prevDistance / currentDistance; }
/// <summary> /// Called on pinch gestures /// </summary> protected virtual void OnPinch(PinchInfo pinch) { if (cameraRig != null) { DoPinchZoom(pinch); } }
/// <summary> /// Called on pinch gestures /// </summary> protected virtual void OnPinch(PinchInfo pinch) { DoPinchZoom(pinch); }