mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 16:59:53 +09:00
Tidy up Slider class.
This commit is contained in:
44
osu.Game.Mode.Osu/Objects/SliderCurve.cs
Normal file
44
osu.Game.Mode.Osu/Objects/SliderCurve.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Modes.Osu.Objects
|
||||
{
|
||||
public class SliderCurve
|
||||
{
|
||||
public double Length;
|
||||
|
||||
public List<Vector2> Path;
|
||||
|
||||
public CurveTypes CurveType;
|
||||
|
||||
private List<Vector2> calculatedPath;
|
||||
|
||||
public void Calculate()
|
||||
{
|
||||
switch (CurveType)
|
||||
{
|
||||
case CurveTypes.Linear:
|
||||
calculatedPath = Path;
|
||||
break;
|
||||
default:
|
||||
var bezier = new BezierApproximator(Path);
|
||||
calculatedPath = bezier.CreateBezier();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 PositionAt(double progress)
|
||||
{
|
||||
progress = MathHelper.Clamp(progress, 0, 1);
|
||||
|
||||
double index = progress * (calculatedPath.Count - 1);
|
||||
int flooredIndex = (int)index;
|
||||
|
||||
Vector2 pos = calculatedPath[flooredIndex];
|
||||
if (index != flooredIndex)
|
||||
pos += (calculatedPath[flooredIndex + 1] - pos) * (float)(index - flooredIndex);
|
||||
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user