kicad/3d-viewer/3d_rendering/raytracing/shapes3D/bbox_3d_ray.cpp

881 lines
28 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file bbox_3d_ray.cpp
* @brief 3D bounding box ray intersection tests.
*/
#include "bbox_3d.h"
#include "../ray.h"
#include <wx/debug.h>
// This BBOX Ray intersection test have the following credits:
// "This source code accompanies the Journal of Graphics Tools paper:
//
// "Fast Ray / Axis-Aligned Bounding Box Overlap Tests using Ray Slopes"
// by Martin Eisemann, Thorsten Grosch, Stefan Müller and Marcus Magnor
// Computer Graphics Lab, TU Braunschweig, Germany and
// University of Koblenz-Landau, Germany
//
// This source code is public domain, but please mention us if you use it."
bool BBOX_3D::Intersect( const RAY& aRay, float* t ) const
{
switch( aRay.m_Classification )
{
case RAY_CLASSIFICATION::MMM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0 )
|| ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0 )
|| ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0 ) )
return false;
// compute the intersection distance
2020-12-11 13:51:42 +00:00
*t = ( m_max.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_max.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
2020-12-11 13:51:42 +00:00
float t2 = ( m_max.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::MMP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0 )
|| ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0 )
|| ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_max.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
2020-12-11 13:51:42 +00:00
float t2 = ( m_min.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::MPM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0 )
|| ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0 )
|| ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_min.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
2020-12-11 13:51:42 +00:00
float t2 = ( m_max.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::MPP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0 )
|| ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0 )
|| ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_min.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
2020-12-11 13:51:42 +00:00
float t2 = ( m_min.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::PMM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0 )
|| ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0 )
|| ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_max.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
2020-12-11 13:51:42 +00:00
float t2 = ( m_max.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::PMP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0 )
|| ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0 )
|| ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_max.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
2020-12-11 13:51:42 +00:00
float t2 = ( m_min.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::PPM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0 )
|| ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0 )
|| ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_min.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
2020-12-11 13:51:42 +00:00
float t2 = ( m_max.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::PPP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0 )
|| ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0 )
|| ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_min.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
2020-12-11 13:51:42 +00:00
float t2 = ( m_min.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::OMM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
|| ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
2020-12-11 13:51:42 +00:00
float t2 = ( m_max.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::OMP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
|| ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
2020-12-11 13:51:42 +00:00
float t2 = ( m_min.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::OPM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
|| ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
2020-12-11 13:51:42 +00:00
float t2 = ( m_max.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::OPP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
|| ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
2020-12-11 13:51:42 +00:00
float t2 = ( m_min.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::MOM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t2 = ( m_max.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::MOP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t2 = ( m_min.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::POM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t2 = ( m_max.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::POP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t2 = ( m_min.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( t2 > *t )
*t = t2;
return true;
}
case RAY_CLASSIFICATION::MMO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_max.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
return true;
}
case RAY_CLASSIFICATION::MPO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_min.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
return true;
}
case RAY_CLASSIFICATION::PMO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_max.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
return true;
}
case RAY_CLASSIFICATION::PPO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0 ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
2020-12-11 13:51:42 +00:00
float t1 = ( m_min.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
if( t1 > *t )
*t = t1;
return true;
}
case RAY_CLASSIFICATION::MOO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.m_Origin.z > m_max.z ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
return true;
}
case RAY_CLASSIFICATION::POO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.m_Origin.z > m_max.z ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
return true;
}
case RAY_CLASSIFICATION::OMO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.x < m_min.x )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.m_Origin.z > m_max.z ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
return true;
}
case RAY_CLASSIFICATION::OPO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.x < m_min.x )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.m_Origin.z > m_max.z ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
return true;
}
case RAY_CLASSIFICATION::OOM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.x < m_min.x )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.y > m_max.y ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_max.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
return true;
}
case RAY_CLASSIFICATION::OOP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z > m_max.z ) || ( aRay.m_Origin.x < m_min.x )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.y > m_max.y ) )
return false;
2020-12-11 13:51:42 +00:00
*t = ( m_min.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
return true;
}
}
return false;
}
bool BBOX_3D::Intersect( const RAY& aRay ) const
{
switch( aRay.m_Classification )
{
case RAY_CLASSIFICATION::MMM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0 )
|| ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0 )
|| ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::MMP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0 )
|| ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0 )
|| ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::MPM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0 )
|| ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0 )
|| ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::MPP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0 )
|| ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0 )
|| ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::PMM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0 )
|| ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0 )
|| ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::PMP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0 )
|| ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0 )
|| ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::PPM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0 )
|| ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0 )
|| ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::PPP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0 )
|| ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0 )
|| ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::OMM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
|| ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::OMP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
|| ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0 )
|| ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::OPM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
|| ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::OPP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
|| ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0 )
|| ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::MOM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::MOP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::POM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0 )
|| ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::POP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0 )
|| ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::MMO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::MPO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::PMO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0 )
|| ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::PPO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y > m_max.y )
|| ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0 )
|| ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0 ) )
return false;
return true;
}
case RAY_CLASSIFICATION::MOO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.m_Origin.z > m_max.z ) )
return false;
return true;
}
case RAY_CLASSIFICATION::POO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.m_Origin.z > m_max.z ) )
return false;
return true;
}
case RAY_CLASSIFICATION::OMO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.x < m_min.x )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.m_Origin.z > m_max.z ) )
return false;
return true;
}
case RAY_CLASSIFICATION::OPO:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.x < m_min.x )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z < m_min.z )
|| ( aRay.m_Origin.z > m_max.z ) )
return false;
return true;
}
case RAY_CLASSIFICATION::OOM:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.x < m_min.x )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.y > m_max.y ) )
return false;
return true;
}
case RAY_CLASSIFICATION::OOP:
{
2020-12-11 13:51:42 +00:00
if( ( aRay.m_Origin.z > m_max.z ) || ( aRay.m_Origin.x < m_min.x )
|| ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
|| ( aRay.m_Origin.y > m_max.y ) )
return false;
return true;
}
}
return false;
}