+ // Now for us to count this actor as hit, we must have also hit
+ // all CLIPPING actors up to this point in the hierarchy as well.
+ // This information is stored in the clippingBitPlaneMask we updated above.
+ // Here we calculate a comparison mask by setting all the bits up to the current depth value.
+ // EG. a depth of 4 (10000 binary) = a mask of 1111 binary.
+ // This allows us a fast way of comparing all bits are set up to this depth.
+ // Note: If the current Actor has clipping, that is included in the depth mask too.
+ uint32_t clippingDepthMask = ( 1u << newClippingDepth ) - 1u;
+
+ // The two masks must be equal to be a hit, as we are already assuming a hit
+ // (for non-clipping mode) then they must be not-equal to disqualify the hit.
+ if( clippingBitPlaneMask != clippingDepthMask )
+ {
+ haveHitActor = false;
+ }
+ }
+
+ if( haveHitActor )
+ {
+ hit.actor = &actor;
+ hit.hitPosition = hitPointLocal;
+ hit.distance = distance;
+ hit.depth = actor.GetSortingDepth() ;
+
+ if( actor.GetRendererCount() > 0 )
+ {
+ //Get renderer with maximum depth
+ int rendererMaxDepth(actor.GetRendererAt( 0 ).Get()->GetDepthIndex());
+ for( uint32_t i(1); i < actor.GetRendererCount(); ++i )
+ {
+ int depth = actor.GetRendererAt( i ).Get()->GetDepthIndex();
+ if( depth > rendererMaxDepth )
+ {
+ rendererMaxDepth = depth;
+ }
+ }
+ hit.depth += rendererMaxDepth;
+ }