Skip to content

Commit 8d53a95

Browse files
committed
BoundingFrustum CreateFromMatrix option for RH coordinates
1 parent cc101d2 commit 8d53a95

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

Inc/DirectXCollision.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ namespace DirectX
258258
: Origin(_Origin), Orientation(_Orientation),
259259
RightSlope(_RightSlope), LeftSlope(_LeftSlope), TopSlope(_TopSlope), BottomSlope(_BottomSlope),
260260
Near(_Near), Far(_Far) {}
261-
BoundingFrustum(_In_ CXMMATRIX Projection) noexcept;
261+
BoundingFrustum(_In_ CXMMATRIX Projection, bool rhcoords = false) noexcept;
262262

263263
// Methods
264264
void XM_CALLCONV Transform(_Out_ BoundingFrustum& Out, _In_ FXMMATRIX M) const noexcept;
@@ -298,7 +298,7 @@ namespace DirectX
298298
// Create 6 Planes representation of Frustum
299299

300300
// Static methods
301-
static void XM_CALLCONV CreateFromMatrix(_Out_ BoundingFrustum& Out, _In_ FXMMATRIX Projection) noexcept;
301+
static void XM_CALLCONV CreateFromMatrix(_Out_ BoundingFrustum& Out, _In_ FXMMATRIX Projection, bool rhcoords = false) noexcept;
302302
};
303303

304304
//-----------------------------------------------------------------------------

Inc/DirectXCollision.inl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,9 +2818,9 @@ inline void BoundingOrientedBox::CreateFromPoints(BoundingOrientedBox& Out, size
28182818
****************************************************************************/
28192819

28202820
_Use_decl_annotations_
2821-
inline BoundingFrustum::BoundingFrustum(CXMMATRIX Projection) noexcept
2821+
inline BoundingFrustum::BoundingFrustum(CXMMATRIX Projection, bool rhcoords) noexcept
28222822
{
2823-
CreateFromMatrix(*this, Projection);
2823+
CreateFromMatrix(*this, Projection, rhcoords);
28242824
}
28252825

28262826

@@ -4252,7 +4252,7 @@ inline void BoundingFrustum::GetPlanes(XMVECTOR* NearPlane, XMVECTOR* FarPlane,
42524252
// constructed frustum to be incorrect.
42534253
//-----------------------------------------------------------------------------
42544254
_Use_decl_annotations_
4255-
inline void XM_CALLCONV BoundingFrustum::CreateFromMatrix(BoundingFrustum& Out, FXMMATRIX Projection) noexcept
4255+
inline void XM_CALLCONV BoundingFrustum::CreateFromMatrix(BoundingFrustum& Out, FXMMATRIX Projection, bool rhcoords) noexcept
42564256
{
42574257
// Corners of the projection frustum in homogenous space.
42584258
static XMVECTORF32 HomogenousPoints[6] =
@@ -4296,8 +4296,16 @@ inline void XM_CALLCONV BoundingFrustum::CreateFromMatrix(BoundingFrustum& Out,
42964296
Points[4] = XMVectorMultiply(Points[4], XMVectorReciprocal(XMVectorSplatW(Points[4])));
42974297
Points[5] = XMVectorMultiply(Points[5], XMVectorReciprocal(XMVectorSplatW(Points[5])));
42984298

4299-
Out.Near = XMVectorGetZ(Points[4]);
4300-
Out.Far = XMVectorGetZ(Points[5]);
4299+
if (rhcoords)
4300+
{
4301+
Out.Near = XMVectorGetZ(Points[5]);
4302+
Out.Far = XMVectorGetZ(Points[4]);
4303+
}
4304+
else
4305+
{
4306+
Out.Near = XMVectorGetZ(Points[4]);
4307+
Out.Far = XMVectorGetZ(Points[5]);
4308+
}
43014309
}
43024310

43034311

0 commit comments

Comments
 (0)