summaryrefslogtreecommitdiff
path: root/modules/mono
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono')
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs18
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs18
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs18
3 files changed, 27 insertions, 27 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs
index bfe9600084..ce213da6a7 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs
@@ -180,6 +180,24 @@ namespace Godot
}
/// <summary>
+ /// Cubic interpolates between two values by a normalized value with pre and post values.
+ /// </summary>
+ /// <param name="from">The start value for interpolation.</param>
+ /// <param name="to">The destination value for interpolation.</param>
+ /// <param name="pre">The value which before "from" value for interpolation.</param>
+ /// <param name="post">The value which after "to" value for interpolation.</param>
+ /// <param name="weight">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 CubicInterpolate(real_t from, real_t to, real_t pre, real_t post, real_t weight)
+ {
+ return 0.5f *
+ ((from * 2.0f) +
+ (-pre + to) * weight +
+ (2.0f * pre - 5.0f * from + 4.0f * to - post) * (weight * weight) +
+ (-pre + 3.0f * from - 3.0f * to + post) * (weight * weight * weight));
+ }
+
+ /// <summary>
/// Converts an angle expressed in degrees to radians.
/// </summary>
/// <param name="deg">An angle expressed in degrees.</param>
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs
index fa7838633c..8679f28132 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs
@@ -204,20 +204,10 @@ namespace Godot
/// <returns>The interpolated vector.</returns>
public Vector2 CubicInterpolate(Vector2 b, Vector2 preA, Vector2 postB, real_t weight)
{
- Vector2 p0 = preA;
- Vector2 p1 = this;
- Vector2 p2 = b;
- Vector2 p3 = postB;
-
- real_t t = weight;
- real_t t2 = t * t;
- real_t t3 = t2 * t;
-
- return 0.5f * (
- (p1 * 2.0f) +
- ((-p0 + p2) * t) +
- (((2.0f * p0) - (5.0f * p1) + (4 * p2) - p3) * t2) +
- ((-p0 + (3.0f * p1) - (3.0f * p2) + p3) * t3)
+ return new Vector2
+ (
+ Mathf.CubicInterpolate(x, b.x, preA.x, postB.x, weight),
+ Mathf.CubicInterpolate(y, b.y, preA.y, postB.y, weight)
);
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs
index 0faf13f8b7..1e60fb9523 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs
@@ -195,19 +195,11 @@ namespace Godot
/// <returns>The interpolated vector.</returns>
public Vector3 CubicInterpolate(Vector3 b, Vector3 preA, Vector3 postB, real_t weight)
{
- Vector3 p0 = preA;
- Vector3 p1 = this;
- Vector3 p2 = b;
- Vector3 p3 = postB;
-
- real_t t = weight;
- real_t t2 = t * t;
- real_t t3 = t2 * t;
-
- return 0.5f * (
- (p1 * 2.0f) + ((-p0 + p2) * t) +
- (((2.0f * p0) - (5.0f * p1) + (4f * p2) - p3) * t2) +
- ((-p0 + (3.0f * p1) - (3.0f * p2) + p3) * t3)
+ return new Vector3
+ (
+ Mathf.CubicInterpolate(x, b.x, preA.x, postB.x, weight),
+ Mathf.CubicInterpolate(y, b.y, preA.y, postB.y, weight),
+ Mathf.CubicInterpolate(z, b.z, preA.z, postB.z, weight)
);
}