C#: Implement BezierDerivative
Adds `BezierDerivative` method to Mathf, Vector2 and Vector3 (already exposed in Core).
This commit is contained in:
parent
cd3d6e63a6
commit
d2f7314716
|
@ -282,7 +282,7 @@ namespace Godot
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the point at the given <paramref name="t"/> on a one-dimensional Bezier curve defined by
|
/// Returns the point at the given <paramref name="t"/> on a one-dimensional Bezier curve defined by
|
||||||
/// the given <paramref name="control1"/>, <paramref name="control2"/> and <paramref name="end"/> points.
|
/// the given <paramref name="control1"/>, <paramref name="control2"/>, and <paramref name="end"/> points.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="start">The start value for the interpolation.</param>
|
/// <param name="start">The start value for the interpolation.</param>
|
||||||
/// <param name="control1">Control point that defines the bezier curve.</param>
|
/// <param name="control1">Control point that defines the bezier curve.</param>
|
||||||
|
@ -302,6 +302,27 @@ namespace Godot
|
||||||
return start * omt3 + control1 * omt2 * t * 3 + control2 * omt * t2 * 3 + end * t3;
|
return start * omt3 + control1 * omt2 * t * 3 + control2 * omt * t2 * 3 + end * t3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the derivative at the given <paramref name="t"/> on a one dimensional Bezier curve defined by
|
||||||
|
/// the given <paramref name="control1"/>, <paramref name="control2"/>, and <paramref name="end"/> points.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="start">The start value for the interpolation.</param>
|
||||||
|
/// <param name="control1">Control point that defines the bezier curve.</param>
|
||||||
|
/// <param name="control2">Control point that defines the bezier curve.</param>
|
||||||
|
/// <param name="end">The destination value for the interpolation.</param>
|
||||||
|
/// <param name="t">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param>
|
||||||
|
/// <returns>The resulting value of the interpolation.</returns>
|
||||||
|
public static real_t BezierDerivative(real_t start, real_t control1, real_t control2, real_t end, real_t t)
|
||||||
|
{
|
||||||
|
// Formula from Wikipedia article on Bezier curves
|
||||||
|
real_t omt = 1 - t;
|
||||||
|
real_t omt2 = omt * omt;
|
||||||
|
real_t t2 = t * t;
|
||||||
|
|
||||||
|
real_t d = (control1 - start) * 3 * omt2 + (control2 - control1) * 6 * omt * t + (end - control2) * 3 * t2;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts an angle expressed in degrees to radians.
|
/// Converts an angle expressed in degrees to radians.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -240,7 +240,7 @@ namespace Godot
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the point at the given <paramref name="t"/> on a one-dimensional Bezier curve defined by this vector
|
/// Returns the point at the given <paramref name="t"/> on a one-dimensional Bezier curve defined by this vector
|
||||||
/// and the given <paramref name="control1"/>, <paramref name="control2"/> and <paramref name="end"/> points.
|
/// and the given <paramref name="control1"/>, <paramref name="control2"/>, and <paramref name="end"/> points.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="control1">Control point that defines the bezier curve.</param>
|
/// <param name="control1">Control point that defines the bezier curve.</param>
|
||||||
/// <param name="control2">Control point that defines the bezier curve.</param>
|
/// <param name="control2">Control point that defines the bezier curve.</param>
|
||||||
|
@ -259,6 +259,23 @@ namespace Godot
|
||||||
return this * omt3 + control1 * omt2 * t * 3 + control2 * omt * t2 * 3 + end * t3;
|
return this * omt3 + control1 * omt2 * t * 3 + control2 * omt * t2 * 3 + end * t3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the derivative at the given <paramref name="t"/> on the Bezier curve defined by this vector
|
||||||
|
/// and the given <paramref name="control1"/>, <paramref name="control2"/>, and <paramref name="end"/> points.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="control1">Control point that defines the bezier curve.</param>
|
||||||
|
/// <param name="control2">Control point that defines the bezier curve.</param>
|
||||||
|
/// <param name="end">The destination value for the interpolation.</param>
|
||||||
|
/// <param name="t">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param>
|
||||||
|
/// <returns>The resulting value of the interpolation.</returns>
|
||||||
|
public readonly Vector2 BezierDerivative(Vector2 control1, Vector2 control2, Vector2 end, real_t t)
|
||||||
|
{
|
||||||
|
return new Vector2(
|
||||||
|
Mathf.BezierDerivative(x, control1.x, control2.x, end.x, t),
|
||||||
|
Mathf.BezierDerivative(y, control1.y, control2.y, end.y, t)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the normalized vector pointing from this vector to <paramref name="to"/>.
|
/// Returns the normalized vector pointing from this vector to <paramref name="to"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -234,7 +234,7 @@ namespace Godot
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the point at the given <paramref name="t"/> on a one-dimensional Bezier curve defined by this vector
|
/// Returns the point at the given <paramref name="t"/> on a one-dimensional Bezier curve defined by this vector
|
||||||
/// and the given <paramref name="control1"/>, <paramref name="control2"/> and <paramref name="end"/> points.
|
/// and the given <paramref name="control1"/>, <paramref name="control2"/>, and <paramref name="end"/> points.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="control1">Control point that defines the bezier curve.</param>
|
/// <param name="control1">Control point that defines the bezier curve.</param>
|
||||||
/// <param name="control2">Control point that defines the bezier curve.</param>
|
/// <param name="control2">Control point that defines the bezier curve.</param>
|
||||||
|
@ -253,6 +253,24 @@ namespace Godot
|
||||||
return this * omt3 + control1 * omt2 * t * 3 + control2 * omt * t2 * 3 + end * t3;
|
return this * omt3 + control1 * omt2 * t * 3 + control2 * omt * t2 * 3 + end * t3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the derivative at the given <paramref name="t"/> on the Bezier curve defined by this vector
|
||||||
|
/// and the given <paramref name="control1"/>, <paramref name="control2"/>, and <paramref name="end"/> points.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="control1">Control point that defines the bezier curve.</param>
|
||||||
|
/// <param name="control2">Control point that defines the bezier curve.</param>
|
||||||
|
/// <param name="end">The destination value for the interpolation.</param>
|
||||||
|
/// <param name="t">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param>
|
||||||
|
/// <returns>The resulting value of the interpolation.</returns>
|
||||||
|
public readonly Vector3 BezierDerivative(Vector3 control1, Vector3 control2, Vector3 end, real_t t)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
Mathf.BezierDerivative(x, control1.x, control2.x, end.x, t),
|
||||||
|
Mathf.BezierDerivative(y, control1.y, control2.y, end.y, t),
|
||||||
|
Mathf.BezierDerivative(z, control1.z, control2.z, end.y, t)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the normalized vector pointing from this vector to <paramref name="to"/>.
|
/// Returns the normalized vector pointing from this vector to <paramref name="to"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue