Exemple #1
0
        // Check if a portal intersects a plane bounded volume
        // NOTE: This check is not exact.
        // NOTE: UNTESTED as of 5/30/07 (EC)
        public bool intersects(PlaneBoundedVolume pbv)
        {
            // Only check if portal is open
            if (this.mOpen)
            {
                switch (this.mType)
                {
                case PORTAL_TYPE.PORTAL_TYPE_QUAD:
                {
                    // first check sphere of the portal
                    if (!pbv.Intersects(this.mDerivedSphere))
                    {
                        return(false);
                    }
                    // if the portal corners are all outside one of the planes of the pbv,
                    // then the portal does not intersect the pbv. (this can result in
                    // some false positives, but it's the best I can do for now)
                    foreach (Plane plane in pbv.planes)
                    {
                        bool allOutside = true;
                        for (int i = 0; i < 4; i++)
                        {
                            if (plane.GetSide(this.mDerivedCorners[i]) != pbv.outside)
                            {
                                allOutside = false;
                            }
                        }
                        if (allOutside)
                        {
                            return(false);
                        }
                    }
                }
                break;

                case PORTAL_TYPE.PORTAL_TYPE_AABB:
                {
                    var aabb = new AxisAlignedBox(this.mDerivedCorners[0], this.mDerivedCorners[1]);
                    if (!pbv.Intersects(aabb))
                    {
                        return(false);
                    }
                }
                break;

                case PORTAL_TYPE.PORTAL_TYPE_SPHERE:
                    if (!pbv.Intersects(this.mDerivedSphere))
                    {
                        return(false);
                    }
                    break;
                }
            }
            return(false);
        }
Exemple #2
0
        public override void FindNodes(PlaneBoundedVolume t, ref List <PCZSceneNode> list, List <Portal> visitedPortals,
                                       bool includeVisitors, bool recurseThruPortals, PCZSceneNode exclude)
        {
            // if this zone has an enclosure, check against the enclosure AABB first
            if (null != mEnclosureNode)
            {
                if (!t.Intersects(mEnclosureNode.WorldAABB))
                {
                    // AABB of zone does not intersect t, just return.
                    return;
                }
            }

            // use the Octree to more efficiently find nodes intersecting the plane bounded volume
            this.rootOctree._findNodes(t, ref list, exclude, includeVisitors, false);

            // if asked to, recurse through portals
            if (recurseThruPortals)
            {
                foreach (Portal portal in mPortals)
                {
                    // check portal versus boundign box
                    if (portal.intersects(t))
                    {
                        // make sure portal hasn't already been recursed through

                        if (!visitedPortals.Contains(portal))
                        {
                            // save portal to the visitedPortals list
                            visitedPortals.Add(portal);
                            // recurse into the connected zone
                            portal.getTargetZone().FindNodes(t, ref list, visitedPortals, includeVisitors, recurseThruPortals, exclude);
                        }
                    }
                }
            }
        }
Exemple #3
0
        public override void FindNodes(PlaneBoundedVolume t, ref List <PCZSceneNode> list, List <Portal> visitedPortals,
                                       bool includeVisitors, bool recurseThruPortals, PCZSceneNode exclude)
        {
            // if this zone has an enclosure, check against the enclosure AABB first
            if (null != mEnclosureNode)
            {
                if (!t.Intersects(mEnclosureNode.WorldAABB))
                {
                    // AABB of zone does not intersect t, just return.
                    return;
                }
            }

            // check nodes at home in this zone
            foreach (PCZSceneNode pczsn in mHomeNodeList)
            {
                if (pczsn != exclude)
                {
                    // make sure node is not already in the list (might have been added in another
                    // zone it was visiting)
                    if (!list.Contains(pczsn))
                    {
                        bool nsect = t.Intersects(pczsn.WorldAABB);
                        if (nsect)
                        {
                            list.Add(pczsn);
                        }
                    }
                }
            }

            if (includeVisitors)
            {
                // check visitor nodes
                foreach (PCZSceneNode pczsn in mVisitorNodeList)
                {
                    if (pczsn != exclude)
                    {
                        // make sure node is not already in the list (might have been added in another
                        // zone it was visiting)
                        if (!list.Contains(pczsn))
                        {
                            bool nsect = t.Intersects(pczsn.WorldAABB);
                            if (nsect)
                            {
                                list.Add(pczsn);
                            }
                        }
                    }
                }
            }

            // if asked to, recurse through portals
            if (recurseThruPortals)
            {
                foreach (Portal portal in mPortals)
                {
                    // check portal versus boundign box
                    if (portal.intersects(t))
                    {
                        // make sure portal hasn't already been recursed through
                        if (!visitedPortals.Contains(portal))
                        {
                            // save portal to the visitedPortals list
                            visitedPortals.Add(portal);
                            // recurse into the connected zone
                            portal.getTargetZone().FindNodes(t, ref list, visitedPortals, includeVisitors, recurseThruPortals, exclude);
                        }
                    }
                }
            }
        }