2

someone who can help me?

I have an object with the follow properties:

FRect := TRectF( 50, 45, 150, 145 );
FRotationScale := 15;
FRotationCenter := TPointF( 0.5, 0.5 );
FScale := 1;
FScaleCenter := TPointF( 0.5, 0.5 );

with this function i get Matrix for drawing on canvas:

function GetMatrix: TMatrix;
var
  LRotationOffSet: TPointF;
  LScalingOffSet: TPointF;
begin
  LRotationOffSet := TPointF.Create( FRect.Left + FRect.Width * FRotationCenter.X, FRect.Top + FRect.Height * FRotationCenter.Y );
  LScalingOffSet := TPointF.Create( FRect.Left + FRect.Width * FScaleCenter.X, FRect.Top + FRect.Height * FScaleCenter.Y );
  Result :=
    TMatrix.Identity
    * TMatrix.CreateTranslation( FRect.Left, FRect.Top )
    * TMatrix.CreateTranslation( - LRotationOffSet.X, - LRotationOffSet.Y )
    * TMatrix.CreateRotation( DegToRad( FRotationAngle ) )
    * TMatrix.CreateTranslation( LRotationOffSet.X, LRotationOffSet.Y )
    * TMatrix.CreateTranslation( - LScalingOffSet.X, - LScalingOffSet.Y )
    * TMatrix.CreateScaling( FScale, FScale )
    * TMatrix.CreateTranslation( LScalingOffSet.X, LScalingOffSet.Y )
  ;
end;

And works fine:

enter image description here

As you can see with the follow function i can get Bounds Rect:

function BoundsPoints: TArray<TPointF>;
begin
  SetLength( Result, 8 );
    Result[ 0 ] := TPointF.Create( FRect.Left, FRect.Top ) * FMatrix;
    Result[ 1 ] := TPointF.Create( FRect.Left + FRect.Width / 2, FRect.Top ) * FMatrix;
    Result[ 2 ] := TPointF.Create( FRect.Left + FRect.Width, FRect.Top ) * FMatrix;
    Result[ 3 ] := TPointF.Create( FRect.Left + FRect.Width, FRect.Top + FRect.Height / 2 ) * FMatrix;
    Result[ 4 ] := TPointF.Create( FRect.Left + FRect.Width, FRect.Top + FRect.Height ) * FMatrix;
    Result[ 5 ] := TPointF.Create( FRect.Left + FRect.Width / 2, FRect.Top + FRect.Height ) * FMatrix;
    Result[ 6 ] := TPointF.Create( FRect.Left, FRect.Top + FRect.Height ) * FMatrix;
    Result[ 7 ] := TPointF.Create( FRect.Left, FRect.Top + FRect.Height /2 ) * FMatrix;
end;

Now the problem is when i drag some points of Bounds:

enter image description here

As you can see in the picture, I can resize the bounds rect smoothly. But when i release the mouse, should i calculate the FRect starting from Bounds Rect, how?

I try in this way but failed:

NormalizeRectF( [ 
  BoundsPoint[ 0 ] * FMatrix.Inverse, 
  BoundsPoint[ 2 ] * FMatrix.Inverse, 
  BoundsPoint[ 4 ] * FMatrix.Inverse, 
  BoundsPoint[ 6 ] * FMatrix.Inverse 
)

Please help!!!!

UPDATE

Ok, i try that:

From Matrix Reversed Dragged Bounds Rect i set the new FRect

  FRect.TopLeft :=

    FRect.TopLeft

    + ReversedBoundsRect.TopLeft

  ;

  FRect.BottomRight :=

    FRect.TopLeft

    + ReversedBoundsRect.BottomRight

    - ReversedBoundsRect.TopLeft

  ;

works almost if not for:

1) when FScaleCenter is 0,0 i can drag all corners expect Top and Left otherwise all point of FRect move wrong

2) when FScaleCenter is 0.5,0.5 when i drag all corners, all point of FRect move wrong

3) when FScaleCenter is 1,1 i can drag all corners expect Bottom and Right otherwise all point of FRect move wrong

Same for FRotationCenter!

UPDATE

Common guys!

I have Offset the FRect with follow formula, and work well but only for FRotationCenter = 0, 0!

FRect.OffSet(

        ( - ARect.Left * ( 1 - LCos ) - ARect.Top * LSin ),

        ( ARect.Left * LSin - ARect.Top * ( 1 - LCos ) )

      );

Possible that there is no one who has encountered these troubles, or a mathematical I do not know :( !

0 Answers0