From 39521f9c8e41e5a0f05adc86b95670d1ba510ad4 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Sun, 4 Sep 2022 19:55:30 -0500 Subject: Fix some bugs with Vector4 in C# --- .../glue/GodotSharp/GodotSharp/Core/Vector4.cs | 57 ++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'modules/mono/glue') diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs index d1962c68cf..e2da41ff47 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs @@ -187,7 +187,7 @@ namespace Godot ( Mathf.CubicInterpolate(x, b.x, preA.x, postB.x, weight), Mathf.CubicInterpolate(y, b.y, preA.y, postB.y, weight), - Mathf.CubicInterpolate(y, b.z, preA.z, postB.z, weight), + Mathf.CubicInterpolate(z, b.z, preA.z, postB.z, weight), Mathf.CubicInterpolate(w, b.w, preA.w, postB.w, weight) ); } @@ -212,7 +212,7 @@ namespace Godot ( Mathf.CubicInterpolateInTime(x, b.x, preA.x, postB.x, weight, t, preAT, postBT), Mathf.CubicInterpolateInTime(y, b.y, preA.y, postB.y, weight, t, preAT, postBT), - Mathf.CubicInterpolateInTime(y, b.z, preA.z, postB.z, weight, t, preAT, postBT), + Mathf.CubicInterpolateInTime(z, b.z, preA.z, postB.z, weight, t, preAT, postBT), Mathf.CubicInterpolateInTime(w, b.w, preA.w, postB.w, weight, t, preAT, postBT) ); } @@ -258,7 +258,7 @@ namespace Godot /// The dot product of the two vectors. public real_t Dot(Vector4 with) { - return (x * with.x) + (y * with.y) + (z * with.z) + (w + with.w); + return (x * with.x) + (y * with.y) + (z * with.z) + (w * with.w); } /// @@ -455,6 +455,7 @@ namespace Godot /// This can also be used to round to an arbitrary number of decimals. /// /// A vector value representing the step size to snap to. + /// The snapped vector. public Vector4 Snapped(Vector4 step) { return new Vector4( @@ -631,6 +632,56 @@ namespace Godot return vec; } + /// + /// Gets the remainder of each component of the + /// with the components of the given . + /// This operation uses truncated division, which is often not desired + /// as it does not work well with negative numbers. + /// Consider using instead + /// if you want to handle negative numbers. + /// + /// + /// + /// GD.Print(new Vector4(10, -20, 30, 40) % 7); // Prints "(3, -6, 2, 5)" + /// + /// + /// The dividend vector. + /// The divisor value. + /// The remainder vector. + public static Vector4 operator %(Vector4 vec, real_t divisor) + { + vec.x %= divisor; + vec.y %= divisor; + vec.z %= divisor; + vec.w %= divisor; + return vec; + } + + /// + /// Gets the remainder of each component of the + /// with the components of the given . + /// This operation uses truncated division, which is often not desired + /// as it does not work well with negative numbers. + /// Consider using instead + /// if you want to handle negative numbers. + /// + /// + /// + /// GD.Print(new Vector4(10, -20, 30, 10) % new Vector4(7, 8, 9, 10)); // Prints "(3, -4, 3, 0)" + /// + /// + /// The dividend vector. + /// The divisor vector. + /// The remainder vector. + public static Vector4 operator %(Vector4 vec, Vector4 divisorv) + { + vec.x %= divisorv.x; + vec.y %= divisorv.y; + vec.z %= divisorv.z; + vec.w %= divisorv.w; + return vec; + } + /// /// Returns if the vectors are exactly equal. /// Note: Due to floating-point precision errors, consider using -- cgit v1.2.3