git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7991 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent 77dd6761ee
commit c6bd03eeab
  1. 63
      engine/src/core/com/jme3/math/FastMath.java

@ -155,6 +155,61 @@ final public class FastMath {
return interpolateLinear(scale, startValue, endValue, null); return interpolateLinear(scale, startValue, endValue, null);
} }
/**
* Linear extrapolation from startValue to endValue by the given scale.
* if scale is between 0 and 1 this method returns the same result as interpolateLinear
* if the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1.
* @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0)
* @param endValue the end value (scale = 1)
* @return an extrapolation for the given parameters
*/
public static float extrapolateLinear(float scale, float startValue, float endValue) {
if (scale <= 0f) {
return startValue;
}
return ((1f - scale) * startValue) + (scale * endValue);
}
/**
* Linear extrapolation from startValue to endValue by the given scale.
* if scale is between 0 and 1 this method returns the same result as interpolateLinear
* if the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1.
* @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0)
* @param endValue the end value (scale = 1)
* @param store an initialized vector to store the return value
* @return an extrapolation for the given parameters
*/
public static Vector3f extrapolateLinear(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
if (scale <= 1f) {
return interpolateLinear(scale, startValue, endValue, store);
}
store.x = extrapolateLinear(scale, startValue.x, endValue.x);
store.y = extrapolateLinear(scale, startValue.y, endValue.y);
store.z = extrapolateLinear(scale, startValue.z, endValue.z);
return store;
}
/**
* Linear extrapolation from startValue to endValue by the given scale.
* if scale is between 0 and 1 this method returns the same result as interpolateLinear
* if the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1.
* @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0)
* @param endValue the end value (scale = 1)
* @return an extrapolation for the given parameters
*/
public static Vector3f extrapolateLinear(float scale, Vector3f startValue, Vector3f endValue) {
return extrapolateLinear(scale, startValue, endValue, null);
}
/**Interpolate a spline between at least 4 control points following the Catmull-Rom equation. /**Interpolate a spline between at least 4 control points following the Catmull-Rom equation.
* here is the interpolation matrix * here is the interpolation matrix
* m = [ 0.0 1.0 0.0 0.0 ] * m = [ 0.0 1.0 0.0 0.0 ]
@ -247,10 +302,10 @@ final public class FastMath {
float oneMinusU = 1.0f - u; float oneMinusU = 1.0f - u;
float oneMinusU2 = oneMinusU * oneMinusU; float oneMinusU2 = oneMinusU * oneMinusU;
float u2 = u * u; float u2 = u * u;
return p0 * oneMinusU2 * oneMinusU + return p0 * oneMinusU2 * oneMinusU
3.0f * p1 * u * oneMinusU2 + + 3.0f * p1 * u * oneMinusU2
3.0f * p2 * u2 * oneMinusU + + 3.0f * p2 * u2 * oneMinusU
p3 * u2 * u; + p3 * u2 * u;
} }
/**Interpolate a spline between at least 4 control points following the Bezier equation. /**Interpolate a spline between at least 4 control points following the Bezier equation.

Loading…
Cancel
Save