Skip to content

Commit

Permalink
take into account rotation period for each grid type
Browse files Browse the repository at this point in the history
  • Loading branch information
OliBomby committed Sep 19, 2024
1 parent e3aeaf6 commit d2f97f5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ public void SetGridFromPoints(Vector2 point1, Vector2 point2)
StartPositionY.Value = point1.Y;

// Get the angle between the two points and normalize to the valid range.
const float period = 180;
GridLinesRotation.Value = (MathHelper.RadiansToDegrees(MathF.Atan2(point2.Y - point1.Y, point2.X - point1.X))
+ period * 1.5f) % period - period * 0.5f;
if (!GridLinesRotation.Disabled)
{
float period = GridLinesRotation.MaxValue - GridLinesRotation.MinValue;
GridLinesRotation.Value = normalizeRotation(MathHelper.RadiansToDegrees(MathF.Atan2(point2.Y - point1.Y, point2.X - point1.X)), period);
}

// Divide the distance so that there is a good density of grid lines.
float dist = Vector2.Distance(point1, point2);
Expand Down Expand Up @@ -231,20 +233,25 @@ protected override void LoadComplete()
switch (v.NewValue)
{
case PositionSnapGridType.Square:
GridLinesRotation.Value = ((GridLinesRotation.Value + 405) % 90) - 45;
GridLinesRotation.Value = normalizeRotation(GridLinesRotation.Value, 90);
GridLinesRotation.MinValue = -45;
GridLinesRotation.MaxValue = 45;
break;
case PositionSnapGridType.Triangle:
GridLinesRotation.Value = ((GridLinesRotation.Value + 390) % 60) - 30;
GridLinesRotation.Value = normalizeRotation(GridLinesRotation.Value, 60);
GridLinesRotation.MinValue = -30;
GridLinesRotation.MaxValue = 30;
break;
}
}, true);
}

private float normalizeRotation(float rotation, float period)
{
return ((rotation + 360 + period * 0.5f) % period) - period * 0.5f;
}

private void nextGridSize()
{
Spacing.Value = Spacing.Value * 2 >= max_automatic_spacing ? Spacing.Value / 8 : Spacing.Value * 2;
Expand Down

0 comments on commit d2f97f5

Please sign in to comment.