More curve types

Catmull curves
Line Curves(half assed)
Curve refactor
#73 near 0 length sliders
This commit is contained in:
fd 2015-04-12 10:25:03 -04:00
parent 13d383463f
commit 12e70002d6
11 changed files with 444 additions and 182 deletions

View File

@ -25,6 +25,7 @@ import itdelatrisu.opsu.GameMod;
import itdelatrisu.opsu.OsuFile;
import itdelatrisu.opsu.OsuHitObject;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.objects.curves.CatmullCurve;
import itdelatrisu.opsu.objects.curves.CircumscribedCircle;
import itdelatrisu.opsu.objects.curves.Curve;
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)
this.curve = new CircumscribedCircle(hitObject, color);
else if ( hitObject.getSliderType() == OsuHitObject.SLIDER_CATMULL)
this.curve = new CatmullCurve(hitObject, color);
else
this.curve = new LinearBezier(hitObject, color);
this.curve = new LinearBezier(hitObject, color, hitObject.getSliderType() == OsuHitObject.SLIDER_LINEAR);
}
@Override

View File

@ -23,22 +23,10 @@ package itdelatrisu.opsu.objects.curves;
*
* @author fluddokt (https://github.com/fluddokt)
*/
public class Bezier2 {
public class Bezier2 extends CurveType{
/** The control points of the Bezier curve. */
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.
* @param points the control points
@ -52,19 +40,7 @@ public class Bezier2 {
for (int i = 0; i < points.length - 1; i++)
approxlength += points[i].cpy().sub(points[i + 1]).len();
// subdivide the curve
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];
}
init(approxlength);
// System.out.println("New Bezier2 "+points.length+" "+approxlength+" "+totalDistance());
}
@ -84,25 +60,6 @@ public class Bezier2 {
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.

View File

@ -0,0 +1,53 @@
/*
* 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;
public class CatmullCurve extends EqualDistanceMultiCurve{
public CatmullCurve(OsuHitObject hitObject, Color color) {
super(hitObject, color);
LinkedList<CurveType> catmulls = new LinkedList<CurveType>();
int ncontrolPoints = hitObject.getSliderX().length + 1;
LinkedList<Vec2f> points = new LinkedList<Vec2f>(); // temporary list of points to separate different curves
//aaa .... needs at least two 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);
}
}

View File

@ -0,0 +1,101 @@
/*
* 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 CatmullRom spline.
* http://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
*
* Currently not technically Centripetal CatmullRom
*
* @author fluddokt (https://github.com/fluddokt)
*/
public class CentripetalCatmullRom extends CurveType{
float [] time;
Vec2f[] points;
protected CentripetalCatmullRom(Vec2f[] points) {
if (points.length != 4)
throw new Error("need exactly 4 points");
this.points = points;
System.out.println("C");
for(int i=0;i<4;i++){
System.out.println(points[i]);
}
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;
System.out.println("knot:"+i+" "+time[i]);
}
init(approxLength/2);
}
public Vec2f pointAt(float t, int start, int end){
int ind1 = start;
int ind2 = end;
if(end-start==3){
ind1 = 1;
ind2 = 2;
}
//System.out.println("ST:"+start+" "+end+" "+ind1+" "+ind2);
float div = (time[ind2] - time[ind1]);
float v1 = (time[ind2] - t)/div;
float v2 = (t - time[ind1])/div;
System.out.println("div"+div+" "+v1+" "+v2);
if(end-start==1)
return points[start].cpy().scale(v1).add(points[end].cpy().scale(v2));
else
return pointAt(t,start,end-1).scale(v1).add(pointAt(t,start+1,end).scale(v2));
}
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;
}
public String toString(){
String t = "CATMULLROM";
for(Vec2f p: points){
t+=p;
}
t+=pointAt(0);
t+=pointAt(1);
return t;
}
}

View File

