From 5d4c168e1e4f192a7ddf5c00f8d5ca91d8b10a58 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Tue, 15 Feb 2022 12:14:31 +0100 Subject: [PATCH] Add Vector3::Clamp for easier inline in optimized builds --- Source/Engine/Core/Math/Vector3.cpp | 17 ----------------- Source/Engine/Core/Math/Vector3.h | 5 ++++- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/Source/Engine/Core/Math/Vector3.cpp b/Source/Engine/Core/Math/Vector3.cpp index 72fb2d080..17d45a0a2 100644 --- a/Source/Engine/Core/Math/Vector3.cpp +++ b/Source/Engine/Core/Math/Vector3.cpp @@ -148,23 +148,6 @@ Vector3 Vector3::Clamp(const Vector3& value, const Vector3& min, const Vector3& return Vector3(x, y, z); } -void Vector3::Clamp(const Vector3& value, const Vector3& min, const Vector3& max, Vector3& result) -{ - float x = value.X; - x = x > max.X ? max.X : x; - x = x < min.X ? min.X : x; - - float y = value.Y; - y = y > max.Y ? max.Y : y; - y = y < min.Y ? min.Y : y; - - float z = value.Z; - z = z > max.Z ? max.Z : z; - z = z < min.Z ? min.Z : z; - - result = Vector3(x, y, z); -} - void Vector3::Hermite(const Vector3& value1, const Vector3& tangent1, const Vector3& value2, const Vector3& tangent2, float amount, Vector3& result) { const float squared = amount * amount; diff --git a/Source/Engine/Core/Math/Vector3.h b/Source/Engine/Core/Math/Vector3.h index c47e71cf2..bc994cb18 100644 --- a/Source/Engine/Core/Math/Vector3.h +++ b/Source/Engine/Core/Math/Vector3.h @@ -600,7 +600,10 @@ public: // @param min The minimum value, // @param max The maximum value // @param result When the method completes, contains the clamped value - static void Clamp(const Vector3& value, const Vector3& min, const Vector3& max, Vector3& result); + static void Clamp(const Vector3& value, const Vector3& min, const Vector3& max, Vector3& result) + { + result = Vector3(Math::Clamp(value.X, min.X, max.X), Math::Clamp(value.Y, min.Y, max.Y), Math::Clamp(value.Z, min.Z, max.Z)); + } // Calculates the distance between two vectors // @param value1 The first vector