Ejemplo n.º 1
0
 /// <summary>
 /// Containment test between this <see cref="BoundingFrustum"/> and specified <see cref="Vector3"/>.
 /// </summary>
 /// <param name="point">A <see cref="Vector3"/> for testing.</param>
 /// <param name="result">Result of testing for containment between this <see cref="BoundingFrustum"/> and specified <see cref="Vector3"/> as an output parameter.</param>
 public void Contains(ref Vector3 point, out ContainmentType result)
 {
     for (var i = 0; i < PlaneCount; ++i)
     {
         // TODO: we might want to inline this for performance reasons
         if (PlaneHelper.ClassifyPoint(ref point, ref this._planes[i]) > 0)
         {
             result = ContainmentType.Disjoint;
             return;
         }
     }
     result = ContainmentType.Contains;
 }
Ejemplo n.º 2
0
        public void Contains(ref BoundingSphere sphere, out ContainmentType result)
        {
            float           val;
            ContainmentType contained;

            // We first check if the sphere is inside the frustum
            this.Contains(ref sphere.Center, out contained);

            // The sphere is inside. Now we need to check if it's fully contained or not
            // So we see if the perpendicular distance to each plane is less than or equal to the sphere's radius.
            // If the perpendicular distance is less, just return Intersects.
            if (contained == ContainmentType.Contains)
            {
                val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.bottom);
                if (val < sphere.Radius)
                {
                    result = ContainmentType.Intersects;
                    return;
                }

                val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.far);
                if (val < sphere.Radius)
                {
                    result = ContainmentType.Intersects;
                    return;
                }

                val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.left);
                if (val < sphere.Radius)
                {
                    result = ContainmentType.Intersects;
                    return;
                }

                val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.near);
                if (val < sphere.Radius)
                {
                    result = ContainmentType.Intersects;
                    return;
                }

                val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.right);
                if (val < sphere.Radius)
                {
                    result = ContainmentType.Intersects;
                    return;
                }

                val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.top);
                if (val < sphere.Radius)
                {
                    result = ContainmentType.Intersects;
                    return;
                }

                // If we get here, the sphere is fully contained
                result = ContainmentType.Contains;
                return;
            }
            //duff idea : test if all corner is in same side of a plane if yes and outside it is disjoint else intersect
            // issue is that we can have some times when really close aabb



            // If we're here, the the sphere's centre was outside of the frustum. This makes things hard :(
            // We can't use perpendicular distance anymore. I'm not sure how to code this.
            throw new NotImplementedException();
        }