Optimize BoundingFrustum::Intersects(BoundingSphere)

This commit is contained in:
Wojtek Figat
2022-10-29 21:13:21 +02:00
parent 00be6ffb89
commit f1b67935b3
4 changed files with 16 additions and 5 deletions

View File

@@ -178,3 +178,14 @@ ContainmentType BoundingFrustum::Contains(const BoundingSphere& sphere) const
return ContainmentType::Contains;
}
}
bool BoundingFrustum::Intersects(const BoundingSphere& sphere) const
{
for (int32 i = 0; i < 6; i++)
{
const Real distance = Vector3::Dot(_planes[i].Normal, sphere.Center) + _planes[i].D;
if (distance < -sphere.Radius)
return false;
}
return true;
}

View File

@@ -235,10 +235,7 @@ public:
/// </summary>
/// <param name="sphere">The sphere.</param>
/// <returns>True if the current BoundingFrustum intersects a BoundingSphere, otherwise false.</returns>
FORCE_INLINE bool Intersects(const BoundingSphere& sphere) const
{
return Contains(sphere) != ContainmentType::Disjoint;
}
bool Intersects(const BoundingSphere& sphere) const;
/// <summary>
/// Checks whether the current BoundingFrustum intersects a BoundingBox.

View File

@@ -907,6 +907,7 @@ namespace FlaxEngine
/// <param name="left">First source vector.</param>
/// <param name="right">Second source vector.</param>
/// <param name="result">When the method completes, contains the dot product of the two vectors.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Dot(ref Vector3 left, ref Vector3 right, out Real result)
{
result = left.X * right.X + left.Y * right.Y + left.Z * right.Z;
@@ -918,6 +919,7 @@ namespace FlaxEngine
/// <param name="left">First source vector.</param>
/// <param name="right">Second source vector.</param>
/// <returns>The dot product of the two vectors.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Real Dot(ref Vector3 left, ref Vector3 right)
{
return left.X * right.X + left.Y * right.Y + left.Z * right.Z;
@@ -929,6 +931,7 @@ namespace FlaxEngine
/// <param name="left">First source vector.</param>
/// <param name="right">Second source vector.</param>
/// <returns>The dot product of the two vectors.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Real Dot(Vector3 left, Vector3 right)
{
return left.X * right.X + left.Y * right.Y + left.Z * right.Z;

View File

@@ -622,7 +622,7 @@ public:
}
// dot product with another vector
static T Dot(const Vector3Base& a, const Vector3Base& b)
FORCE_INLINE static T Dot(const Vector3Base& a, const Vector3Base& b)
{
return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
}