Commit 9ef13c43 authored by Frédéric Larue's avatar Frédéric Larue

Ray/Box intersection test modified so as to manage the case where the ray origin is inside the box.

parent 77baeea2
......@@ -12,6 +12,7 @@
#include <QVector2D>
#include <QVector3D>
#include <limits>
......@@ -651,6 +652,24 @@ inline bool Box3f::Intersects( const QVector3D& rayOrigin,
// points, but only the farthest positive one may correspond to the real ray/cube intersection, if it exists.
int intersectionPlaneId = -1;
if( Contains(rayOrigin) )
{
intersectionDist = std::numeric_limits<float>::max();
for( int i=0; i<3; ++i )
{
float frontFacingPlane = (rayDirection[i] > 0.0f)? m_Max[i] : m_Min[i];
float t = (frontFacingPlane - rayOrigin[i]) / rayDirection[i];
if( t < intersectionDist )
{
intersectionDist = t;
intersectionPlaneId = i;
}
}
}
else
{
intersectionDist = 0.0f;
for( int i=0; i<3; ++i )
......@@ -663,6 +682,7 @@ inline bool Box3f::Intersects( const QVector3D& rayOrigin,
intersectionPlaneId = i;
}
}
}
if( intersectionPlaneId < 0 )
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment