private void UpdatePinch() { float pinchDistance = GetPinchDistance(TouchWrapper.Touches[0].Position, TouchWrapper.Touches[1].Position); if (OnPinchUpdate != null) { OnPinchUpdate.Invoke((TouchWrapper.Touches[0].Position + TouchWrapper.Touches[1].Position) * 0.5f, pinchDistance, pinchStartDistance); } }
private void UpdatePinch() { float pinchDistance = GetPinchDistance(TouchWrapper.Touches[0].Position, TouchWrapper.Touches[1].Position); Vector3 pinchVector = TouchWrapper.Touches[1].Position - TouchWrapper.Touches[0].Position; float pinchAngleSign = Vector3.Cross(pinchVectorLastFrame, pinchVector).z < 0 ? -1 : 1; float pinchAngleDelta = 0; if (Mathf.Approximately(Vector3.Distance(pinchVectorLastFrame, pinchVector), 0) == false) { pinchAngleDelta = Vector3.Angle(pinchVectorLastFrame, pinchVector) * pinchAngleSign; } float pinchVectorDeltaMag = Mathf.Abs(pinchVectorLastFrame.magnitude - pinchVector.magnitude); float pinchAngleDeltaNormalized = 0; if (Mathf.Approximately(pinchVectorDeltaMag, 0) == false) { pinchAngleDeltaNormalized = pinchAngleDelta / pinchVectorDeltaMag; } Vector3 pinchCenter = (TouchWrapper.Touches[0].Position + TouchWrapper.Touches[1].Position) * 0.5f; #region tilting gesture float pinchTiltDelta = 0; Vector3 touch0DeltaRelative = GetTouchPositionRelative(TouchWrapper.Touches[0].Position - touchPositionLastFrame[0]); Vector3 touch1DeltaRelative = GetTouchPositionRelative(TouchWrapper.Touches[1].Position - touchPositionLastFrame[1]); float touch0DotUp = Vector2.Dot(touch0DeltaRelative.normalized, Vector2.up); float touch1DotUp = Vector2.Dot(touch1DeltaRelative.normalized, Vector2.up); float pinchVectorDotHorizontal = Vector3.Dot(pinchVector.normalized, Vector3.right); if (Mathf.Sign(touch0DotUp) == Mathf.Sign(touch1DotUp)) { if (Mathf.Abs(touch0DotUp) > tiltMoveDotTreshold && Mathf.Abs(touch1DotUp) > tiltMoveDotTreshold) { if (Mathf.Abs(pinchVectorDotHorizontal) >= tiltHorizontalDotThreshold) { pinchTiltDelta = 0.5f * (touch0DeltaRelative.y + touch1DeltaRelative.y); } } } totalFingerMovement += touch0DeltaRelative.magnitude + touch1DeltaRelative.magnitude; #endregion if (OnPinchUpdate != null) { OnPinchUpdate.Invoke(pinchCenter, pinchDistance, pinchStartDistance); } if (OnPinchUpdateExtended != null) { OnPinchUpdateExtended(new PinchUpdateData() { pinchCenter = pinchCenter, pinchDistance = pinchDistance, pinchStartDistance = pinchStartDistance, pinchAngleDelta = pinchAngleDelta, pinchAngleDeltaNormalized = pinchAngleDeltaNormalized, pinchTiltDelta = pinchTiltDelta, pinchTotalFingerMovement = totalFingerMovement }); } pinchVectorLastFrame = pinchVector; touchPositionLastFrame[0] = TouchWrapper.Touches[0].Position; touchPositionLastFrame[1] = TouchWrapper.Touches[1].Position; }