friend FORCEINLINE boolIntersect(const FBoxCenterAndExtent& A, const FBoxCenterAndExtent& B) { // CenterDifference is the vector between the centers of the bounding boxes. const VectorRegister CenterDifference = VectorAbs(VectorSubtract(VectorLoadAligned(&A.Center), VectorLoadAligned(&B.Center)));
// CompositeExtent is the extent of the bounding box which is the convolution of A with B. const VectorRegister CompositeExtent = VectorAdd(VectorLoadAligned(&A.Extent), VectorLoadAligned(&B.Extent));
// For each axis, the boxes intersect on that axis if the projected distance between their centers is less than the sum of their // extents. If the boxes don't intersect on any of the axes, they don't intersect. returnVectorAnyGreaterThan(CenterDifference, CompositeExtent) == false; }
/** Initialized the reference with a child index. */ FOctreeChildNodeRef(int8 InIndex = 0) : Index(InIndex) { checkSlow(Index < 8); }
/** Advances the reference to the next child node. If this was the last node remain, Index will be 8 which represents null. */ FORCEINLINE voidAdvance() { ++Index; }
/** @return true if the reference isn't set. */ FORCEINLINE boolIsNULL()const { return Index >= 8; }
// Load the query bounding box values as VectorRegisters. const VectorRegister QueryBoundsCenter = VectorLoadAligned(&QueryBounds.Center); const VectorRegister QueryBoundsExtent = VectorLoadAligned(&QueryBounds.Extent);
// Compute the bounds of the node's children. const VectorRegister BoundsCenter = VectorLoadAligned(&Bounds.Center); const VectorRegister ChildCenterOffsetVector = VectorLoadFloat1(&ChildCenterOffset); const VectorRegister NegativeCenterDifference = VectorSubtract(QueryBoundsCenter,VectorSubtract(BoundsCenter,ChildCenterOffsetVector)); const VectorRegister PositiveCenterDifference = VectorSubtract(VectorAdd(BoundsCenter,ChildCenterOffsetVector),QueryBoundsCenter);
// If the query bounds isn't entirely inside the bounding box of the child it's closest to, it's not contained by any of the child nodes. const VectorRegister MinDifference = VectorMin(PositiveCenterDifference,NegativeCenterDifference); if(VectorAnyGreaterThan(VectorAdd(QueryBoundsExtent,MinDifference),VectorLoadFloat1(&ChildExtent))) { Result.SetNULL(); } else { // Return the child node that the query is closest to as the containing child. Result.Index = VectorMaskBits(VectorCompareGT(QueryBoundsCenter, BoundsCenter)) & 0x7; }