Merge pull request #39 from fluddokt/omaster
Fixes some sliders with too much control points. / Attempts to load music with incorrect file names. #33
This commit is contained in:
commit
cfd335de88
|
@ -77,8 +77,9 @@ public class Bezier2 {
|
||||||
Vec2f c = new Vec2f();
|
Vec2f c = new Vec2f();
|
||||||
int n = points.length - 1;
|
int n = points.length - 1;
|
||||||
for (int i = 0; i <= n; i++) {
|
for (int i = 0; i <= n; i++) {
|
||||||
c.x += points[i].x * bernstein(i, n, t);
|
double b = bernstein(i, n, t);
|
||||||
c.y += points[i].y * bernstein(i, n, t);
|
c.x += points[i].x * b;
|
||||||
|
c.y += points[i].y * b;
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -104,12 +105,21 @@ public class Bezier2 {
|
||||||
public float totalDistance() { return totalDistance; }
|
public float totalDistance() { return totalDistance; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the factorial of a number.
|
* http://en.wikipedia.org/wiki/Binomial_coefficient#Binomial_coefficient_in_programming_languages
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
private static long factorial(int n) {
|
public static long binomialCoefficient(int n, int k) {
|
||||||
return (n <= 1 || n > 20) ? 1 : n * factorial(n - 1);
|
if (k < 0 || k > n)
|
||||||
|
return 0;
|
||||||
|
if (k == 0 || k == n)
|
||||||
|
return 1;
|
||||||
|
k = Math.min(k, n - k); // # take advantage of symmetry
|
||||||
|
long c = 1;
|
||||||
|
for (int i = 0; i < k; i++) {
|
||||||
|
c = c * (n - i) / (i + 1);
|
||||||
|
}
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the Bernstein polynomial.
|
* Calculates the Bernstein polynomial.
|
||||||
* @param i the index
|
* @param i the index
|
||||||
|
@ -117,7 +127,8 @@ public class Bezier2 {
|
||||||
* @param t the t value [0, 1]
|
* @param t the t value [0, 1]
|
||||||
*/
|
*/
|
||||||
private static double bernstein(int i, int n, float t) {
|
private static double bernstein(int i, int n, float t) {
|
||||||
return factorial(n) / (factorial(i) * factorial(n - i)) *
|
return binomialCoefficient(n, i) * Math.pow(t, i) * Math.pow(1 - t, n - i);
|
||||||
Math.pow(t, i) * Math.pow(1 - t, n - i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,13 +87,4 @@ public abstract class Curve {
|
||||||
return a * (1 - t) + b * t;
|
return a * (1 - t) + b * t;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A recursive method to evaluate polynomials in Bernstein form or Bezier curves.
|
|
||||||
* http://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm
|
|
||||||
*/
|
|
||||||
protected float deCasteljau(float[] a, int i, int order, float t) {
|
|
||||||
if (order == 0)
|
|
||||||
return a[i];
|
|
||||||
return lerp(deCasteljau(a, i, order - 1, t), deCasteljau(a, i + 1, order - 1, t), t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,6 +149,14 @@ public class OpenALStreamPlayer {
|
||||||
audio = new Mp3InputStream(ResourceLoader.getResourceAsStream(ref));
|
audio = new Mp3InputStream(ResourceLoader.getResourceAsStream(ref));
|
||||||
else
|
else
|
||||||
audio = new OggInputStream(ResourceLoader.getResourceAsStream(ref));
|
audio = new OggInputStream(ResourceLoader.getResourceAsStream(ref));
|
||||||
|
|
||||||
|
if(audio.getRate() == 0 && audio.getChannels() == 0) {
|
||||||
|
if (ref.toLowerCase().endsWith(".mp3"))
|
||||||
|
audio = new OggInputStream(ResourceLoader.getResourceAsStream(ref));
|
||||||
|
else
|
||||||
|
audio = new Mp3InputStream(ResourceLoader.getResourceAsStream(ref));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.audio = audio;
|
this.audio = audio;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user