add rotation to snapped position

This commit is contained in:
OliBomby 2023-12-28 18:56:49 +01:00
parent f3b88c318b
commit f2edd705ea
2 changed files with 18 additions and 5 deletions

View File

@ -9,6 +9,7 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Layout;
using osu.Framework.Utils;
using osu.Game.Utils;
using osuTK;
namespace osu.Game.Screens.Edit.Compose.Components
@ -215,11 +216,11 @@ private void generateOutline(Vector2 drawSize)
public Vector2 GetSnappedPosition(Vector2 original)
{
Vector2 relativeToStart = original - StartPosition;
Vector2 relativeToStart = GeometryUtils.RotateVector(original - StartPosition, GridLineRotation);
Vector2 offset = Vector2.Divide(relativeToStart, Spacing);
Vector2 roundedOffset = new Vector2(MathF.Round(offset.X), MathF.Round(offset.Y));
return StartPosition + Vector2.Multiply(roundedOffset, Spacing);
return StartPosition + GeometryUtils.RotateVector(Vector2.Multiply(roundedOffset, Spacing), -GridLineRotation);
}
}
}

View File

@ -27,9 +27,8 @@ public static Vector2 RotatePointAroundOrigin(Vector2 point, Vector2 origin, flo
point.X -= origin.X;
point.Y -= origin.Y;
Vector2 ret;
ret.X = point.X * MathF.Cos(MathUtils.DegreesToRadians(angle)) + point.Y * MathF.Sin(MathUtils.DegreesToRadians(angle));
ret.Y = point.X * -MathF.Sin(MathUtils.DegreesToRadians(angle)) + point.Y * MathF.Cos(MathUtils.DegreesToRadians(angle));
Vector2 ret = RotateVector(point, angle);
Matrix2
ret.X += origin.X;
ret.Y += origin.Y;
@ -37,6 +36,19 @@ public static Vector2 RotatePointAroundOrigin(Vector2 point, Vector2 origin, flo
return ret;
}
/// <summary>
/// Rotate a vector around the origin.
/// </summary>
/// <param name="vector">The vector.</param>
/// <param name="angle">The angle to rotate (in degrees).</param>
public static Vector2 RotateVector(Vector2 vector, float angle)
{
return new Vector2(
vector.X * MathF.Cos(MathUtils.DegreesToRadians(angle)) + vector.Y * MathF.Sin(MathUtils.DegreesToRadians(angle)),
vector.X * -MathF.Sin(MathUtils.DegreesToRadians(angle)) + vector.Y * MathF.Cos(MathUtils.DegreesToRadians(angle))
);
}
/// <summary>
/// Given a flip direction, a surrounding quad for all selected objects, and a position,
/// will return the flipped position in screen space coordinates.