forum

There a way to calculate the point in time of a sliderpoint?

posted
Total Posts
5
Topic Starter
Awlex
Let's say that your only source of information is the .osu-file. So you know in which what timing point the slider in what positions the points have. Is it possible to map each of the points to a point in time?

(If possible without having to create the slider-curve)

Thanks in advance
Amryu
I'm going to answer you a bit more than that if you don't mind ;)

First off:
You gonna need the curve, timing points and some beatmap information to determine where they are.
So no, there is not an easy way out. You can skip right to the "PATH" part if you know the stuff already.


The .osu file saves only time, start position, slider type, slider anchors, repeats, and pixel length for sliders
(There are more but those aren't important for this).

Here an example:

x,y,time,type,hitsound,slider type|<point 1>|<point 2>|...|<point n>,repeat,pixelLength,...(hitsounding stuffs)
424,96,66,2,0,B|380:120|332:96|332:96|304:12,1,130,2|0,0:0|0:0,0:0:0:0:


X, Y

This is the start position of the slider.
The start position can be counted to the anchors which I will tak about later.

TIME

The time states when the slider starts moving.

TYPE

This is the type of the hitobject.

First subtract 16 as often as you can. The amount you subtracted it is the number
of new combo colors to skip (mappers can force combo colors and this is done by skipping them).
The number you should have left now should be 6 (2 = slider + 4 = new combo).

If there is no new combo the number should be just 2.

(For the note: 1 = circle, 2 = slider, 4 = new combo, 8 = spinner)

HITSOUND

The additions on the hitsound to use. Just add the numbers:

2 - Whistle
4 - Finish
8 - Clap

SLIDER TYPES

There are 4 slider types:

L - linear (basically just a slider with a start and end point)
P - passthrough (those are the 3-point circle sliders, those have always exactly 3 points)
B - bezier (this is a bezier curve with it's anchor points)
C - catmull (old sliders, similar to bezier but the curve goes always through the anchors)

The last type is very rare (only old maps have them).

PATH

First you need to seperate the list whenever the same point appears twice since that's
a new slider section (aka red anchor in the editor). If there are multiple sections it should
always be a bezier slider, though they can contain linear sections.

So to tackle your question:

It is possible to get the points calculating the curve and approximating where the slider ball
should be on a specific beat (so you need to know the current slider velocity). Finding out where
the slider ticks (your slider points) are is only easily possible with L and P sliders.

The slider ticks always appear on ticks like you can see them in the editor. How much of them appear,
or rather on what kind of ticks they appear, is set by a value in the beatmap (you can set it in the editor
in the timing section).

To calculate the points:

Slider velocity is 100 osupixels per beat (the beat length can be found in the last non-inherited timing point).

To get the current slider velocity you need to multiply the beatmap SV and the current SV
which is given by the last timingpoint (a non-inherited point sets the timing SV back to 1).

Now you need to calculate each curve section by calculating points on the bezier curve
(the points of all sections). The more points you calculate the more accurate it's gonna be.

Now you measure the distance between each point. If you want to be accurate here and
keep it simple use alot of points and calculate the direct point distance, which is inaccurate of
course since it is a curve. If you need performance you need to calculate the arc length between
two points (in that case you can use less).

Using the SV value you know at what point of time you are:

Time passed for distance = (distance/SV*100) * MsPerBeat - (MsPerBeat is the format osu saves the BPM as. It's basically MsPerBeat = 1/(BPM/60) * 1000)

If you passed a beat (or tick) you know there is a slidertick between this and the last point. Again either
use alot of points, or interpolate the distance to get accurate results.

REPEATS

How often the slider repeats... duh... (1 = no repeat, 2 = 1 repeat, etc...)

Though notice that the slider could end at it's start point this way and the duration of the slider increases.

PIXEL LENGTH

How long the slider is in pixels (NOT including repeats).

This values helps you to get the slider duration:

slider duration in beats = (pixelLength*repeats)/(SV*100)

Here is the code to calculate bezier curve points (in JS):

	coordsOnBezier: function(pointArray, t) {
var bx = 0, by = 0, n = pointArray.length - 1; // degree

if (n == 1) { // if linear
bx = (1 - t) * pointArray[0].x + t * pointArray[1].x;
by = (1 - t) * pointArray[0].y + t * pointArray[1].y;
} else if (n == 2) { // if quadratic
bx = (1 - t) * (1 - t) * pointArray[0].x + 2 * (1 - t) * t * pointArray[1].x + t * t * pointArray[2].x;
by = (1 - t) * (1 - t) * pointArray[0].y + 2 * (1 - t) * t * pointArray[1].y + t * t * pointArray[2].y;
} else if (n == 3) { // if cubic
bx = (1 - t) * (1 - t) * (1 - t) * pointArray[0].x + 3 * (1 - t) * (1 - t) * t * pointArray[1].x + 3 * (1 - t) * t * t * pointArray[2].x + t * t * t * pointArray[3].x;
by = (1 - t) * (1 - t) * (1 - t) * pointArray[0].y + 3 * (1 - t) * (1 - t) * t * pointArray[1].y + 3 * (1 - t) * t * t * pointArray[2].y + t * t * t * pointArray[3].y;
} else { // generalized equation
for(var i = 0; i <= n; i++) {
bx += this.binomialCoef(n, i) * Math.pow(1 - t, n - i) * Math.pow(t, i) * pointArray[i].x;
by += this.binomialCoef(n, i) * Math.pow(1 - t, n - i) * Math.pow(t, i) * pointArray[i].y;
}
}

return {x: bx, y: by}
}

binomialCoef: function(n, k) {
var r = 1;

if (k > n)
return 0;

for (var d = 1; d <= k; d++) {
r *= n--;
r /= d;
}

return r;
}

The point array should contain the anchor points for the bezier sliders (only the points of one section since you need
to calculate each section seperately). The t is a value ranging from 0 to 1. If you want 21 points you get your first point
using t = 0, second one t = 0.05, etc... (always increase by 0.05). For more points just add less per point.


Hope I could help you since I thought you might wanna know a bit more about sliders ;)

If you need something else don't hesitate to ask. I'm building my own osu in HTML5 and JS so I did some research already.

Amryu
Topic Starter
Awlex
Thanks for the prompt answer. This is pretty much everything I needed to know about sliders. Also, good luck for your project!
IllianDeCube09
What is the "SV" in calculating slider duration in beats?
Zelzatter Zero
SV is an acronym of Slider Velocity, determining the speed of the sliderball and the length on the timeline of the slider.

Also don't bump old threads.
Please sign in to reply.

New reply