mirror of
https://github.com/ppy/osu.git
synced 2025-03-06 04:23:21 +08:00
Move distanceToPrev
inside randomisation function
This commit is contained in:
parent
6ca9b37c28
commit
ad3e4287cd
@ -66,15 +66,10 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
|
|
||||||
for (int i = 0; i < hitObjects.Count; i++)
|
for (int i = 0; i < hitObjects.Count; i++)
|
||||||
{
|
{
|
||||||
var distanceToPrev = 0f;
|
|
||||||
|
|
||||||
var hitObject = hitObjects[i];
|
var hitObject = hitObjects[i];
|
||||||
|
|
||||||
var currentObjectInfo = new RandomObjectInfo(hitObject);
|
var currentObjectInfo = new RandomObjectInfo(hitObject);
|
||||||
|
|
||||||
if (prevObjectInfo != null)
|
|
||||||
distanceToPrev = Vector2.Distance(prevObjectInfo.EndPositionOriginal, currentObjectInfo.PositionOriginal);
|
|
||||||
|
|
||||||
// rateOfChangeMultiplier only changes every i iterations to prevent shaky-line-shaped streams
|
// rateOfChangeMultiplier only changes every i iterations to prevent shaky-line-shaped streams
|
||||||
if (i % 3 == 0)
|
if (i % 3 == 0)
|
||||||
rateOfChangeMultiplier = (float)rng.NextDouble() * 2 - 1;
|
rateOfChangeMultiplier = (float)rng.NextDouble() * 2 - 1;
|
||||||
@ -85,11 +80,7 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
applyRandomisation(rateOfChangeMultiplier,
|
applyRandomisation(rateOfChangeMultiplier, prevObjectInfo, currentObjectInfo);
|
||||||
prevObjectInfo,
|
|
||||||
distanceToPrev,
|
|
||||||
currentObjectInfo
|
|
||||||
);
|
|
||||||
|
|
||||||
hitObject.Position = currentObjectInfo.PositionRandomised;
|
hitObject.Position = currentObjectInfo.PositionRandomised;
|
||||||
|
|
||||||
@ -113,44 +104,46 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
/// Returns the final position of the hit object
|
/// Returns the final position of the hit object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Final position of the hit object</returns>
|
/// <returns>Final position of the hit object</returns>
|
||||||
private void applyRandomisation(float rateOfChangeMultiplier, RandomObjectInfo prevObject, float distanceToPrev, RandomObjectInfo currentObjectInfo)
|
private void applyRandomisation(float rateOfChangeMultiplier, RandomObjectInfo previous, RandomObjectInfo current)
|
||||||
{
|
{
|
||||||
if (prevObject == null)
|
if (previous == null)
|
||||||
{
|
{
|
||||||
var playfieldSize = OsuPlayfield.BASE_SIZE;
|
var playfieldSize = OsuPlayfield.BASE_SIZE;
|
||||||
|
|
||||||
currentObjectInfo.AngleRad = (float)(rng.NextDouble() * 2 * Math.PI - Math.PI);
|
current.AngleRad = (float)(rng.NextDouble() * 2 * Math.PI - Math.PI);
|
||||||
currentObjectInfo.PositionRandomised = new Vector2((float)rng.NextDouble() * playfieldSize.X, (float)rng.NextDouble() * playfieldSize.Y);
|
current.PositionRandomised = new Vector2((float)rng.NextDouble() * playfieldSize.X, (float)rng.NextDouble() * playfieldSize.Y);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float distanceToPrev = Vector2.Distance(previous.EndPositionOriginal, current.PositionOriginal);
|
||||||
|
|
||||||
// The max. angle (relative to the angle of the vector pointing from the 2nd last to the last hit object)
|
// The max. angle (relative to the angle of the vector pointing from the 2nd last to the last hit object)
|
||||||
// is proportional to the distance between the last and the current hit object
|
// is proportional to the distance between the last and the current hit object
|
||||||
// to allow jumps and prevent too sharp turns during streams.
|
// to allow jumps and prevent too sharp turns during streams.
|
||||||
var randomAngleRad = rateOfChangeMultiplier * 2 * Math.PI * distanceToPrev / playfield_diagonal;
|
var randomAngleRad = rateOfChangeMultiplier * 2 * Math.PI * distanceToPrev / playfield_diagonal;
|
||||||
|
|
||||||
currentObjectInfo.AngleRad = (float)randomAngleRad + prevObject.AngleRad;
|
current.AngleRad = (float)randomAngleRad + previous.AngleRad;
|
||||||
if (currentObjectInfo.AngleRad < 0)
|
if (current.AngleRad < 0)
|
||||||
currentObjectInfo.AngleRad += 2 * (float)Math.PI;
|
current.AngleRad += 2 * (float)Math.PI;
|
||||||
|
|
||||||
var posRelativeToPrev = new Vector2(
|
var posRelativeToPrev = new Vector2(
|
||||||
distanceToPrev * (float)Math.Cos(currentObjectInfo.AngleRad),
|
distanceToPrev * (float)Math.Cos(current.AngleRad),
|
||||||
distanceToPrev * (float)Math.Sin(currentObjectInfo.AngleRad)
|
distanceToPrev * (float)Math.Sin(current.AngleRad)
|
||||||
);
|
);
|
||||||
|
|
||||||
posRelativeToPrev = getRotatedVector(prevObject.EndPositionRandomised, posRelativeToPrev);
|
posRelativeToPrev = getRotatedVector(previous.EndPositionRandomised, posRelativeToPrev);
|
||||||
|
|
||||||
currentObjectInfo.AngleRad = (float)Math.Atan2(posRelativeToPrev.Y, posRelativeToPrev.X);
|
current.AngleRad = (float)Math.Atan2(posRelativeToPrev.Y, posRelativeToPrev.X);
|
||||||
|
|
||||||
var position = Vector2.Add(prevObject.EndPositionRandomised, posRelativeToPrev);
|
var position = Vector2.Add(previous.EndPositionRandomised, posRelativeToPrev);
|
||||||
|
|
||||||
// Move hit objects back into the playfield if they are outside of it,
|
// Move hit objects back into the playfield if they are outside of it,
|
||||||
// which would sometimes happen during big jumps otherwise.
|
// which would sometimes happen during big jumps otherwise.
|
||||||
position.X = MathHelper.Clamp(position.X, 0, OsuPlayfield.BASE_SIZE.X);
|
position.X = MathHelper.Clamp(position.X, 0, OsuPlayfield.BASE_SIZE.X);
|
||||||
position.Y = MathHelper.Clamp(position.Y, 0, OsuPlayfield.BASE_SIZE.Y);
|
position.Y = MathHelper.Clamp(position.Y, 0, OsuPlayfield.BASE_SIZE.Y);
|
||||||
|
|
||||||
currentObjectInfo.PositionRandomised = position;
|
current.PositionRandomised = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user