Merge pull request #76 from fluddokt/omaster
Implemented Catmull curves and more curve types.
This commit is contained in:
commit
a69f960e26
|
@ -25,6 +25,7 @@ import itdelatrisu.opsu.GameMod;
|
||||||
import itdelatrisu.opsu.OsuFile;
|
import itdelatrisu.opsu.OsuFile;
|
||||||
import itdelatrisu.opsu.OsuHitObject;
|
import itdelatrisu.opsu.OsuHitObject;
|
||||||
import itdelatrisu.opsu.Utils;
|
import itdelatrisu.opsu.Utils;
|
||||||
|
import itdelatrisu.opsu.objects.curves.CatmullCurve;
|
||||||
import itdelatrisu.opsu.objects.curves.CircumscribedCircle;
|
import itdelatrisu.opsu.objects.curves.CircumscribedCircle;
|
||||||
import itdelatrisu.opsu.objects.curves.Curve;
|
import itdelatrisu.opsu.objects.curves.Curve;
|
||||||
import itdelatrisu.opsu.objects.curves.LinearBezier;
|
import itdelatrisu.opsu.objects.curves.LinearBezier;
|
||||||
|
@ -459,8 +460,10 @@ public class Slider implements HitObject {
|
||||||
|
|
||||||
if (hitObject.getSliderType() == OsuHitObject.SLIDER_PASSTHROUGH && hitObject.getSliderX().length == 2)
|
if (hitObject.getSliderType() == OsuHitObject.SLIDER_PASSTHROUGH && hitObject.getSliderX().length == 2)
|
||||||
this.curve = new CircumscribedCircle(hitObject, color);
|
this.curve = new CircumscribedCircle(hitObject, color);
|
||||||
|
else if ( hitObject.getSliderType() == OsuHitObject.SLIDER_CATMULL)
|
||||||
|
this.curve = new CatmullCurve(hitObject, color);
|
||||||
else
|
else
|
||||||
this.curve = new LinearBezier(hitObject, color);
|
this.curve = new LinearBezier(hitObject, color, hitObject.getSliderType() == OsuHitObject.SLIDER_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,22 +23,10 @@ package itdelatrisu.opsu.objects.curves;
|
||||||
*
|
*
|
||||||
* @author fluddokt (https://github.com/fluddokt)
|
* @author fluddokt (https://github.com/fluddokt)
|
||||||
*/
|
*/
|
||||||
public class Bezier2 {
|
public class Bezier2 extends CurveType{
|
||||||
/** The control points of the Bezier curve. */
|
/** The control points of the Bezier curve. */
|
||||||
private Vec2f[] points;
|
private Vec2f[] points;
|
||||||
|
|
||||||
/** Points along the curve of the Bezier curve. */
|
|
||||||
private Vec2f[] curve;
|
|
||||||
|
|
||||||
/** Distances between a point of the curve and the last point. */
|
|
||||||
private float[] curveDis;
|
|
||||||
|
|
||||||
/** The number of points along the curve. */
|
|
||||||
private int ncurve;
|
|
||||||
|
|
||||||
/** The total distances of this Bezier. */
|
|
||||||
private float totalDistance;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
* @param points the control points
|
* @param points the control points
|
||||||
|
@ -52,27 +40,10 @@ public class Bezier2 {
|
||||||
for (int i = 0; i < points.length - 1; i++)
|
for (int i = 0; i < points.length - 1; i++)
|
||||||
approxlength += points[i].cpy().sub(points[i + 1]).len();
|
approxlength += points[i].cpy().sub(points[i + 1]).len();
|
||||||
|
|
||||||
// subdivide the curve
|
init(approxlength);
|
||||||
this.ncurve = (int) (approxlength / 4);
|
|
||||||
this.curve = new Vec2f[ncurve];
|
|
||||||
for (int i = 0; i < ncurve; i++)
|
|
||||||
curve[i] = pointAt(i / (float) ncurve);
|
|
||||||
|
|
||||||
// find the distance of each point from the previous point
|
|
||||||
this.curveDis = new float[ncurve];
|
|
||||||
this.totalDistance = 0;
|
|
||||||
for (int i = 0; i < ncurve; i++) {
|
|
||||||
curveDis[i] = (i == 0) ? 0 : curve[i].cpy().sub(curve[i - 1]).len();
|
|
||||||
totalDistance += curveDis[i];
|
|
||||||
}
|
|
||||||
// System.out.println("New Bezier2 "+points.length+" "+approxlength+" "+totalDistance());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Returns the point on the Bezier curve at a value t.
|
|
||||||
* @param t the t value [0, 1]
|
|
||||||
* @return the point [x, y]
|
|
||||||
*/
|
|
||||||
public Vec2f pointAt(float t) {
|
public Vec2f pointAt(float t) {
|
||||||
Vec2f c = new Vec2f();
|
Vec2f c = new Vec2f();
|
||||||
int n = points.length - 1;
|
int n = points.length - 1;
|
||||||
|
@ -84,25 +55,6 @@ public class Bezier2 {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the points along the curve of the Bezier curve.
|
|
||||||
*/
|
|
||||||
public Vec2f[] getCurve() { return curve; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the distances between a point of the curve and the last point.
|
|
||||||
*/
|
|
||||||
public float[] getCurveDistances() { return curveDis; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of points along the curve.
|
|
||||||
*/
|
|
||||||
public int points() { return ncurve; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the total distances of this Bezier curve.
|
|
||||||
*/
|
|
||||||
public float totalDistance() { return totalDistance; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the binomial coefficient.
|
* Calculates the binomial coefficient.
|
||||||
|
|
64
src/itdelatrisu/opsu/objects/curves/CatmullCurve.java
Normal file
64
src/itdelatrisu/opsu/objects/curves/CatmullCurve.java
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import itdelatrisu.opsu.OsuHitObject;
|
||||||
|
|
||||||
|
import org.newdawn.slick.Color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Representation of Catmull Curve with equidistant points.
|
||||||
|
*
|
||||||
|
* @author fluddokt (https://github.com/fluddokt)
|
||||||
|
*/
|
||||||
|
public class CatmullCurve extends EqualDistanceMultiCurve{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* @param hitObject the associated OsuHitObject
|
||||||
|
* @param color the color of this curve
|
||||||
|
*/
|
||||||
|
public CatmullCurve(OsuHitObject hitObject, Color color) {
|
||||||
|
super(hitObject, color);
|
||||||
|
LinkedList<CurveType> catmulls = new LinkedList<CurveType>();
|
||||||
|
int ncontrolPoints = hitObject.getSliderX().length + 1;
|
||||||
|
// temporary list of points to separate different curves
|
||||||
|
LinkedList<Vec2f> points = new LinkedList<Vec2f>();
|
||||||
|
|
||||||
|
// repeat the first and last points as controls points
|
||||||
|
// aabb
|
||||||
|
// aabc abcc
|
||||||
|
// aabc abcd bcdd
|
||||||
|
points.addLast(new Vec2f(getX(0), getY(0)));
|
||||||
|
for (int i = 0; i < ncontrolPoints; i++) {
|
||||||
|
points.addLast(new Vec2f(getX(i), getY(i)));
|
||||||
|
if (points.size() >= 4) {
|
||||||
|
catmulls.add(new CentripetalCatmullRom(points.toArray(new Vec2f[0])));
|
||||||
|
points.removeFirst();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
points.addLast(new Vec2f(getX(ncontrolPoints - 1),getY(ncontrolPoints - 1)));
|
||||||
|
if (points.size() >= 4) {
|
||||||
|
catmulls.add(new CentripetalCatmullRom(points.toArray(new Vec2f[0])));
|
||||||
|
}
|
||||||
|
init(catmulls);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Representation of a Centripetal Catmull–Rom spline.
|
||||||
|
* http://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
|
||||||
|
*
|
||||||
|
* Currently not technically Centripetal Catmull–Rom
|
||||||
|
*
|
||||||
|
* @author fluddokt (https://github.com/fluddokt)
|
||||||
|
*/
|
||||||
|
public class CentripetalCatmullRom extends CurveType{
|
||||||
|
|
||||||
|
/** The time values of the Catmull curve. */
|
||||||
|
float [] time;
|
||||||
|
|
||||||
|
/** The control points of the Catmull curve. */
|
||||||
|
Vec2f[] points;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* @param hitObject the associated OsuHitObject
|
||||||
|
* @param color the color of this curve
|
||||||
|
*/
|
||||||
|
protected CentripetalCatmullRom(Vec2f[] points) {
|
||||||
|
if (points.length != 4)
|
||||||
|
throw new Error("need exactly 4 points");
|
||||||
|
|
||||||
|
this.points = points;
|
||||||
|
time = new float[4];
|
||||||
|
time[0] = 0;
|
||||||
|
float approxLength = 0;
|
||||||
|
for (int i = 1; i < 4; i++) {
|
||||||
|
float len = 0;
|
||||||
|
if (i > 0)
|
||||||
|
len = points[i].cpy().sub(points[i - 1]).len();
|
||||||
|
if (len <= 0)
|
||||||
|
len += 0.0001f;
|
||||||
|
approxLength += len;
|
||||||
|
// time[i] = (float) Math.sqrt(len) + time[i-1];// ^(0.5)
|
||||||
|
time[i] = i;
|
||||||
|
}
|
||||||
|
init(approxLength / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vec2f pointAt(float t){
|
||||||
|
t = t * (time[2] - time[1]) + time[1];
|
||||||
|
|
||||||
|
Vec2f A1 = points[0].cpy().scale((time[1] - t) / (time[1] - time[0]))
|
||||||
|
.add(points[1].cpy().scale((t - time[0]) / (time[1] - time[0])));
|
||||||
|
Vec2f A2 = points[1].cpy().scale((time[2] - t) / (time[2] - time[1]))
|
||||||
|
.add(points[2].cpy().scale((t - time[1]) / (time[2] - time[1])));
|
||||||
|
Vec2f A3 = points[2].cpy().scale((time[3] - t) / (time[3] - time[2]))
|
||||||
|
.add(points[3].cpy().scale((t - time[2]) / (time[3] - time[2])));
|
||||||
|
|
||||||
|
Vec2f B1 = A1.cpy().scale((time[2] - t) / (time[2] - time[0]))
|
||||||
|
.add(A2.cpy().scale((t - time[0]) / (time[2] - time[0])));
|
||||||
|
Vec2f B2 = A2.cpy().scale((time[3] - t) / (time[3] - time[1]))
|
||||||
|
.add(A3.cpy().scale((t - time[1]) / (time[3] - time[1])));
|
||||||
|
|
||||||
|
Vec2f C = B1.cpy().scale((time[2] - t) / (time[2] - time[1]))
|
||||||
|
.add(B2.cpy().scale((t - time[1]) / (time[2] - time[1])));
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,12 +19,9 @@
|
||||||
package itdelatrisu.opsu.objects.curves;
|
package itdelatrisu.opsu.objects.curves;
|
||||||
|
|
||||||
import itdelatrisu.opsu.ErrorHandler;
|
import itdelatrisu.opsu.ErrorHandler;
|
||||||
import itdelatrisu.opsu.GameImage;
|
|
||||||
import itdelatrisu.opsu.OsuHitObject;
|
import itdelatrisu.opsu.OsuHitObject;
|
||||||
import itdelatrisu.opsu.Utils;
|
|
||||||
|
|
||||||
import org.newdawn.slick.Color;
|
import org.newdawn.slick.Color;
|
||||||
import org.newdawn.slick.Image;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of a curve along a Circumscribed Circle of three points.
|
* Representation of a curve along a Circumscribed Circle of three points.
|
||||||
|
@ -53,12 +50,6 @@ public class CircumscribedCircle extends Curve {
|
||||||
/** The start and end angles for drawing. */
|
/** The start and end angles for drawing. */
|
||||||
private float drawStartAngle, drawEndAngle;
|
private float drawStartAngle, drawEndAngle;
|
||||||
|
|
||||||
/** The number of steps in the curve to draw. */
|
|
||||||
private float step;
|
|
||||||
|
|
||||||
/** Points along the curve. */
|
|
||||||
private Vec2f[] curve;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
* @param hitObject the associated OsuHitObject
|
* @param hitObject the associated OsuHitObject
|
||||||
|
@ -67,8 +58,6 @@ public class CircumscribedCircle extends Curve {
|
||||||
public CircumscribedCircle(OsuHitObject hitObject, Color color) {
|
public CircumscribedCircle(OsuHitObject hitObject, Color color) {
|
||||||
super(hitObject, color);
|
super(hitObject, color);
|
||||||
|
|
||||||
this.step = hitObject.getPixelLength() / 5f;
|
|
||||||
|
|
||||||
// construct the three points
|
// construct the three points
|
||||||
this.start = new Vec2f(getX(0), getY(0));
|
this.start = new Vec2f(getX(0), getY(0));
|
||||||
this.mid = new Vec2f(getX(1), getY(1));
|
this.mid = new Vec2f(getX(1), getY(1));
|
||||||
|
@ -125,6 +114,7 @@ public class CircumscribedCircle extends Curve {
|
||||||
this.drawStartAngle = (float) ((startAng + (startAng > endAng ? -HALF_PI : HALF_PI)) * 180 / Math.PI);
|
this.drawStartAngle = (float) ((startAng + (startAng > endAng ? -HALF_PI : HALF_PI)) * 180 / Math.PI);
|
||||||
|
|
||||||
// calculate points
|
// calculate points
|
||||||
|
float step = hitObject.getPixelLength() / CURVE_POINTS_SEPERATION;
|
||||||
curve = new Vec2f[(int) step + 1];
|
curve = new Vec2f[(int) step + 1];
|
||||||
for (int i = 0; i < curve.length; i++) {
|
for (int i = 0; i < curve.length; i++) {
|
||||||
float[] xy = pointAt(i / step);
|
float[] xy = pointAt(i / step);
|
||||||
|
@ -178,15 +168,6 @@ public class CircumscribedCircle extends Curve {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(Color color) {
|
|
||||||
Image hitCircle = GameImage.HITCIRCLE.getImage();
|
|
||||||
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
|
|
||||||
for (int i = 0; i < step; i++)
|
|
||||||
hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Utils.COLOR_WHITE_FADE);
|
|
||||||
for (int i = 0; i < step; i++)
|
|
||||||
hitCircle.drawCentered(curve[i].x, curve[i].y, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getEndAngle() { return drawEndAngle; }
|
public float getEndAngle() { return drawEndAngle; }
|
||||||
|
|
|
@ -18,9 +18,12 @@
|
||||||
|
|
||||||
package itdelatrisu.opsu.objects.curves;
|
package itdelatrisu.opsu.objects.curves;
|
||||||
|
|
||||||
|
import itdelatrisu.opsu.GameImage;
|
||||||
import itdelatrisu.opsu.OsuHitObject;
|
import itdelatrisu.opsu.OsuHitObject;
|
||||||
|
import itdelatrisu.opsu.Utils;
|
||||||
|
|
||||||
import org.newdawn.slick.Color;
|
import org.newdawn.slick.Color;
|
||||||
|
import org.newdawn.slick.Image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of a curve.
|
* Representation of a curve.
|
||||||
|
@ -28,6 +31,10 @@ import org.newdawn.slick.Color;
|
||||||
* @author fluddokt (https://github.com/fluddokt)
|
* @author fluddokt (https://github.com/fluddokt)
|
||||||
*/
|
*/
|
||||||
public abstract class Curve {
|
public abstract class Curve {
|
||||||
|
|
||||||
|
/** Points generated along the curve should be spaced this much apart*/
|
||||||
|
protected static float CURVE_POINTS_SEPERATION = 5;
|
||||||
|
|
||||||
/** The associated OsuHitObject. */
|
/** The associated OsuHitObject. */
|
||||||
protected OsuHitObject hitObject;
|
protected OsuHitObject hitObject;
|
||||||
|
|
||||||
|
@ -37,6 +44,9 @@ public abstract class Curve {
|
||||||
/** The scaled slider x, y coordinate lists. */
|
/** The scaled slider x, y coordinate lists. */
|
||||||
protected float[] sliderX, sliderY;
|
protected float[] sliderX, sliderY;
|
||||||
|
|
||||||
|
/** Points along the curve. To be set be inherited classes*/
|
||||||
|
protected Vec2f[] curve;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
* @param hitObject the associated OsuHitObject
|
* @param hitObject the associated OsuHitObject
|
||||||
|
@ -61,7 +71,17 @@ public abstract class Curve {
|
||||||
* Draws the full curve to the graphics context.
|
* Draws the full curve to the graphics context.
|
||||||
* @param color the color filter
|
* @param color the color filter
|
||||||
*/
|
*/
|
||||||
public abstract void draw(Color color);
|
public void draw(Color color) {
|
||||||
|
if (curve == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Image hitCircle = GameImage.HITCIRCLE.getImage();
|
||||||
|
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
|
||||||
|
for (int i = 0; i < curve.length; i++)
|
||||||
|
hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Utils.COLOR_WHITE_FADE);
|
||||||
|
for (int i = 0; i < curve.length; i++)
|
||||||
|
hitCircle.drawCentered(curve[i].x, curve[i].y, color);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the angle of the first control point.
|
* Returns the angle of the first control point.
|
||||||
|
|
88
src/itdelatrisu/opsu/objects/curves/CurveType.java
Normal file
88
src/itdelatrisu/opsu/objects/curves/CurveType.java
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Representation of a curve with the distance between each point calculated.
|
||||||
|
*
|
||||||
|
* @author fluddokt (https://github.com/fluddokt)
|
||||||
|
*/
|
||||||
|
public abstract class CurveType {
|
||||||
|
|
||||||
|
/** Points along the curve of the Bezier curve. */
|
||||||
|
private Vec2f[] curve;
|
||||||
|
|
||||||
|
/** Distances between a point of the curve and the last point. */
|
||||||
|
private float[] curveDis;
|
||||||
|
|
||||||
|
/** The number of points along the curve. */
|
||||||
|
private int ncurve;
|
||||||
|
|
||||||
|
/** The total distances of this Bezier. */
|
||||||
|
private float totalDistance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the point on the curve at a value t.
|
||||||
|
* @param t the t value [0, 1]
|
||||||
|
* @return the point [x, y]
|
||||||
|
*/
|
||||||
|
public abstract Vec2f pointAt(float t);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the curve points and distance
|
||||||
|
* Must be called by inherited classes
|
||||||
|
*
|
||||||
|
* @param approxlength an approximate length of the curve
|
||||||
|
*/
|
||||||
|
public void init(float approxlength) {
|
||||||
|
// subdivide the curve
|
||||||
|
this.ncurve = (int) (approxlength / 4) + 1;
|
||||||
|
this.curve = new Vec2f[ncurve];
|
||||||
|
for (int i = 0; i < ncurve; i++)
|
||||||
|
curve[i] = pointAt(i / (float) (ncurve - 1));
|
||||||
|
|
||||||
|
// find the distance of each point from the previous point
|
||||||
|
this.curveDis = new float[ncurve];
|
||||||
|
this.totalDistance = 0;
|
||||||
|
for (int i = 0; i < ncurve; i++) {
|
||||||
|
curveDis[i] = (i == 0) ? 0 : curve[i].cpy().sub(curve[i - 1]).len();
|
||||||
|
totalDistance += curveDis[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Returns the points along the curve of the Bezier curve.
|
||||||
|
*/
|
||||||
|
public Vec2f[] getCurvePoint() { return curve; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the distances between a point of the curve and the last point.
|
||||||
|
*/
|
||||||
|
public float[] getCurveDistances() { return curveDis; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of points along the curve.
|
||||||
|
*/
|
||||||
|
public int getCurvesCount() { return ncurve; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the total distances of this Bezier curve.
|
||||||
|
*/
|
||||||
|
public float totalDistance() { return totalDistance; }
|
||||||
|
|
||||||
|
}
|
143
src/itdelatrisu/opsu/objects/curves/EqualDistanceMultiCurve.java
Normal file
143
src/itdelatrisu/opsu/objects/curves/EqualDistanceMultiCurve.java
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import itdelatrisu.opsu.OsuHitObject;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import org.newdawn.slick.Color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Representation of multiple curve with equidistant points.
|
||||||
|
* http://pomax.github.io/bezierinfo/#tracing
|
||||||
|
*
|
||||||
|
* @author fluddokt (https://github.com/fluddokt)
|
||||||
|
*/
|
||||||
|
public abstract class EqualDistanceMultiCurve extends Curve {
|
||||||
|
/** The angles of the first and last control points for drawing. */
|
||||||
|
private float startAngle, endAngle;
|
||||||
|
|
||||||
|
/** The number of points along the curve. */
|
||||||
|
private int ncurve;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* @param hitObject the associated OsuHitObject
|
||||||
|
* @param color the color of this curve
|
||||||
|
*/
|
||||||
|
public EqualDistanceMultiCurve(OsuHitObject hitObject, Color color) {
|
||||||
|
super(hitObject, color);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the curve points with equal distance
|
||||||
|
* Must be called by inherited classes
|
||||||
|
*
|
||||||
|
* @param curvesList a list of curves to join
|
||||||
|
*/
|
||||||
|
public void init(LinkedList<CurveType> curvesList){
|
||||||
|
// now try to creates points the are equidistant to each other
|
||||||
|
this.ncurve = (int) (hitObject.getPixelLength() / CURVE_POINTS_SEPERATION);
|
||||||
|
this.curve = new Vec2f[ncurve + 1];
|
||||||
|
|
||||||
|
float distanceAt = 0;
|
||||||
|
Iterator<CurveType> iter = curvesList.iterator();
|
||||||
|
int curPoint = 0;
|
||||||
|
CurveType curCurve = iter.next();
|
||||||
|
Vec2f lastCurve = curCurve.getCurvePoint()[0];
|
||||||
|
float lastDistanceAt = 0;
|
||||||
|
|
||||||
|
// length of Curve should equal pixel length (in 640x480)
|
||||||
|
float pixelLength = hitObject.getPixelLength() * OsuHitObject.getXMultiplier();
|
||||||
|
|
||||||
|
// for each distance, try to get in between the two points that are between it
|
||||||
|
for (int i = 0; i < ncurve + 1; i++) {
|
||||||
|
int prefDistance = (int) (i * pixelLength / ncurve);
|
||||||
|
while (distanceAt < prefDistance) {
|
||||||
|
lastDistanceAt = distanceAt;
|
||||||
|
lastCurve = curCurve.getCurvePoint()[curPoint];
|
||||||
|
distanceAt += curCurve.getCurveDistances()[curPoint++];
|
||||||
|
|
||||||
|
if (curPoint >= curCurve.getCurvesCount()) {
|
||||||
|
if (iter.hasNext()) {
|
||||||
|
curCurve = iter.next();
|
||||||
|
curPoint = 0;
|
||||||
|
} else {
|
||||||
|
curPoint = curCurve.getCurvesCount() - 1;
|
||||||
|
if (lastDistanceAt == distanceAt) {
|
||||||
|
// out of points even though the preferred distance hasn't been reached
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Vec2f thisCurve = curCurve.getCurvePoint()[curPoint];
|
||||||
|
|
||||||
|
// interpolate the point between the two closest distances
|
||||||
|
if (distanceAt - lastDistanceAt > 1) {
|
||||||
|
float t = (prefDistance - lastDistanceAt) / (distanceAt - lastDistanceAt);
|
||||||
|
curve[i] = new Vec2f(lerp(lastCurve.x, thisCurve.x, t), lerp(lastCurve.y, thisCurve.y, t));
|
||||||
|
} else
|
||||||
|
curve[i] = thisCurve;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (hitObject.getRepeatCount() > 1) {
|
||||||
|
Vec2f c1 = curve[0];
|
||||||
|
int cnt = 1;
|
||||||
|
Vec2f c2 = curve[cnt++];
|
||||||
|
while (cnt <= ncurve && c2.cpy().sub(c1).len() < 1)
|
||||||
|
c2 = curve[cnt++];
|
||||||
|
this.startAngle = (float) (Math.atan2(c2.y - c1.y, c2.x - c1.x) * 180 / Math.PI);
|
||||||
|
|
||||||
|
c1 = curve[ncurve];
|
||||||
|
cnt = ncurve - 1;
|
||||||
|
c2 = curve[cnt--];
|
||||||
|
while (cnt >= 0 && c2.cpy().sub(c1).len() < 1)
|
||||||
|
c2 = curve[cnt--];
|
||||||
|
this.endAngle = (float) (Math.atan2(c2.y - c1.y, c2.x - c1.x) * 180 / Math.PI);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float[] pointAt(float t) {
|
||||||
|
float indexF = t * ncurve;
|
||||||
|
int index = (int) indexF;
|
||||||
|
if (index >= ncurve) {
|
||||||
|
Vec2f poi = curve[ncurve];
|
||||||
|
return new float[] { poi.x, poi.y };
|
||||||
|
} else {
|
||||||
|
Vec2f poi = curve[index];
|
||||||
|
Vec2f poi2 = curve[index + 1];
|
||||||
|
float t2 = indexF - index;
|
||||||
|
return new float[] {
|
||||||
|
lerp(poi.x, poi2.x, t2),
|
||||||
|
lerp(poi.y, poi2.y, t2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getEndAngle() { return endAngle; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getStartAngle() { return startAngle; }
|
||||||
|
}
|
|
@ -18,50 +18,46 @@
|
||||||
|
|
||||||
package itdelatrisu.opsu.objects.curves;
|
package itdelatrisu.opsu.objects.curves;
|
||||||
|
|
||||||
import itdelatrisu.opsu.GameImage;
|
|
||||||
import itdelatrisu.opsu.OsuHitObject;
|
import itdelatrisu.opsu.OsuHitObject;
|
||||||
import itdelatrisu.opsu.Utils;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import org.newdawn.slick.Color;
|
import org.newdawn.slick.Color;
|
||||||
import org.newdawn.slick.Image;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of a Bezier curve with equidistant points.
|
* Representation of Bezier curve with equidistant points.
|
||||||
* http://pomax.github.io/bezierinfo/#tracing
|
* http://pomax.github.io/bezierinfo/#tracing
|
||||||
*
|
*
|
||||||
* @author fluddokt (https://github.com/fluddokt)
|
* @author fluddokt (https://github.com/fluddokt)
|
||||||
*/
|
*/
|
||||||
public class LinearBezier extends Curve {
|
public class LinearBezier extends EqualDistanceMultiCurve {
|
||||||
/** The angles of the first and last control points for drawing. */
|
|
||||||
private float startAngle, endAngle;
|
|
||||||
|
|
||||||
/** List of Bezier curves in the set of points. */
|
|
||||||
private LinkedList<Bezier2> beziers = new LinkedList<Bezier2>();
|
|
||||||
|
|
||||||
/** Points along the curve at equal distance. */
|
|
||||||
private Vec2f[] curve;
|
|
||||||
|
|
||||||
/** The number of points along the curve. */
|
|
||||||
private int ncurve;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
* @param hitObject the associated OsuHitObject
|
* @param hitObject the associated OsuHitObject
|
||||||
* @param color the color of this curve
|
* @param color the color of this curve
|
||||||
*/
|
*/
|
||||||
public LinearBezier(OsuHitObject hitObject, Color color) {
|
public LinearBezier(OsuHitObject hitObject, Color color, boolean line) {
|
||||||
super(hitObject, color);
|
super(hitObject, color);
|
||||||
|
|
||||||
// splits points into different Beziers if has the same points (red points)
|
LinkedList<CurveType> beziers = new LinkedList<CurveType>();
|
||||||
|
|
||||||
|
// Beziers: splits points into different Beziers if has the same points (red points)
|
||||||
|
// a b c - c d - d e f g
|
||||||
|
// Lines: generate a new curve for each sequential pair
|
||||||
|
// ab bc cd de ef fg
|
||||||
|
|
||||||
int controlPoints = hitObject.getSliderX().length + 1;
|
int controlPoints = hitObject.getSliderX().length + 1;
|
||||||
LinkedList<Vec2f> points = new LinkedList<Vec2f>(); // temporary list of points to separate different Bezier curves
|
LinkedList<Vec2f> points = new LinkedList<Vec2f>(); // temporary list of points to separate different Bezier curves
|
||||||
Vec2f lastPoi = null;
|
Vec2f lastPoi = null;
|
||||||
for (int i = 0; i < controlPoints; i++) {
|
for (int i = 0; i < controlPoints; i++) {
|
||||||
Vec2f tpoi = new Vec2f(getX(i), getY(i));
|
Vec2f tpoi = new Vec2f(getX(i), getY(i));
|
||||||
if (lastPoi != null && tpoi.equals(lastPoi)) {
|
if (line) {
|
||||||
|
if(lastPoi != null) {
|
||||||
|
points.add(tpoi);
|
||||||
|
beziers.add(new Bezier2(points.toArray(new Vec2f[0])));
|
||||||
|
points.clear();
|
||||||
|
}
|
||||||
|
} else if (lastPoi != null && tpoi.equals(lastPoi)) {
|
||||||
if (points.size() >= 2)
|
if (points.size() >= 2)
|
||||||
beziers.add(new Bezier2(points.toArray(new Vec2f[0])));
|
beziers.add(new Bezier2(points.toArray(new Vec2f[0])));
|
||||||
points.clear();
|
points.clear();
|
||||||
|
@ -69,113 +65,14 @@ public class LinearBezier extends Curve {
|
||||||
points.add(tpoi);
|
points.add(tpoi);
|
||||||
lastPoi = tpoi;
|
lastPoi = tpoi;
|
||||||
}
|
}
|
||||||
if (points.size() < 2) {
|
if (line || points.size() < 2) {
|
||||||
// trying to continue Bezier with less than 2 points
|
// trying to continue Bezier with less than 2 points
|
||||||
// probably ending on a red point, just ignore it
|
// probably ending on a red point, just ignore it
|
||||||
} else {
|
} else {
|
||||||
beziers.add(new Bezier2(points.toArray(new Vec2f[0])));
|
beziers.add(new Bezier2(points.toArray(new Vec2f[0])));
|
||||||
points.clear();
|
points.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the length of all beziers
|
init(beziers);
|
||||||
// int totalDistance = 0;
|
|
||||||
// for (Bezier2 bez : beziers) {
|
|
||||||
// totalDistance += bez.totalDistance();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// now try to creates points the are equidistant to each other
|
|
||||||
this.ncurve = (int) (hitObject.getPixelLength() / 5f);
|
|
||||||
this.curve = new Vec2f[ncurve + 1];
|
|
||||||
|
|
||||||
float distanceAt = 0;
|
|
||||||
Iterator<Bezier2> iter = beziers.iterator();
|
|
||||||
int curPoint = 0;
|
|
||||||
Bezier2 curBezier = iter.next();
|
|
||||||
Vec2f lastCurve = curBezier.getCurve()[0];
|
|
||||||
float lastDistanceAt = 0;
|
|
||||||
|
|
||||||
// length of Bezier should equal pixel length (in 640x480)
|
|
||||||
float pixelLength = hitObject.getPixelLength() * OsuHitObject.getXMultiplier();
|
|
||||||
|
|
||||||
// for each distance, try to get in between the two points that are between it
|
|
||||||
for (int i = 0; i < ncurve + 1; i++) {
|
|
||||||
int prefDistance = (int) (i * pixelLength / ncurve);
|
|
||||||
while (distanceAt < prefDistance) {
|
|
||||||
lastDistanceAt = distanceAt;
|
|
||||||
lastCurve = curBezier.getCurve()[curPoint];
|
|
||||||
distanceAt += curBezier.getCurveDistances()[curPoint++];
|
|
||||||
|
|
||||||
if (curPoint >= curBezier.points()) {
|
|
||||||
if (iter.hasNext()) {
|
|
||||||
curBezier = iter.next();
|
|
||||||
curPoint = 0;
|
|
||||||
} else {
|
|
||||||
curPoint = curBezier.points() - 1;
|
|
||||||
if (lastDistanceAt == distanceAt) {
|
|
||||||
// out of points even though the preferred distance hasn't been reached
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Vec2f thisCurve = curBezier.getCurve()[curPoint];
|
|
||||||
|
|
||||||
// interpolate the point between the two closest distances
|
|
||||||
if (distanceAt - lastDistanceAt > 1) {
|
|
||||||
float t = (prefDistance - lastDistanceAt) / (distanceAt - lastDistanceAt);
|
|
||||||
curve[i] = new Vec2f(lerp(lastCurve.x, thisCurve.x, t), lerp(lastCurve.y, thisCurve.y, t));
|
|
||||||
} else
|
|
||||||
curve[i] = thisCurve;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (hitObject.getRepeatCount() > 1) {
|
|
||||||
Vec2f c1 = curve[0];
|
|
||||||
int cnt = 1;
|
|
||||||
Vec2f c2 = curve[cnt++];
|
|
||||||
while (cnt <= ncurve && c2.cpy().sub(c1).len() < 1)
|
|
||||||
c2 = curve[cnt++];
|
|
||||||
this.startAngle = (float) (Math.atan2(c2.y - c1.y, c2.x - c1.x) * 180 / Math.PI);
|
|
||||||
|
|
||||||
c1 = curve[ncurve];
|
|
||||||
cnt = ncurve - 1;
|
|
||||||
c2 = curve[cnt--];
|
|
||||||
while (cnt >= 0 && c2.cpy().sub(c1).len() < 1)
|
|
||||||
c2 = curve[cnt--];
|
|
||||||
this.endAngle = (float) (Math.atan2(c2.y - c1.y, c2.x - c1.x) * 180 / Math.PI);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public float[] pointAt(float t) {
|
|
||||||
float indexF = t * ncurve;
|
|
||||||
int index = (int) indexF;
|
|
||||||
if (index >= ncurve) {
|
|
||||||
Vec2f poi = curve[ncurve];
|
|
||||||
return new float[] { poi.x, poi.y };
|
|
||||||
} else {
|
|
||||||
Vec2f poi = curve[index];
|
|
||||||
Vec2f poi2 = curve[index + 1];
|
|
||||||
float t2 = indexF - index;
|
|
||||||
return new float[] {
|
|
||||||
lerp(poi.x, poi2.x, t2),
|
|
||||||
lerp(poi.y, poi2.y, t2)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(Color color) {
|
|
||||||
Image hitCircle = GameImage.HITCIRCLE.getImage();
|
|
||||||
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
|
|
||||||
for (int i = curve.length - 2; i >= 0; i--)
|
|
||||||
hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Utils.COLOR_WHITE_FADE);
|
|
||||||
for (int i = curve.length - 2; i >= 0; i--)
|
|
||||||
hitCircle.drawCentered(curve[i].x, curve[i].y, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getEndAngle() { return endAngle; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getStartAngle() { return startAngle; }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,28 @@ public class Vec2f {
|
||||||
return new Vec2f((x + o.x) / 2, (y + o.y) / 2);
|
return new Vec2f((x + o.x) / 2, (y + o.y) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scales the vector.
|
||||||
|
* @param s scaler to scale by
|
||||||
|
* @return itself (for chaining)
|
||||||
|
*/
|
||||||
|
public Vec2f scale(float s) {
|
||||||
|
x *= s;
|
||||||
|
y *= s;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a vector to this vector.
|
||||||
|
* @param o the other vector
|
||||||
|
* @return itself (for chaining)
|
||||||
|
*/
|
||||||
|
public Vec2f add(Vec2f o) {
|
||||||
|
x += o.x;
|
||||||
|
y += o.y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subtracts a vector from this vector.
|
* Subtracts a vector from this vector.
|
||||||
* @param o the other vector
|
* @param o the other vector
|
||||||
|
@ -97,4 +119,8 @@ public class Vec2f {
|
||||||
* @return true if the two vectors are numerically equal
|
* @return true if the two vectors are numerically equal
|
||||||
*/
|
*/
|
||||||
public boolean equals(Vec2f o) { return (x == o.x && y == o.y); }
|
public boolean equals(Vec2f o) { return (x == o.x && y == o.y); }
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return "Vec2f:"+x+" "+y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1043,6 +1043,16 @@ public class Game extends BasicGameState {
|
||||||
// reset game data
|
// reset game data
|
||||||
resetGameData();
|
resetGameData();
|
||||||
|
|
||||||
|
// load the first timingPoint for stacking
|
||||||
|
timingPointIndex = 0;
|
||||||
|
beatLengthBase = beatLength = 1;
|
||||||
|
if (!osu.timingPoints.isEmpty()) {
|
||||||
|
OsuTimingPoint timingPoint = osu.timingPoints.get(0);
|
||||||
|
if (!timingPoint.isInherited()) {
|
||||||
|
setBeatLength(timingPoint, true);
|
||||||
|
timingPointIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
// initialize object maps
|
// initialize object maps
|
||||||
for (int i = 0; i < osu.objects.length; i++) {
|
for (int i = 0; i < osu.objects.length; i++) {
|
||||||
OsuHitObject hitObject = osu.objects[i];
|
OsuHitObject hitObject = osu.objects[i];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user