public static void ApplyTransformationToWidgetsGroupObb(Widget sceneWidget, IList <Widget> widgetsInParentSpace, Vector2?overridePivotInSceneSpace, bool obbInFirstWidgetSpace, Vector2 currentMousePosInSceneSpace, Vector2 previousMousePosSceneSpace, bool convertScaleToSize, CalculateTransformationDelegate onCalculateTransformation) { if (widgetsInParentSpace.Count == 0) { return; } Matrix32d fromSceneToParentSpace = widgetsInParentSpace[0].ParentWidget .CalcEffectiveTransformToTopWidgetDouble(sceneWidget).CalcInversed(); ApplyTransformationToWidgetsGroupObb( widgetsInParentSpace, overridePivotInSceneSpace == null ? (Vector2d?)null : ((Vector2d)overridePivotInSceneSpace.Value * fromSceneToParentSpace), obbInFirstWidgetSpace, (Vector2d)currentMousePosInSceneSpace * fromSceneToParentSpace, (Vector2d)previousMousePosSceneSpace * fromSceneToParentSpace, convertScaleToSize, onCalculateTransformation); }
public static void ApplyTransformationToWidgetsGroupObb(IList <Widget> widgetsInParentSpace, Vector2d?overridePivotInParentSpace, bool obbInFirstWidgetSpace, Vector2d currentMousePosInParentSpace, Vector2d previousMousePosInParentSpace, bool convertScaleToSize, CalculateTransformationDelegate onCalculateTransformation) { if (widgetsInParentSpace.Count == 0) { return; } // Importent. Try to correct the pivot point to the closest pivot of one of widgets. if (overridePivotInParentSpace != null) { foreach (Widget widget in widgetsInParentSpace) { double length = ((Vector2d)widget.Position - overridePivotInParentSpace.Value).Length; if (length <= 1e-3) { overridePivotInParentSpace = (Vector2d)widget.Position; break; } } } Matrix32d originalObbToParentSpace; if (!obbInFirstWidgetSpace) { originalObbToParentSpace = Matrix32d.Translation(overridePivotInParentSpace ?? (Vector2d)widgetsInParentSpace[0].Position); } else { Widget widgetFirst = widgetsInParentSpace[0]; WidgetZeroScalePreserver zeroScalePreserver = new WidgetZeroScalePreserver(widgetFirst); zeroScalePreserver.Store(); // Nullify Pivot and Scale, to simplify transformation matrix from M = mT' * mR * mS * mT, to M = mR * mT, // to be able to use it with complex transformation by user (U = uT' uR * uS * uT), as // dM = U * M, instead of we must make dM = mT' * uR * mR * uS * mS * uT * mT, // and now if mT' = 1 and mS = 1 and uT = 1 it is reduced to dM = uT' * uS * uR * mR * mT = U * M. Matrix32d firstWidgetToParentSpace; Vector2 savedPivot = widgetFirst.Pivot; Vector2 savedScale = widgetFirst.Scale; widgetFirst.Pivot = Vector2.Zero; widgetFirst.Scale = Vector2.One; try { firstWidgetToParentSpace = widgetFirst.CalcLocalToParentTransformDouble(); if (overridePivotInParentSpace != null) { firstWidgetToParentSpace.T = overridePivotInParentSpace.Value; } } finally { widgetFirst.Pivot = savedPivot; widgetFirst.Scale = savedScale; zeroScalePreserver.Restore(); } originalObbToParentSpace = firstWidgetToParentSpace; } ApplyTransformationToWidgetsGroupObb( widgetsInParentSpace, originalObbToParentSpace, currentMousePosInParentSpace, previousMousePosInParentSpace, convertScaleToSize, onCalculateTransformation); }
public static void ApplyTransformationToWidgetsGroupObb(IEnumerable <Widget> widgetsInParentSpace, Matrix32d obbInParentSpace, Vector2d currentMousePosInParentSpace, Vector2d previousMousePosInParentSpace, bool convertScaleToSize, CalculateTransformationDelegate onCalculateTransformation) { if (Math.Abs(obbInParentSpace.CalcDeterminant()) < Mathf.ZeroTolerance) { return; } Matrix32d transformationFromParentToObb = obbInParentSpace.CalcInversed(); Vector2d controlPointInObbSpace = previousMousePosInParentSpace * transformationFromParentToObb; Vector2d targetPointInObbSpace = currentMousePosInParentSpace * transformationFromParentToObb; Vector2d originalVectorInObbSpace = controlPointInObbSpace; Vector2d deformedVectorInObbSpace = targetPointInObbSpace; Transform2d obbTransformation = onCalculateTransformation( originalVectorInObbSpace, deformedVectorInObbSpace ); ApplyTransformationToWidgetsGroupObb( widgetsInParentSpace, obbInParentSpace, obbTransformation, convertScaleToSize ); }