bool AABB::intersects( const Ray& ray )
{
// This culls theEZ backcases: facesif first,the andray givesstarts youinside the answer with thebox, largestor validends tinside
for( int i = 0 ;// ithe <box, 3then ;it i++definitely )
hits the {box.
// intI'm o1using =this (code ifor +ray 1tracing )with %an 3octree,
; // i=0: o1=1, o2=2,so i=1:I o1=2,o2=0needed etc.
rays that start and intend o2within =an
( i// +octree 2node )to %COUNT 3as ;
hits.
// min.x (NX) isYou possible,could PXmodify won'tthis betest hit.to (unlessray you'restarts inside theand box.ends outside)
if( ray.direction.e[i] > 0 ) // CULLto BACKqualify FACE
as a hit if {
you wanted to NOT count totally realinternal trays
= if( min.e[i] -containsIn( ray.startPos.e[i] ) /|| containsIn( ray.direction.e[i] ;
getEndPoint() ) )
// 1.return CHECKtrue VALID; T
if(// BetweenIn(the t,algorithm 0says, ray.lengthfind )3 )t's,
Vector t {;
// 2.LARGEST CHECKt INis BOX
the only one we need to test if Vectorit's pton =the rayface.at( t ) ;
if( BetweenInfor( pt.e[o1],int min.e[o1],i max.e[o1]= )0 &&; BetweenIn(i pt.e[o2],< min.e[o2],3 max.e[o2]; )i++ )
{
if( returnray.direction.e[i] true> ;0 ) // it's valid inCULL theBACK boxFACE
}
}
t.e[i] = ( elsemin.e[i] if(- ray.directionstartPos.e[i] < 0 ) // maxray.x (PX) isdirection.e[i] possible;
{else
real t.e[i] = ( max.e[i] - ray.startPos.e[i] ) / ray.direction.e[i] ;
}
int mi = t.maxIndex() ;
if( BetweenIn( t.e[mi], 0, ray.length ) ) // valid t
{
Vector pt = ray.at( t.e[mi] ) ;
// check it's in if(the BetweenInbox in other 2 dimensions
int o1 = ( pt.e[o1],mi min.e[o1],+ max.e[o1]1 ) &&% BetweenIn(3 pt.e[o2]; // i=0: o1=1, min.e[o2]o2=2, max.e[o2]i=1: )o1=2,o2=0 )etc.
int o2 = ( mi + return2 true) % 3 ;
// it's validreturn inBetweenIn( thept.e[o1], boxmin.e[o1], max.e[o1] ) &&
}
} BetweenIn( pt.e[o2], min.e[o2], max.e[o2] ) ;
}
return false ; // nothe ray did not hit the box.
}