From 93513f3ea88548f90eb4bb6ccfa47aea4137b368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Wed, 25 Aug 2021 22:22:59 +0200 Subject: [PATCH] Vector Lerp --- GlitchyEngine/src/Math/Vector2.bf | 14 +++++++++++++- GlitchyEngine/src/Math/Vector3.bf | 13 +++++++++++++ GlitchyEngine/src/Math/Vector4.bf | 13 +++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/GlitchyEngine/src/Math/Vector2.bf b/GlitchyEngine/src/Math/Vector2.bf index 010aee9..945d748 100644 --- a/GlitchyEngine/src/Math/Vector2.bf +++ b/GlitchyEngine/src/Math/Vector2.bf @@ -145,7 +145,19 @@ namespace GlitchyEngine.Math { return (a - b * (Dot(a, b) / Dot(b, b))); } - + + /** + * Interpolates linearly between two given vectors. + * @param a The first vector. + * @param b The second vector. + * @param interpolationValue The value that linearly interpolates between a and b. + * (0 means a will be returned, 1 means b will be returned.) + * @returns The resulting linear interpolation. + */ + public static Vector2 Lerp(Vector2 a, Vector2 b, float interpolationValue) + { + return a + interpolationValue * (b - a); + } // // Assignment operators diff --git a/GlitchyEngine/src/Math/Vector3.bf b/GlitchyEngine/src/Math/Vector3.bf index 500e44c..3f037b3 100644 --- a/GlitchyEngine/src/Math/Vector3.bf +++ b/GlitchyEngine/src/Math/Vector3.bf @@ -180,6 +180,19 @@ namespace GlitchyEngine.Math { return .(Math.Floor(value.X), Math.Floor(value.Y), Math.Floor(value.Z)); } + + /** + * Interpolates linearly between two given vectors. + * @param a The first vector. + * @param b The second vector. + * @param interpolationValue The value that linearly interpolates between a and b. + * (0 means a will be returned, 1 means b will be returned.) + * @returns The resulting linear interpolation. + */ + public static Vector3 Lerp(Vector3 a, Vector3 b, float interpolationValue) + { + return a + interpolationValue * (b - a); + } // // Assignment operators diff --git a/GlitchyEngine/src/Math/Vector4.bf b/GlitchyEngine/src/Math/Vector4.bf index 428e9f8..07dfdb2 100644 --- a/GlitchyEngine/src/Math/Vector4.bf +++ b/GlitchyEngine/src/Math/Vector4.bf @@ -166,6 +166,19 @@ namespace GlitchyEngine.Math return (a - b * (Dot(a, b) / Dot(b, b))); } + /** + * Interpolates linearly between two given vectors. + * @param a The first vector. + * @param b The second vector. + * @param interpolationValue The value that linearly interpolates between a and b. + * (0 means a will be returned, 1 means b will be returned.) + * @returns The resulting linear interpolation. + */ + public static Vector4 Lerp(Vector4 a, Vector4 b, float interpolationValue) + { + return a + interpolationValue * (b - a); + } + // // Assignment operators //