Beispiel #1
0
        public Frustum.Intersect Intersects(Cube cube)
        {
            Frustum.Intersect result = Frustum.Intersect.Inside;

            foreach (Plane plane in _Planes)
            {
                if (plane.Distance(cube.GreaterSumVertex(plane.Normal)) < 0f)
                {
                    return(Frustum.Intersect.Outside);
                }
                else if (plane.Distance(cube.LesserSumVertex(plane.Normal)) < 0f)
                {
                    result = Frustum.Intersect.Intersect;
                }
            }

            return(result);
        }
Beispiel #2
0
        public Frustum.Intersect Intersects(Sphere sphere)
        {
            Frustum.Intersect result = Frustum.Intersect.Inside;

            foreach (Plane plane in _Planes)
            {
                float distance = plane.Distance(sphere.Center);

                if (distance < -sphere.Radius)
                {
                    return(Frustum.Intersect.Outside);
                }
                else if (distance < sphere.Radius)
                {
                    result = Frustum.Intersect.Intersect;
                }
            }

            return(result);
        }
Beispiel #3
0
        private static bool CheckClipFrustumOccludeEntity(Entity entity, Span <Plane> planes, Matrix4x4 mvp)
        {
            if (!_ENABLE_FRUSTUM_CULLING || !entity.TryComponent(out OcclusionBounds? bounds))
            {
                return(false);
            }

            ClipFrustum frustum = new ClipFrustum(planes, mvp);

            Frustum.Intersect intersection = Frustum.Intersect.Outside;

            return

                // test spherical bounds
                (((bounds.Spheric != Sphere.Zero) && (intersection = frustum.Intersects(bounds.Spheric)) is Frustum.Intersect.Outside)

                 // if spherical bounds occlusion fails (i.e. intersects) try cubic
                 || (intersection is not Frustum.Intersect.Inside &&
                     (bounds.Cubic != Cube.Zero) &&
                     frustum.Intersects(bounds.Cubic) is Frustum.Intersect.Outside));
        }