microsoft / DirectXMath

DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps

Home Page:https://walbourn.github.io/introducing-directxmath/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Building a BoundingFrustum from an orthographic projection has errors

shanehyde opened this issue · comments

When creating a BoundingFrustum from an orthographic projection, the following values are created for the slopes

RightSlope = -0.5
LeftSlope = 0.5
TopSlope = -0.5
BottomSlope = 0.5

The correct values for the slopes for an orthographic projection should all be 0. There is no slope to the planes in an ortho projection.

The error is caused by the assumption that the x/y values will vary from 0 to the provided value over the z range. But, in ortho x/y will not vary over the z range.

If you create a Frustum like this, all collision tests will be wrong, since the wrong planes will be used for testing.

This could be fixed by using all 8 points of the frustum instead of just 4.

At further looking, seems that BoundingFrustum is not really adaptable to ortho, since it doesnt store the plane offsets. Perhaps the documentation should be updated to reflect that it doesnt function with ortho at all.

A Frustum is almost always associated with a perspective projection AFAIK for collision volumes. Wouldn't an orthographic projection just be a bounding box or oriented bounding box?

Fixed in this PR on Microsoft Docs.