Fix to bezier curve length computation.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7100 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
b17d5d3706
commit
a343fef6ea
@ -335,37 +335,23 @@ final public class FastMath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute the length on a Bezier spline between control point 1 and 2.
|
* Compute the lenght on a bezier spline between control point 1 and 2
|
||||||
* @param p0 control point 0
|
* @param p0 control point 0
|
||||||
* @param p1 control point 1
|
* @param p1 control point 1
|
||||||
* @param p2 control point 2
|
* @param p2 control point 2
|
||||||
* @param p3 control point 3
|
* @param p3 control point 3
|
||||||
* @param startRange the starting range on the segment (use 0)
|
|
||||||
* @param endRange the end range on the segment (use 1)
|
|
||||||
* @return the length of the segment
|
* @return the length of the segment
|
||||||
*/
|
*/
|
||||||
public static float getBezierP1toP2Length(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, float startRange, float endRange) {
|
public static float getBezierP1toP2Length(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) {
|
||||||
float epsilon = 0.001f;
|
float delta = 0.02f, t = 0.0f, result = 0.0f;
|
||||||
float middleValue = (startRange + endRange) * 0.5f;
|
Vector3f v1 = p0.clone(), v2 = new Vector3f();
|
||||||
Vector3f start = p1.clone();
|
while(t<=1.0f) {
|
||||||
if (startRange != 0) {
|
FastMath.interpolateBezier(t, p0, p1, p2, p3, v2);
|
||||||
FastMath.interpolateBezier(startRange, p0, p1, p2, p3, start);
|
result += v1.subtractLocal(v2).length();
|
||||||
|
v1.set(v2);
|
||||||
|
t += delta;
|
||||||
}
|
}
|
||||||
Vector3f end = p2.clone();
|
return result;
|
||||||
if (endRange != 1) {
|
|
||||||
FastMath.interpolateBezier(endRange, p0, p1, p2, p3, end);
|
|
||||||
}
|
|
||||||
Vector3f middle = FastMath.interpolateBezier(middleValue, p0, p1, p2, p3);
|
|
||||||
float l = end.subtract(start).length();
|
|
||||||
float l1 = middle.subtract(start).length();
|
|
||||||
float l2 = end.subtract(middle).length();
|
|
||||||
float len = l1 + l2;
|
|
||||||
if (l + epsilon < len) {
|
|
||||||
l1 = FastMath.getBezierP1toP2Length(p0, p1, p2, p3, startRange, middleValue);
|
|
||||||
l2 = FastMath.getBezierP1toP2Length(p0, p1, p2, p3, middleValue, endRange);
|
|
||||||
}
|
|
||||||
l = l1 + l2;
|
|
||||||
return l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -231,7 +231,7 @@ public class Spline implements Savable {
|
|||||||
if (controlPoints.size() > 1) {
|
if (controlPoints.size() > 1) {
|
||||||
for (int i = 0; i < controlPoints.size() - 1; i+=3) {
|
for (int i = 0; i < controlPoints.size() - 1; i+=3) {
|
||||||
l = FastMath.getBezierP1toP2Length(controlPoints.get(i),
|
l = FastMath.getBezierP1toP2Length(controlPoints.get(i),
|
||||||
controlPoints.get(i + 1), controlPoints.get(i + 2), controlPoints.get(i + 3), 0, 1);
|
controlPoints.get(i + 1), controlPoints.get(i + 2), controlPoints.get(i + 3));
|
||||||
segmentsLength.add(l);
|
segmentsLength.add(l);
|
||||||
totalLength += l;
|
totalLength += l;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user