2016-08-22 18:43:47 +00:00
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
// DirectXCollision.h -- C++ Collision Math library
|
|
|
|
//
|
2021-02-27 07:17:26 +00:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
2018-03-19 19:12:03 +00:00
|
|
|
// Licensed under the MIT License.
|
2016-08-22 18:43:47 +00:00
|
|
|
//
|
|
|
|
// http://go.microsoft.com/fwlink/?LinkID=615560
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "DirectXMath.h"
|
|
|
|
|
|
|
|
namespace DirectX
|
|
|
|
{
|
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
enum ContainmentType
|
|
|
|
{
|
|
|
|
DISJOINT = 0,
|
|
|
|
INTERSECTS = 1,
|
|
|
|
CONTAINS = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
enum PlaneIntersectionType
|
|
|
|
{
|
|
|
|
FRONT = 0,
|
|
|
|
INTERSECTING = 1,
|
|
|
|
BACK = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BoundingBox;
|
|
|
|
struct BoundingOrientedBox;
|
|
|
|
struct BoundingFrustum;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2021-11-29 21:08:15 +00:00
|
|
|
#ifdef _MSC_VER
|
2016-08-22 18:43:47 +00:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4324 4820)
|
2020-03-01 00:07:57 +00:00
|
|
|
// C4324: alignment padding warnings
|
|
|
|
// C4820: Off by default noise
|
2021-11-29 21:08:15 +00:00
|
|
|
#endif
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
// Bounding sphere
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
struct BoundingSphere
|
|
|
|
{
|
|
|
|
XMFLOAT3 Center; // Center of the sphere.
|
|
|
|
float Radius; // Radius of the sphere.
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
// Creators
|
|
|
|
BoundingSphere() noexcept : Center(0, 0, 0), Radius(1.f) {}
|
2018-04-04 00:52:24 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
BoundingSphere(const BoundingSphere&) = default;
|
|
|
|
BoundingSphere& operator=(const BoundingSphere&) = default;
|
2018-04-04 00:52:24 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
BoundingSphere(BoundingSphere&&) = default;
|
|
|
|
BoundingSphere& operator=(BoundingSphere&&) = default;
|
2018-04-04 00:52:24 +00:00
|
|
|
|
2020-03-01 06:40:50 +00:00
|
|
|
constexpr BoundingSphere(_In_ const XMFLOAT3& center, _In_ float radius) noexcept
|
2020-03-01 00:07:57 +00:00
|
|
|
: Center(center), Radius(radius) {}
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
// Methods
|
2020-03-01 06:12:46 +00:00
|
|
|
void XM_CALLCONV Transform(_Out_ BoundingSphere& Out, _In_ FXMMATRIX M) const noexcept;
|
|
|
|
void XM_CALLCONV Transform(_Out_ BoundingSphere& Out, _In_ float Scale, _In_ FXMVECTOR Rotation, _In_ FXMVECTOR Translation) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Transform the sphere
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
ContainmentType XM_CALLCONV Contains(_In_ FXMVECTOR Point) const noexcept;
|
|
|
|
ContainmentType XM_CALLCONV Contains(_In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingSphere& sh) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingBox& box) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingOrientedBox& box) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingFrustum& fr) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool Intersects(_In_ const BoundingSphere& sh) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingBox& box) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingOrientedBox& box) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingFrustum& fr) const noexcept;
|
2019-01-30 22:13:18 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool XM_CALLCONV Intersects(_In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Triangle-sphere test
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
PlaneIntersectionType XM_CALLCONV Intersects(_In_ FXMVECTOR Plane) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Plane-sphere test
|
2019-01-30 22:13:18 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool XM_CALLCONV Intersects(_In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float& Dist) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Ray-sphere test
|
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
ContainmentType XM_CALLCONV ContainedBy(_In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
|
2020-03-01 06:12:46 +00:00
|
|
|
_In_ GXMVECTOR Plane3, _In_ HXMVECTOR Plane4, _In_ HXMVECTOR Plane5) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Test sphere against six planes (see BoundingFrustum::GetPlanes)
|
|
|
|
|
2022-01-18 07:31:04 +00:00
|
|
|
// Static methods
|
2020-03-01 06:12:46 +00:00
|
|
|
static void CreateMerged(_Out_ BoundingSphere& Out, _In_ const BoundingSphere& S1, _In_ const BoundingSphere& S2) noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
static void CreateFromBoundingBox(_Out_ BoundingSphere& Out, _In_ const BoundingBox& box) noexcept;
|
|
|
|
static void CreateFromBoundingBox(_Out_ BoundingSphere& Out, _In_ const BoundingOrientedBox& box) noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
static void CreateFromPoints(_Out_ BoundingSphere& Out, _In_ size_t Count,
|
2020-03-01 06:12:46 +00:00
|
|
|
_In_reads_bytes_(sizeof(XMFLOAT3) + Stride * (Count - 1)) const XMFLOAT3* pPoints, _In_ size_t Stride) noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
static void CreateFromFrustum(_Out_ BoundingSphere& Out, _In_ const BoundingFrustum& fr) noexcept;
|
2020-03-01 00:07:57 +00:00
|
|
|
};
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
// Axis-aligned bounding box
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
struct BoundingBox
|
|
|
|
{
|
2022-01-18 07:31:04 +00:00
|
|
|
static constexpr size_t CORNER_COUNT = 8;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
XMFLOAT3 Center; // Center of the box.
|
|
|
|
XMFLOAT3 Extents; // Distance from the center to each side.
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
// Creators
|
|
|
|
BoundingBox() noexcept : Center(0, 0, 0), Extents(1.f, 1.f, 1.f) {}
|
2018-04-04 00:52:24 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
BoundingBox(const BoundingBox&) = default;
|
|
|
|
BoundingBox& operator=(const BoundingBox&) = default;
|
2018-04-04 00:52:24 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
BoundingBox(BoundingBox&&) = default;
|
|
|
|
BoundingBox& operator=(BoundingBox&&) = default;
|
2018-04-04 00:52:24 +00:00
|
|
|
|
2020-03-01 06:40:50 +00:00
|
|
|
constexpr BoundingBox(_In_ const XMFLOAT3& center, _In_ const XMFLOAT3& extents) noexcept
|
2020-03-01 00:07:57 +00:00
|
|
|
: Center(center), Extents(extents) {}
|
2019-01-30 22:13:18 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
// Methods
|
2020-03-01 06:12:46 +00:00
|
|
|
void XM_CALLCONV Transform(_Out_ BoundingBox& Out, _In_ FXMMATRIX M) const noexcept;
|
|
|
|
void XM_CALLCONV Transform(_Out_ BoundingBox& Out, _In_ float Scale, _In_ FXMVECTOR Rotation, _In_ FXMVECTOR Translation) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
void GetCorners(_Out_writes_(8) XMFLOAT3* Corners) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Gets the 8 corners of the box
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
ContainmentType XM_CALLCONV Contains(_In_ FXMVECTOR Point) const noexcept;
|
|
|
|
ContainmentType XM_CALLCONV Contains(_In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingSphere& sh) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingBox& box) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingOrientedBox& box) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingFrustum& fr) const noexcept;
|
2019-01-30 22:13:18 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool Intersects(_In_ const BoundingSphere& sh) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingBox& box) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingOrientedBox& box) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingFrustum& fr) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool XM_CALLCONV Intersects(_In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Triangle-Box test
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
PlaneIntersectionType XM_CALLCONV Intersects(_In_ FXMVECTOR Plane) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Plane-box test
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool XM_CALLCONV Intersects(_In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float& Dist) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Ray-Box test
|
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
ContainmentType XM_CALLCONV ContainedBy(_In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
|
2020-03-01 06:12:46 +00:00
|
|
|
_In_ GXMVECTOR Plane3, _In_ HXMVECTOR Plane4, _In_ HXMVECTOR Plane5) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Test box against six planes (see BoundingFrustum::GetPlanes)
|
|
|
|
|
2022-01-18 07:31:04 +00:00
|
|
|
// Static methods
|
2020-03-01 06:12:46 +00:00
|
|
|
static void CreateMerged(_Out_ BoundingBox& Out, _In_ const BoundingBox& b1, _In_ const BoundingBox& b2) noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
static void CreateFromSphere(_Out_ BoundingBox& Out, _In_ const BoundingSphere& sh) noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
static void XM_CALLCONV CreateFromPoints(_Out_ BoundingBox& Out, _In_ FXMVECTOR pt1, _In_ FXMVECTOR pt2) noexcept;
|
2020-03-01 00:07:57 +00:00
|
|
|
static void CreateFromPoints(_Out_ BoundingBox& Out, _In_ size_t Count,
|
2020-03-01 06:12:46 +00:00
|
|
|
_In_reads_bytes_(sizeof(XMFLOAT3) + Stride * (Count - 1)) const XMFLOAT3* pPoints, _In_ size_t Stride) noexcept;
|
2020-03-01 00:07:57 +00:00
|
|
|
};
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
// Oriented bounding box
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
struct BoundingOrientedBox
|
|
|
|
{
|
2022-01-18 07:31:04 +00:00
|
|
|
static constexpr size_t CORNER_COUNT = 8;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
XMFLOAT3 Center; // Center of the box.
|
|
|
|
XMFLOAT3 Extents; // Distance from the center to each side.
|
|
|
|
XMFLOAT4 Orientation; // Unit quaternion representing rotation (box -> world).
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
// Creators
|
|
|
|
BoundingOrientedBox() noexcept : Center(0, 0, 0), Extents(1.f, 1.f, 1.f), Orientation(0, 0, 0, 1.f) {}
|
2018-04-04 00:52:24 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
BoundingOrientedBox(const BoundingOrientedBox&) = default;
|
|
|
|
BoundingOrientedBox& operator=(const BoundingOrientedBox&) = default;
|
2018-04-04 00:52:24 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
BoundingOrientedBox(BoundingOrientedBox&&) = default;
|
|
|
|
BoundingOrientedBox& operator=(BoundingOrientedBox&&) = default;
|
2018-04-04 00:52:24 +00:00
|
|
|
|
2022-04-05 06:10:47 +00:00
|
|
|
constexpr BoundingOrientedBox(_In_ const XMFLOAT3& center, _In_ const XMFLOAT3& extents, _In_ const XMFLOAT4& orientation) noexcept
|
|
|
|
: Center(center), Extents(extents), Orientation(orientation) {}
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
// Methods
|
2020-03-01 06:12:46 +00:00
|
|
|
void XM_CALLCONV Transform(_Out_ BoundingOrientedBox& Out, _In_ FXMMATRIX M) const noexcept;
|
|
|
|
void XM_CALLCONV Transform(_Out_ BoundingOrientedBox& Out, _In_ float Scale, _In_ FXMVECTOR Rotation, _In_ FXMVECTOR Translation) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
void GetCorners(_Out_writes_(8) XMFLOAT3* Corners) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Gets the 8 corners of the box
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
ContainmentType XM_CALLCONV Contains(_In_ FXMVECTOR Point) const noexcept;
|
|
|
|
ContainmentType XM_CALLCONV Contains(_In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingSphere& sh) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingBox& box) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingOrientedBox& box) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingFrustum& fr) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool Intersects(_In_ const BoundingSphere& sh) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingBox& box) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingOrientedBox& box) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingFrustum& fr) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool XM_CALLCONV Intersects(_In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Triangle-OrientedBox test
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
PlaneIntersectionType XM_CALLCONV Intersects(_In_ FXMVECTOR Plane) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Plane-OrientedBox test
|
2019-01-30 22:13:18 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool XM_CALLCONV Intersects(_In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float& Dist) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Ray-OrientedBox test
|
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
ContainmentType XM_CALLCONV ContainedBy(_In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
|
2020-03-01 06:12:46 +00:00
|
|
|
_In_ GXMVECTOR Plane3, _In_ HXMVECTOR Plane4, _In_ HXMVECTOR Plane5) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Test OrientedBox against six planes (see BoundingFrustum::GetPlanes)
|
|
|
|
|
2022-01-18 07:31:04 +00:00
|
|
|
// Static methods
|
2020-03-01 06:12:46 +00:00
|
|
|
static void CreateFromBoundingBox(_Out_ BoundingOrientedBox& Out, _In_ const BoundingBox& box) noexcept;
|
2020-03-01 00:07:57 +00:00
|
|
|
|
|
|
|
static void CreateFromPoints(_Out_ BoundingOrientedBox& Out, _In_ size_t Count,
|
2020-03-01 06:12:46 +00:00
|
|
|
_In_reads_bytes_(sizeof(XMFLOAT3) + Stride * (Count - 1)) const XMFLOAT3* pPoints, _In_ size_t Stride) noexcept;
|
2020-03-01 00:07:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
// Bounding frustum
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
struct BoundingFrustum
|
|
|
|
{
|
2022-01-18 07:31:04 +00:00
|
|
|
static constexpr size_t CORNER_COUNT = 8;
|
2020-03-01 00:07:57 +00:00
|
|
|
|
|
|
|
XMFLOAT3 Origin; // Origin of the frustum (and projection).
|
|
|
|
XMFLOAT4 Orientation; // Quaternion representing rotation.
|
|
|
|
|
|
|
|
float RightSlope; // Positive X (X/Z)
|
|
|
|
float LeftSlope; // Negative X
|
|
|
|
float TopSlope; // Positive Y (Y/Z)
|
|
|
|
float BottomSlope; // Negative Y
|
|
|
|
float Near, Far; // Z of the near plane and far plane.
|
|
|
|
|
|
|
|
// Creators
|
|
|
|
BoundingFrustum() noexcept :
|
|
|
|
Origin(0, 0, 0), Orientation(0, 0, 0, 1.f), RightSlope(1.f), LeftSlope(-1.f),
|
|
|
|
TopSlope(1.f), BottomSlope(-1.f), Near(0), Far(1.f) {}
|
|
|
|
|
|
|
|
BoundingFrustum(const BoundingFrustum&) = default;
|
|
|
|
BoundingFrustum& operator=(const BoundingFrustum&) = default;
|
|
|
|
|
|
|
|
BoundingFrustum(BoundingFrustum&&) = default;
|
|
|
|
BoundingFrustum& operator=(BoundingFrustum&&) = default;
|
|
|
|
|
2022-04-05 06:10:47 +00:00
|
|
|
constexpr BoundingFrustum(_In_ const XMFLOAT3& origin, _In_ const XMFLOAT4& orientation,
|
|
|
|
_In_ float rightSlope, _In_ float leftSlope, _In_ float topSlope, _In_ float bottomSlope,
|
|
|
|
_In_ float nearPlane, _In_ float farPlane) noexcept
|
|
|
|
: Origin(origin), Orientation(orientation),
|
|
|
|
RightSlope(rightSlope), LeftSlope(leftSlope), TopSlope(topSlope), BottomSlope(bottomSlope),
|
|
|
|
Near(nearPlane), Far(farPlane) {}
|
2020-08-03 00:38:25 +00:00
|
|
|
BoundingFrustum(_In_ CXMMATRIX Projection, bool rhcoords = false) noexcept;
|
2020-03-01 00:07:57 +00:00
|
|
|
|
|
|
|
// Methods
|
2020-03-01 06:12:46 +00:00
|
|
|
void XM_CALLCONV Transform(_Out_ BoundingFrustum& Out, _In_ FXMMATRIX M) const noexcept;
|
|
|
|
void XM_CALLCONV Transform(_Out_ BoundingFrustum& Out, _In_ float Scale, _In_ FXMVECTOR Rotation, _In_ FXMVECTOR Translation) const noexcept;
|
2020-03-01 00:07:57 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
void GetCorners(_Out_writes_(8) XMFLOAT3* Corners) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Gets the 8 corners of the frustum
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
ContainmentType XM_CALLCONV Contains(_In_ FXMVECTOR Point) const noexcept;
|
|
|
|
ContainmentType XM_CALLCONV Contains(_In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingSphere& sp) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingBox& box) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingOrientedBox& box) const noexcept;
|
|
|
|
ContainmentType Contains(_In_ const BoundingFrustum& fr) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Frustum-Frustum test
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool Intersects(_In_ const BoundingSphere& sh) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingBox& box) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingOrientedBox& box) const noexcept;
|
|
|
|
bool Intersects(_In_ const BoundingFrustum& fr) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool XM_CALLCONV Intersects(_In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Triangle-Frustum test
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
PlaneIntersectionType XM_CALLCONV Intersects(_In_ FXMVECTOR Plane) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Plane-Frustum test
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool XM_CALLCONV Intersects(_In_ FXMVECTOR rayOrigin, _In_ FXMVECTOR Direction, _Out_ float& Dist) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Ray-Frustum test
|
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
ContainmentType XM_CALLCONV ContainedBy(_In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
|
2020-03-01 06:12:46 +00:00
|
|
|
_In_ GXMVECTOR Plane3, _In_ HXMVECTOR Plane4, _In_ HXMVECTOR Plane5) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Test frustum against six planes (see BoundingFrustum::GetPlanes)
|
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
void GetPlanes(_Out_opt_ XMVECTOR* NearPlane, _Out_opt_ XMVECTOR* FarPlane, _Out_opt_ XMVECTOR* RightPlane,
|
2020-03-01 06:12:46 +00:00
|
|
|
_Out_opt_ XMVECTOR* LeftPlane, _Out_opt_ XMVECTOR* TopPlane, _Out_opt_ XMVECTOR* BottomPlane) const noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Create 6 Planes representation of Frustum
|
|
|
|
|
2022-01-18 07:31:04 +00:00
|
|
|
// Static methods
|
2020-08-03 00:38:25 +00:00
|
|
|
static void XM_CALLCONV CreateFromMatrix(_Out_ BoundingFrustum& Out, _In_ FXMMATRIX Projection, bool rhcoords = false) noexcept;
|
2020-03-01 00:07:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Triangle intersection testing routines.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
namespace TriangleTests
|
|
|
|
{
|
2020-03-01 06:12:46 +00:00
|
|
|
bool XM_CALLCONV Intersects(_In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _In_ FXMVECTOR V0, _In_ GXMVECTOR V1, _In_ HXMVECTOR V2, _Out_ float& Dist) noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Ray-Triangle
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
bool XM_CALLCONV Intersects(_In_ FXMVECTOR A0, _In_ FXMVECTOR A1, _In_ FXMVECTOR A2, _In_ GXMVECTOR B0, _In_ HXMVECTOR B1, _In_ HXMVECTOR B2) noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Triangle-Triangle
|
|
|
|
|
2020-03-01 06:12:46 +00:00
|
|
|
PlaneIntersectionType XM_CALLCONV Intersects(_In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2, _In_ GXMVECTOR Plane) noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Plane-Triangle
|
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
ContainmentType XM_CALLCONV ContainedBy(_In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2,
|
|
|
|
_In_ GXMVECTOR Plane0, _In_ HXMVECTOR Plane1, _In_ HXMVECTOR Plane2,
|
2020-03-01 06:12:46 +00:00
|
|
|
_In_ CXMVECTOR Plane3, _In_ CXMVECTOR Plane4, _In_ CXMVECTOR Plane5) noexcept;
|
2016-08-22 18:43:47 +00:00
|
|
|
// Test a triangle against six planes at once (see BoundingFrustum::GetPlanes)
|
2020-03-01 00:07:57 +00:00
|
|
|
}
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2021-11-29 21:08:15 +00:00
|
|
|
#ifdef _MSC_VER
|
2016-08-22 18:43:47 +00:00
|
|
|
#pragma warning(pop)
|
2021-11-29 21:08:15 +00:00
|
|
|
#endif
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2020-03-01 00:07:57 +00:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* Implementation
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2021-11-29 21:08:15 +00:00
|
|
|
#ifdef _MSC_VER
|
2016-08-22 18:43:47 +00:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4068 4365 4616 6001)
|
2020-03-01 00:07:57 +00:00
|
|
|
// C4068/4616: ignore unknown pragmas
|
|
|
|
// C4365: Off by default noise
|
|
|
|
// C6001: False positives
|
2021-11-29 21:08:15 +00:00
|
|
|
#endif
|
2023-05-05 20:22:46 +00:00
|
|
|
|
2017-05-18 00:46:45 +00:00
|
|
|
#ifdef _PREFAST_
|
2016-08-22 18:43:47 +00:00
|
|
|
#pragma prefast(push)
|
|
|
|
#pragma prefast(disable : 25000, "FXMVECTOR is 16 bytes")
|
2018-04-17 17:22:14 +00:00
|
|
|
#pragma prefast(disable : 26495, "Union initialization confuses /analyze")
|
2017-05-18 00:46:45 +00:00
|
|
|
#endif
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2023-05-05 20:22:46 +00:00
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wfloat-equal"
|
|
|
|
#pragma clang diagnostic ignored "-Wunknown-warning-option"
|
|
|
|
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
|
|
|
|
#endif
|
|
|
|
|
2016-08-22 18:43:47 +00:00
|
|
|
#include "DirectXCollision.inl"
|
|
|
|
|
2023-05-05 20:22:46 +00:00
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif
|
2017-05-18 00:46:45 +00:00
|
|
|
#ifdef _PREFAST_
|
2016-08-22 18:43:47 +00:00
|
|
|
#pragma prefast(pop)
|
2017-05-18 00:46:45 +00:00
|
|
|
#endif
|
2021-11-29 21:08:15 +00:00
|
|
|
#ifdef _MSC_VER
|
2016-08-22 18:43:47 +00:00
|
|
|
#pragma warning(pop)
|
2021-11-29 21:08:15 +00:00
|
|
|
#endif
|
2016-08-22 18:43:47 +00:00
|
|
|
|
2018-01-16 22:30:35 +00:00
|
|
|
} // namespace DirectX
|
2016-08-22 18:43:47 +00:00
|
|
|
|