2015-04-12 16:25:03 +02:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
|
|
|
* Copyright (C) 2014, 2015 Jeffrey Han
|
|
|
|
*
|
|
|
|
* opsu! is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu! is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package itdelatrisu.opsu.objects.curves;
|
|
|
|
|
2015-04-13 04:33:20 +02:00
|
|
|
import itdelatrisu.opsu.ErrorHandler;
|
2015-05-17 03:42:03 +02:00
|
|
|
import itdelatrisu.opsu.beatmap.HitObject;
|
2015-04-12 16:25:03 +02:00
|
|
|
|
2015-04-13 04:33:20 +02:00
|
|
|
import java.util.LinkedList;
|
|
|
|
|
2015-04-12 16:25:03 +02:00
|
|
|
import org.newdawn.slick.Color;
|
2015-04-13 04:33:20 +02:00
|
|
|
import org.newdawn.slick.SlickException;
|
2015-04-12 16:25:03 +02:00
|
|
|
|
2015-04-12 19:19:33 +02:00
|
|
|
/**
|
|
|
|
* Representation of Catmull Curve with equidistant points.
|
|
|
|
*
|
|
|
|
* @author fluddokt (https://github.com/fluddokt)
|
|
|
|
*/
|
2015-04-13 04:33:20 +02:00
|
|
|
public class CatmullCurve extends EqualDistanceMultiCurve {
|
2015-04-12 19:19:33 +02:00
|
|
|
/**
|
|
|
|
* Constructor.
|
2015-05-17 03:42:03 +02:00
|
|
|
* @param hitObject the associated HitObject
|
2015-04-12 19:19:33 +02:00
|
|
|
* @param color the color of this curve
|
|
|
|
*/
|
2015-05-17 03:42:03 +02:00
|
|
|
public CatmullCurve(HitObject hitObject, Color color) {
|
2015-04-12 16:25:03 +02:00
|
|
|
super(hitObject, color);
|
|
|
|
LinkedList<CurveType> catmulls = new LinkedList<CurveType>();
|
|
|
|
int ncontrolPoints = hitObject.getSliderX().length + 1;
|
2015-04-13 04:33:20 +02:00
|
|
|
LinkedList<Vec2f> points = new LinkedList<Vec2f>(); // temporary list of points to separate different curves
|
|
|
|
|
2015-04-12 19:19:33 +02:00
|
|
|
// repeat the first and last points as controls points
|
2015-04-14 04:56:07 +02:00
|
|
|
// only if the first/last two points are different
|
2015-04-12 19:19:33 +02:00
|
|
|
// aabb
|
|
|
|
// aabc abcc
|
|
|
|
// aabc abcd bcdd
|
2015-04-14 04:56:07 +02:00
|
|
|
if (getX(0) != getX(1) || getY(0) != getY(1))
|
|
|
|
points.addLast(new Vec2f(getX(0), getY(0)));
|
2015-04-12 19:19:33 +02:00
|
|
|
for (int i = 0; i < ncontrolPoints; i++) {
|
|
|
|
points.addLast(new Vec2f(getX(i), getY(i)));
|
|
|
|
if (points.size() >= 4) {
|
2015-04-13 04:33:20 +02:00
|
|
|
try {
|
|
|
|
catmulls.add(new CentripetalCatmullRom(points.toArray(new Vec2f[0])));
|
|
|
|
} catch (SlickException e) {
|
|
|
|
ErrorHandler.error(null, e, true);
|
|
|
|
}
|
2015-04-12 16:25:03 +02:00
|
|
|
points.removeFirst();
|
|
|
|
}
|
|
|
|
}
|
2015-09-01 05:54:35 +02:00
|
|
|
if (getX(ncontrolPoints - 1) != getX(ncontrolPoints - 2) ||
|
|
|
|
getY(ncontrolPoints - 1) != getY(ncontrolPoints - 2))
|
|
|
|
points.addLast(new Vec2f(getX(ncontrolPoints - 1), getY(ncontrolPoints - 1)));
|
2015-04-12 19:19:33 +02:00
|
|
|
if (points.size() >= 4) {
|
2015-04-13 04:33:20 +02:00
|
|
|
try {
|
|
|
|
catmulls.add(new CentripetalCatmullRom(points.toArray(new Vec2f[0])));
|
|
|
|
} catch (SlickException e) {
|
|
|
|
ErrorHandler.error(null, e, true);
|
|
|
|
}
|
2015-04-12 16:25:03 +02:00
|
|
|
}
|
2015-04-13 04:33:20 +02:00
|
|
|
|
2015-04-12 16:25:03 +02:00
|
|
|
init(catmulls);
|
|
|
|
}
|
|
|
|
}
|