From 465c857ff2b16d9d0256a384263d8bc851f72996 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Mon, 17 Jan 2022 10:12:05 +0100 Subject: [PATCH] Fix bounding box size setter --- Source/Engine/Core/Math/BoundingBox.cs | 60 ++++++-------------------- Source/Engine/Core/Math/BoundingBox.h | 5 ++- 2 files changed, 17 insertions(+), 48 deletions(-) diff --git a/Source/Engine/Core/Math/BoundingBox.cs b/Source/Engine/Core/Math/BoundingBox.cs index e6ad532bd..72bbf365e 100644 --- a/Source/Engine/Core/Math/BoundingBox.cs +++ b/Source/Engine/Core/Math/BoundingBox.cs @@ -71,9 +71,6 @@ namespace FlaxEngine /// /// Gets or sets the size. /// - /// - /// The size. - /// [NoSerialize] public Vector3 Size { @@ -81,17 +78,15 @@ namespace FlaxEngine set { var center = Center; - Minimum = center - value; - Maximum = center + value; + var sizeHalf = value * 0.5f; + Minimum = center - sizeHalf; + Maximum = center + sizeHalf; } } /// /// Gets or sets the center point location. /// - /// - /// The center. - /// [NoSerialize] public Vector3 Center { @@ -156,10 +151,7 @@ namespace FlaxEngine /// Determines if there is an intersection between the current object and a . /// /// The ray to test. - /// - /// When the method completes, contains the distance of the intersection, - /// or 0 if there was no intersection. - /// + /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. public bool Intersects(ref Ray ray, out float distance) { @@ -170,10 +162,7 @@ namespace FlaxEngine /// Determines if there is an intersection between the current object and a . /// /// The ray to test. - /// - /// When the method completes, contains the point of intersection, - /// or if there was no intersection. - /// + /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. public bool Intersects(ref Ray ray, out Vector3 point) { @@ -516,10 +505,7 @@ namespace FlaxEngine /// /// The first value to compare. /// The second value to compare. - /// - /// true if has the same value as ; otherwise, - /// false. - /// + /// true if has the same value as ; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(BoundingBox left, BoundingBox right) { @@ -531,10 +517,7 @@ namespace FlaxEngine /// /// The first value to compare. /// The second value to compare. - /// - /// true if has a different value than ; otherwise, - /// false. - /// + /// true if has a different value than ; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(BoundingBox left, BoundingBox right) { @@ -544,9 +527,7 @@ namespace FlaxEngine /// /// Returns a that represents this instance. /// - /// - /// A that represents this instance. - /// + /// A that represents this instance. public override string ToString() { return string.Format(CultureInfo.CurrentCulture, @@ -577,9 +558,7 @@ namespace FlaxEngine /// Returns a that represents this instance. /// /// The format provider. - /// - /// A that represents this instance. - /// + /// A that represents this instance. public string ToString(IFormatProvider formatProvider) { return string.Format(formatProvider, @@ -593,9 +572,7 @@ namespace FlaxEngine /// /// The format. /// The format provider. - /// - /// A that represents this instance. - /// + /// A that represents this instance. public string ToString(string format, IFormatProvider formatProvider) { if (format == null) @@ -610,9 +587,7 @@ namespace FlaxEngine /// /// Returns a hash code for this instance. /// - /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. - /// + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. public override int GetHashCode() { unchecked @@ -625,9 +600,7 @@ namespace FlaxEngine /// Determines whether the specified is equal to this instance. /// /// The to compare with this instance. - /// - /// true if the specified is equal to this instance; otherwise, false. - /// + /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref BoundingBox value) { @@ -638,9 +611,7 @@ namespace FlaxEngine /// Determines whether the specified is equal to this instance. /// /// The to compare with this instance. - /// - /// true if the specified is equal to this instance; otherwise, false. - /// + /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(BoundingBox value) { @@ -651,14 +622,11 @@ namespace FlaxEngine /// Determines whether the specified is equal to this instance. /// /// The to compare with this instance. - /// - /// true if the specified is equal to this instance; otherwise, false. - /// + /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { if (!(value is BoundingBox)) return false; - var strongValue = (BoundingBox)value; return Equals(ref strongValue); } diff --git a/Source/Engine/Core/Math/BoundingBox.h b/Source/Engine/Core/Math/BoundingBox.h index 154c87009..4652bb3f6 100644 --- a/Source/Engine/Core/Math/BoundingBox.h +++ b/Source/Engine/Core/Math/BoundingBox.h @@ -127,8 +127,9 @@ public: { Vector3 center; GetCenter(center); - Minimum = center - value; - Maximum = center + value; + const Vector3 sizeHalf = value * 0.5f; + Minimum = center - sizeHalf; + Maximum = center + sizeHalf; } ///