+ if(actor.IsOverlay())
+ {
+ overlayHit = true;
+ }
+
+ // At this point we have hit an actor.
+ // Now perform checks for clipping.
+ // Assume we have hit the actor first as if it is not clipped this would be the case.
+ bool haveHitActor = true;
+
+ // Check if we are performing clipping. IE. if any actors so far have clipping enabled - not necessarily this one.
+ // We can do this by checking the clipping depth has a value 1 or above.
+ if(newClippingDepth >= 1u)
+ {
+ // 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;
+ }
+ }