forked from itdelatrisu/opsu
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catmull curves Line Curves(half assed) Curve refactor #73 near 0 length sliders
- Loading branch information
fd
committed
Apr 12, 2015
1 parent
13d3834
commit 12e7000
Showing
11 changed files
with
444 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/itdelatrisu/opsu/objects/curves/CentripetalCatmullRom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 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{ | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.