Take circle radius into account when clamping to playfield

This commit is contained in:
Henry Lin 2021-06-29 13:36:30 +08:00
parent 0c5777c2c8
commit 2722565204
1 changed files with 23 additions and 13 deletions

View File

@ -74,6 +74,10 @@ public void ApplyToBeatmap(IBeatmap beatmap)
applyRandomisation(rateOfChangeMultiplier, previous, current);
// Move hit objects back into the playfield if they are outside of it,
// which would sometimes happen during big jumps otherwise.
current.PositionRandomised = clampToPlayfield(current.PositionRandomised, (float)hitObject.Radius);
hitObject.Position = current.PositionRandomised;
// update end position as it may have changed as a result of the position update.
@ -142,14 +146,7 @@ private void applyRandomisation(float rateOfChangeMultiplier, RandomObjectInfo p
current.AngleRad = (float)Math.Atan2(posRelativeToPrev.Y, posRelativeToPrev.X);
var position = previous.EndPositionRandomised + posRelativeToPrev;
// Move hit objects back into the playfield if they are outside of it,
// which would sometimes happen during big jumps otherwise.
position.X = MathHelper.Clamp(position.X, 0, OsuPlayfield.BASE_SIZE.X);
position.Y = MathHelper.Clamp(position.Y, 0, OsuPlayfield.BASE_SIZE.Y);
current.PositionRandomised = position;
current.PositionRandomised = previous.EndPositionRandomised + posRelativeToPrev;
}
/// <summary>
@ -185,14 +182,12 @@ private void applyDecreasingShift(IList<OsuHitObject> hitObjects, Vector2 shift)
{
for (int i = 0; i < hitObjects.Count; i++)
{
var hitObject = hitObjects[i];
// The first object is shifted by a vector slightly smaller than shift
// The last object is shifted by a vector slightly larger than zero
Vector2 position = hitObjects[i].Position + shift * ((hitObjects.Count - i) / (float)(hitObjects.Count + 1));
Vector2 position = hitObject.Position + shift * ((hitObjects.Count - i) / (float)(hitObjects.Count + 1));
position.X = MathHelper.Clamp(position.X, 0, OsuPlayfield.BASE_SIZE.X);
position.Y = MathHelper.Clamp(position.Y, 0, OsuPlayfield.BASE_SIZE.Y);
hitObjects[i].Position = position;
hitObject.Position = clampToPlayfield(position, (float)hitObject.Radius);
}
}
@ -217,6 +212,13 @@ private MarginPadding getMinSliderMargin(Slider slider)
minMargin.Left = Math.Min(minMargin.Left, OsuPlayfield.BASE_SIZE.X - minMargin.Right);
minMargin.Top = Math.Min(minMargin.Top, OsuPlayfield.BASE_SIZE.Y - minMargin.Bottom);
var radius = (float)slider.Radius;
minMargin.Left += radius;
minMargin.Right += radius;
minMargin.Top += radius;
minMargin.Bottom += radius;
return minMargin;
}
@ -236,6 +238,14 @@ private void shiftNestedObjects(Slider slider, Vector2 shift)
}
}
private Vector2 clampToPlayfield(Vector2 position, float radius)
{
position.X = MathHelper.Clamp(position.X, radius, OsuPlayfield.BASE_SIZE.X - radius);
position.Y = MathHelper.Clamp(position.Y, radius, OsuPlayfield.BASE_SIZE.Y - radius);
return position;
}
private class RandomObjectInfo
{
public float AngleRad { get; set; }