-------------------------------------------------------------------------------------- Description: A ray AABB intersection check. Arguments: minBounds, maxBounds - The min/max bounds of the AABB rayOrigin, rayDir - The ray origin and direction (normalized) intersection - The intersection point if there is any Return Value: false if ray does not intersect AABB true if ray may intersect AABB ------
| 354 | // true if ray may intersect AABB |
| 355 | // -------------------------------------------------------------------------------------- |
| 356 | bool IntersectAxisAlignedBoxRay( const Vector3& minBounds, const Vector3& maxBounds, const Vector3& rayOrigin, const Vector3& rayDir, Vector3& intersection ) |
| 357 | { |
| 358 | if( minBounds == maxBounds ) |
| 359 | { |
| 360 | // we are actually dealing with a point but not a box |
| 361 | intersection = minBounds; |
| 362 | return LengthSq( Normalize( minBounds - rayOrigin ) - rayDir ) < 1e10; |
| 363 | } |
| 364 | |
| 365 | XMVECTOR minA = XMVectorSet( minBounds.x, minBounds.y, minBounds.z, 0.0f ); |
| 366 | XMVECTOR maxA = XMVectorSet( maxBounds.x, maxBounds.y, maxBounds.z, 0.0f ); |
| 367 | |
| 368 | XMVECTOR invRayDir = XMVectorReciprocal( rayDir ); |
| 369 | |
| 370 | XMVECTOR t0 = ( minA - rayOrigin ) * invRayDir; |
| 371 | XMVECTOR t1 = ( maxA - rayOrigin ) * invRayDir; |
| 372 | |
| 373 | XMVECTOR smallerIntersection = XMVectorMin( t0, t1 ); |
| 374 | XMVECTOR biggerIntersection = XMVectorMax( t0, t1 ); |
| 375 | |
| 376 | float minT = max( XMVectorGetX( smallerIntersection ), max( XMVectorGetY( smallerIntersection ), XMVectorGetZ( smallerIntersection ) ) ); |
| 377 | float maxT = min( XMVectorGetX( biggerIntersection ), min( XMVectorGetY( biggerIntersection ), XMVectorGetZ( biggerIntersection ) ) ); |
| 378 | |
| 379 | intersection = rayOrigin + minT * rayDir; |
| 380 | return minT < maxT; |
| 381 | } |
| 382 | |
| 383 | bool IntersectOrientedBoxAxisAlignedBox( const Vector3& centerA, const Vector3& extentsA, const Quaternion& orientationA, const Vector3& minBounds, const Vector3& maxBounds ) |
| 384 | { |
no test coverage detected