microsoft / DirectXMath

DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps
https://walbourn.github.io/introducing-directxmath/
MIT License
1.54k stars 238 forks source link

Building a BoundingFrustum from an orthographic projection has errors #123

Closed shanehyde closed 3 years ago

shanehyde commented 3 years ago

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.

shanehyde commented 3 years ago

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.

walbourn commented 3 years ago

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?

walbourn commented 3 years ago

Fixed in this PR on Microsoft Docs.