// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System.Runtime.CompilerServices;
namespace math
{
///
/// A bounding frustum.
///
public struct BoundingFrustum
{
///
/// The left plane of this frustum.
///
public Plane LeftPlane;
///
/// The right plane of this frustum.
///
public Plane RightPlane;
///
/// The top plane of this frustum.
///
public Plane TopPlane;
///
/// The bottom plane of this frustum.
///
public Plane BottomPlane;
///
/// The near plane of this frustum.
///
public Plane NearPlane;
///
/// The far plane of this frustum.
///
public Plane FarPlane;
///
/// Initializes a new instance of the struct from a matrix view-projection.
///
/// The matrix view projection.
public BoundingFrustum(ref Matrix matrix)
{
// Left
LeftPlane = Plane.Normalize(new Plane(
matrix.M14 + matrix.M11,
matrix.M24 + matrix.M21,
matrix.M34 + matrix.M31,
matrix.M44 + matrix.M41));
// Right
RightPlane = Plane.Normalize(new Plane(
matrix.M14 - matrix.M11,
matrix.M24 - matrix.M21,
matrix.M34 - matrix.M31,
matrix.M44 - matrix.M41));
// Top
TopPlane = Plane.Normalize(new Plane(
matrix.M14 - matrix.M12,
matrix.M24 - matrix.M22,
matrix.M34 - matrix.M32,
matrix.M44 - matrix.M42));
// Bottom
BottomPlane = Plane.Normalize(new Plane(
matrix.M14 + matrix.M12,
matrix.M24 + matrix.M22,
matrix.M34 + matrix.M32,
matrix.M44 + matrix.M42));
// Near
NearPlane = Plane.Normalize(new Plane(
matrix.M13,
matrix.M23,
matrix.M33,
matrix.M43));
// Far
FarPlane = Plane.Normalize(new Plane(
matrix.M14 - matrix.M13,
matrix.M24 - matrix.M23,
matrix.M34 - matrix.M33,
matrix.M44 - matrix.M43));
}
///
/// Check whether this frustum contains the specified .
///
/// The bounding box.
/// true if this frustum contains the specified bounding box.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Contains(ref BoundingBoxExt boundingBoxExt)
{
return CollisionHelper.FrustumContainsBox(ref this, ref boundingBoxExt);
}
}
}