// check if portal is close to another portal.
// Note, both portals are assumed to be stationary
// and DerivedCP is the current position.
// this function is INTENTIONALLY NOT EXACT because
// it is used by PCZSM::connectPortalsToTargetZonesByLocation
// which is a utility function to link up nearby portals
//
public bool closeTo(Portal otherPortal)
{
// only portals of the same type can be "close to" each other.
if (this.mType != otherPortal.Type)
{
return(false);
}
bool close = false;
switch (this.mType)
{
default:
case PORTAL_TYPE.PORTAL_TYPE_QUAD:
{
// quad portals must be within 1/4 sphere of each other
Sphere quarterSphere1 = this.mDerivedSphere;
quarterSphere1.Radius = quarterSphere1.Radius * 0.25f;
Sphere quarterSphere2 = otherPortal.getDerivedSphere();
quarterSphere2.Radius = quarterSphere2.Radius * 0.25f;
close = quarterSphere1.Intersects(quarterSphere2);
}
break;
case PORTAL_TYPE.PORTAL_TYPE_AABB:
// NOTE: AABB's must match perfectly
if (this.mDerivedCP == otherPortal.getDerivedCP() && this.mCorners[0] == otherPortal.getCorner(0) &&
this.mCorners[1] == otherPortal.getCorner(1))
{
close = true;
}
break;
case PORTAL_TYPE.PORTAL_TYPE_SPHERE:
// NOTE: Spheres must match perfectly
if (this.mDerivedCP == otherPortal.getDerivedCP() && this.mRadius == otherPortal.getRadius())
{
close = true;
}
break;
}
return(close);
}