@ -56,9 +56,6 @@ public class CircumscribedCircle extends Curve {
/** The number of steps in the curve to draw. */
private float step;
/** Points along the curve. */
private Vec2f[] curve;
/**
* Constructor.
* @param hitObject the associated OsuHitObject
@ -67,7 +64,6 @@ public class CircumscribedCircle extends Curve {
public CircumscribedCircle(OsuHitObject hitObject, Color color) {
super(hitObject, color);
this.step = hitObject.getPixelLength() / 5f;
// construct the three points
this.start = new Vec2f(getX(0), getY(0));
@ -125,6 +121,7 @@ public class CircumscribedCircle extends Curve {
this.drawStartAngle = (float) ((startAng + (startAng > endAng ? -HALF_PI : HALF_PI)) * 180 / Math.PI);
// calculate points
this.step = hitObject.getPixelLength() / CURVE_POINTS_SEPERATION;
curve = new Vec2f[(int) step + 1];
for (int i = 0; i < curve.length; i++) {
float[] xy = pointAt(i / step);
@ -178,15 +175,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
public float getEndAngle() { return drawEndAngle; }

View File

@ -18,9 +18,12 @@
package itdelatrisu.opsu.objects.curves;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.OsuHitObject;
import itdelatrisu.opsu.Utils;
import org.newdawn.slick.Color;
import org.newdawn.slick.Image;
/**
* Representation of a curve.
@ -28,6 +31,8 @@ import org.newdawn.slick.Color;
* @author fluddokt (https://github.com/fluddokt)
*/
public abstract class Curve {
protected static float CURVE_POINTS_SEPERATION = 50;
/** The associated OsuHitObject. */
protected OsuHitObject hitObject;
@ -37,6 +42,9 @@ public abstract class Curve {
/** The scaled slider x, y coordinate lists. */
protected float[] sliderX, sliderY;
/** Points along the curve. To be set be inherited classes*/
protected Vec2f[] curve;
/**
* Constructor.
* @param hitObject the associated OsuHitObject
@ -48,6 +56,7 @@ public abstract class Curve {
this.y = hitObject.getScaledY();
this.sliderX = hitObject.getScaledSliderX();
this.sliderY = hitObject.getScaledSliderY();
CURVE_POINTS_SEPERATION = 5;
}
/**
@ -61,7 +70,18 @@ public abstract class Curve {
* Draws the full curve to the graphics context.
* @param color the color filter
*/
public abstract void draw(Color color);
public void draw(Color color) {
if ( curve == null){
System.out.println("draw curve"+this);
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.

View File

@ -0,0 +1,79 @@
/*
* 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;
public abstract Vec2f pointAt(float t);
public void init(float approxlength){
// subdivide the curve
this.ncurve = (int) (approxlength / 4) + 1;
this.curve = new Vec2f[ncurve];
System.out.println(approxlength+" "+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];
System.out.println("curvedis:"+curveDis[i]);
}
}
/**
* 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 getCurvesCount() { return ncurve; }
/**
* Returns the total distances of this Bezier curve.
*/
public float totalDistance() { return totalDistance; }
}

View File

@ -0,0 +1,141 @@
/*
* 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 a Bezier 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);
}
public void init(LinkedList<CurveType> beziers){
for(CurveType ct : beziers){
System.out.println("CT:"+ct);
}
// 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 = beziers.iterator();
int curPoint = 0;
CurveType 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.getCurvesCount()) {
if (iter.hasNext()) {
curBezier = iter.next();
curPoint = 0;
} else {
curPoint = curBezier.getCurvesCount() - 1;
if (lastDistanceAt == distanceAt) {
// out of points even though the preferred distance hasn't been reached
break;
}
}
}
}
System.out.println("prefDis:"+prefDistance+" "+distanceAt+" "+lastDistanceAt);
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 float getEndAngle() { return endAngle; }
@Override
public float getStartAngle() { return startAngle; }
}

View File

@ -18,15 +18,10 @@
package itdelatrisu.opsu.objects.curves;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.OsuHitObject;
import itdelatrisu.opsu.Utils;
import java.util.Iterator;
import java.util.LinkedList;
import org.newdawn.slick.Color;
import org.newdawn.slick.Image;
/**
* Representation of a Bezier curve with equidistant points.
@ -34,34 +29,32 @@ import org.newdawn.slick.Image;
*
* @author fluddokt (https://github.com/fluddokt)
*/
public class LinearBezier extends Curve {
/** 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;
public class LinearBezier extends EqualDistanceMultiCurve {
/**
* Constructor.
* @param hitObject the associated OsuHitObject
* @param color the color of this curve
*/
public LinearBezier(OsuHitObject hitObject, Color color) {
public LinearBezier(OsuHitObject hitObject, Color color, boolean line) {
super(hitObject, color);
LinkedList<CurveType> beziers = new LinkedList<CurveType>();
// a b c - c d - d e f g
// ab bc cd de ef fg
// splits points into different Beziers if has the same points (red points)
int controlPoints = hitObject.getSliderX().length + 1;
LinkedList<Vec2f> points = new LinkedList<Vec2f>(); // temporary list of points to separate different Bezier curves
Vec2f lastPoi = null;
for (int i = 0; i < controlPoints; 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)
beziers.add(new Bezier2(points.toArray(new Vec2f[0])));
points.clear();
@ -69,7 +62,7 @@ public class LinearBezier extends Curve {
points.add(tpoi);
lastPoi = tpoi;
}
if (points.size() < 2) {
if (line || points.size() < 2) {
// trying to continue Bezier with less than 2 points
// probably ending on a red point, just ignore it
} else {
@ -77,105 +70,6 @@ public class LinearBezier extends Curve {
points.clear();
}
// find the length of all 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;
init(beziers);
}
}
}
}
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; }
}

View File

@ -49,6 +49,18 @@ public class Vec2f {
return new Vec2f((x + o.x) / 2, (y + o.y) / 2);
}
public Vec2f scale(float s) {
x *= s;
y *= s;
return this;
}
public Vec2f add(Vec2f o) {
x += o.x;
y += o.y;
return this;
}
/**
* Subtracts a vector from this vector.
* @param o the other vector
@ -97,4 +109,8 @@ public class Vec2f {
* @return true if the two vectors are numerically equal
*/
public boolean equals(Vec2f o) { return (x == o.x && y == o.y); }
public String toString(){
return "Vec2f:"+x+" "+y;
}
}

View File

@ -1043,6 +1043,16 @@ public class Game extends BasicGameState {
// reset game data
resetGameData();
// load the first timingPoint
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
for (int i = 0; i < osu.objects.length; i++) {
OsuHitObject hitObject = osu.objects[i];