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>
......@@ -54,7 +55,7 @@ public:
inline iterator begin() { return &xy; }
inline const_iterator begin() const { return &xy; }
inline iterator end() { return (&XY)+1; }
inline const_iterator end() const { return (&XY)+1; }
inline const_iterator end() const { return (&XY)+1; }
};
......@@ -651,16 +652,35 @@ 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;
intersectionDist = 0.0f;
for( int i=0; i<3; ++i )
if( Contains(rayOrigin) )
{
float frontFacingPlane = (rayDirection[i] > 0.0f)? m_Min[i] : m_Max[i];
float t = (frontFacingPlane - rayOrigin[i]) / rayDirection[i];
if( t > intersectionDist )
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 )
{
intersectionDist = t;
intersectionPlaneId = i;
float frontFacingPlane = (rayDirection[i] > 0.0f)? m_Min[i] : m_Max[i];
float t = (frontFacingPlane - rayOrigin[i]) / rayDirection[i];
if( t > intersectionDist )
{
intersectionDist = t;
intersectionPlaneId = i;
}
}
}
......
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