public override PCZone UpdateNodeHomeZone( PCZSceneNode pczsn, bool allowBackTouches )
{
// default to newHomeZone being the current home zone
PCZone newHomeZone = pczsn.HomeZone;
// Check all portals of the start zone for crossings!
foreach ( Portal portal in mPortals )
{
PortalIntersectResult pir = portal.intersects( pczsn );
switch ( pir )
{
default:
case PortalIntersectResult.NO_INTERSECT: // node does not intersect portal - do nothing
case PortalIntersectResult.INTERSECT_NO_CROSS:// node intersects but does not cross portal - do nothing
break;
case PortalIntersectResult.INTERSECT_BACK_NO_CROSS:// node intersects but on the back of the portal
if ( allowBackTouches )
{
// node is on wrong side of the portal - fix if we're allowing backside touches
if ( portal.getTargetZone() != this &&
portal.getTargetZone() != pczsn.HomeZone )
{
// set the home zone of the node to the target zone of the portal
pczsn.HomeZone = portal.getTargetZone();
// continue checking for portal crossings in the new zone
newHomeZone = portal.getTargetZone().UpdateNodeHomeZone( pczsn, false );
}
}
break;
case PortalIntersectResult.INTERSECT_CROSS:
// node intersects and crosses the portal - recurse into that zone as new home zone
if ( portal.getTargetZone() != this &&
portal.getTargetZone() != pczsn.HomeZone )
{
// set the home zone of the node to the target zone of the portal
pczsn.HomeZone = portal.getTargetZone();
// continue checking for portal crossings in the new zone
newHomeZone = portal.getTargetZone().UpdateNodeHomeZone( pczsn, true );
}
break;
}
}
// return the new home zone
return newHomeZone;
}