/** * Interpolate a spline between at least 4 control points using the * Catmull-Rom equation. Here is the interpolation matrix: * m = [ 0.0 1.0 0.0 0.0 ] * [-T 0.0 T 0.0 ] * [ 2T T-3 3-2T -T ] * [-T 2-T T-2 T ] * where T is the tension of the curve * the result is a value between p1 and p2, t=0 for p1, t=1 for p2 * @param u value from 0 to 1 * @param T The tension of the curve * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @return Catmull–Rom interpolation */ public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) { return interpolateCatmullRom(u, T, p0, p1, p2, p3, null); }
/**Interpolate a spline between at least 4 control points following the Catmull-Rom equation. * here is the interpolation matrix * m = [ 0.0 1.0 0.0 0.0 ] * [-T 0.0 T 0.0 ] * [ 2T T-3 3-2T -T ] * [-T 2-T T-2 T ] * where T is the tension of the curve * the result is a value between p1 and p2, t=0 for p1, t=1 for p2 * @param u value from 0 to 1 * @param T The tension of the curve * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @param store a Vector3f to store the result * @return Catmull–Rom interpolation */ public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) { if (store == null) { store = new Vector3f(); } store.x = interpolateCatmullRom(u, T, p0.x, p1.x, p2.x, p3.x); store.y = interpolateCatmullRom(u, T, p0.y, p1.y, p2.y, p3.y); store.z = interpolateCatmullRom(u, T, p0.z, p1.z, p2.z, p3.z); return store; }
/** * Interpolate a position on the spline * @param value a value from 0 to 1 that represent the position between the current control point and the next one * @param currentControlPoint the current control point * @param store a vector to store the result (use null to create a new one that will be returned by the method) * @return the position */ public Vector3f interpolate(float value, int currentControlPoint, Vector3f store) { if (store == null) { store = new Vector3f(); } switch (type) { case CatmullRom: FastMath.interpolateCatmullRom(value, curveTension, CRcontrolPoints.get(currentControlPoint), CRcontrolPoints.get(currentControlPoint + 1), CRcontrolPoints.get(currentControlPoint + 2), CRcontrolPoints.get(currentControlPoint + 3), store); break; case Linear: FastMath.interpolateLinear(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), store); break; case Bezier: FastMath.interpolateBezier(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), controlPoints.get(currentControlPoint + 2), controlPoints.get(currentControlPoint + 3), store); break; case Nurb: CurveAndSurfaceMath.interpolateNurbs(value, this, store); break; default: break; } return store; }
@Override public Vector3f interpolate(float t, int currentIndex, TrackDataReader<Vector3f> data, TrackTimeReader times, Vector3f store) { data.getEntryModSkip(currentIndex - 1, p0); data.getEntryModSkip(currentIndex, p1); data.getEntryModSkip(currentIndex + 1, p2); data.getEntryModSkip(currentIndex + 2, p3); FastMath.interpolateCatmullRom(t, tension, p0, p1, p2, p3, store); return store; } }
Vector3f start = p1.clone(); if (startRange != 0) { FastMath.interpolateCatmullRom(startRange, curveTension, p0, p1, p2, p3, start); FastMath.interpolateCatmullRom(endRange, curveTension, p0, p1, p2, p3, end); Vector3f middle = FastMath.interpolateCatmullRom(middleValue, curveTension, p0, p1, p2, p3); float l = end.subtract(start).length(); float l1 = middle.subtract(start).length();
/**Interpolate a spline between at least 4 control points following the Catmull-Rom equation. * here is the interpolation matrix * m = [ 0.0 1.0 0.0 0.0 ] * [-T 0.0 T 0.0 ] * [ 2T T-3 3-2T -T ] * [-T 2-T T-2 T ] * where T is the tension of the curve * the result is a value between p1 and p2, t=0 for p1, t=1 for p2 * @param u value from 0 to 1 * @param T The tension of the curve * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @return catmull-Rom interpolation */ public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) { return interpolateCatmullRom(u, T, p0, p1, p2, p3, null); }
/** * Interpolate a spline between at least 4 control points using the * Catmull-Rom equation. Here is the interpolation matrix: * m = [ 0.0 1.0 0.0 0.0 ] * [-T 0.0 T 0.0 ] * [ 2T T-3 3-2T -T ] * [-T 2-T T-2 T ] * where T is the tension of the curve * the result is a value between p1 and p2, t=0 for p1, t=1 for p2 * @param u value from 0 to 1 * @param T The tension of the curve * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @return Catmull–Rom interpolation */ public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) { return interpolateCatmullRom(u, T, p0, p1, p2, p3, null); }
/**Interpolate a spline between at least 4 control points following the Catmull-Rom equation. * here is the interpolation matrix * m = [ 0.0 1.0 0.0 0.0 ] * [-T 0.0 T 0.0 ] * [ 2T T-3 3-2T -T ] * [-T 2-T T-2 T ] * where T is the tension of the curve * the result is a value between p1 and p2, t=0 for p1, t=1 for p2 * @param u value from 0 to 1 * @param T The tension of the curve * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @param store a Vector3f to store the result * @return Catmull–Rom interpolation */ public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) { if (store == null) { store = new Vector3f(); } store.x = interpolateCatmullRom(u, T, p0.x, p1.x, p2.x, p3.x); store.y = interpolateCatmullRom(u, T, p0.y, p1.y, p2.y, p3.y); store.z = interpolateCatmullRom(u, T, p0.z, p1.z, p2.z, p3.z); return store; }
/**Interpolate a spline between at least 4 control points following the Catmull-Rom equation. * here is the interpolation matrix * m = [ 0.0 1.0 0.0 0.0 ] * [-T 0.0 T 0.0 ] * [ 2T T-3 3-2T -T ] * [-T 2-T T-2 T ] * where T is the tension of the curve * the result is a value between p1 and p2, t=0 for p1, t=1 for p2 * @param u value from 0 to 1 * @param T The tension of the curve * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @param store a Vector3f to store the result * @return catmull-Rom interpolation */ public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) { if (store == null) { store = new Vector3f(); } store.x = interpolateCatmullRom(u, T, p0.x, p1.x, p2.x, p3.x); store.y = interpolateCatmullRom(u, T, p0.y, p1.y, p2.y, p3.y); store.z = interpolateCatmullRom(u, T, p0.z, p1.z, p2.z, p3.z); return store; }
/** * Interpolate a position on the spline * @param value a value from 0 to 1 that represent the position between the current control point and the next one * @param currentControlPoint the current control point * @param store a vector to store the result (use null to create a new one that will be returned by the method) * @return the position */ public Vector3f interpolate(float value, int currentControlPoint, Vector3f store) { if (store == null) { store = new Vector3f(); } switch (type) { case CatmullRom: FastMath.interpolateCatmullRom(value, curveTension, CRcontrolPoints.get(currentControlPoint), CRcontrolPoints.get(currentControlPoint + 1), CRcontrolPoints.get(currentControlPoint + 2), CRcontrolPoints.get(currentControlPoint + 3), store); break; case Linear: FastMath.interpolateLinear(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), store); break; case Bezier: FastMath.interpolateBezier(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), controlPoints.get(currentControlPoint + 2), controlPoints.get(currentControlPoint + 3), store); break; case Nurb: CurveAndSurfaceMath.interpolateNurbs(value, this, store); break; default: break; } return store; }
/** * Iterpolate a position on the spline * @param value a value from 0 to 1 that represent the postion between the curent control point and the next one * @param currentControlPoint the current control point * @param store a vector to store the result (use null to create a new one that will be returned by the method) * @return the position */ public Vector3f interpolate(float value, int currentControlPoint, Vector3f store) { if (store == null) { store = new Vector3f(); } switch (type) { case CatmullRom: FastMath.interpolateCatmullRom(value, curveTension, CRcontrolPoints.get(currentControlPoint), CRcontrolPoints.get(currentControlPoint + 1), CRcontrolPoints.get(currentControlPoint + 2), CRcontrolPoints.get(currentControlPoint + 3), store); break; case Linear: FastMath.interpolateLinear(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), store); break; case Bezier: FastMath.interpolateBezier(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), controlPoints.get(currentControlPoint + 2), controlPoints.get(currentControlPoint + 3), store); break; case Nurb: CurveAndSurfaceMath.interpolateNurbs(value, this, store); break; default: break; } return store; }
Vector3f start = p1.clone(); if (startRange != 0) { FastMath.interpolateCatmullRom(startRange, curveTension, p0, p1, p2, p3, start); FastMath.interpolateCatmullRom(endRange, curveTension, p0, p1, p2, p3, end); Vector3f middle = FastMath.interpolateCatmullRom(middleValue, curveTension, p0, p1, p2, p3); float l = end.subtract(start).length(); float l1 = middle.subtract(start).length();
Vector3f start = p1.clone(); if (startRange != 0) { FastMath.interpolateCatmullRom(startRange, curveTension, p0, p1, p2, p3, start); FastMath.interpolateCatmullRom(endRange, curveTension, p0, p1, p2, p3, end); Vector3f middle = FastMath.interpolateCatmullRom(middleValue, curveTension, p0, p1, p2, p3); float l = end.subtract(start).length(); float l1 = middle.subtract(start).length();