Example #1
0
 public static IEnumerable <Volume> NarrowPhase(IConvex3Polytope conv, IEnumerable <Volume> broadphased)
 {
     foreach (var v in broadphased)
     {
         if (v.GetConvexPolyhedron().Intersect(conv))
         {
             yield return(v);
         }
     }
 }
        public static bool Contains(this IConvex3Polytope a, Vector3 point)
        {
            if (!a.WorldBounds().Contains(point))
            {
                return(false);
            }

            foreach (var ax in a.Normals())
            {
                if (ax.sqrMagnitude > E && !Contains(ax, a.Vertices(), point))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #3
0
        public static IEnumerable <Volume> Find(IConvex3Polytope conv,
                                                System.Func <Volume, bool> NarrowFilter, System.Func <Volume, bool> BroadFilter)
        {
            var r = Instance;
            BaseBVHController <Volume> bvh;

            if (r == null || (bvh = r.BVH) == null)
            {
                yield break;
            }

            var bb = conv.WorldBounds();

            foreach (var v in Broadphase(bvh, bb))
            {
                if (BroadFilter(v) && v.GetConvexPolyhedron().Intersect(conv) && NarrowFilter(v))
                {
                    yield return(v);
                }
            }
        }
        public static bool Intersect(this IConvex3Polytope a, IConvex3Polytope b)
        {
            if (!a.WorldBounds().Intersects(b.WorldBounds()))
            {
                return(false);
            }

            foreach (var ax in a.Normals())
            {
                if (ax.sqrMagnitude > E && !Intersect(ax, a.Vertices(), b.Vertices()))
                {
                    return(false);
                }
            }

            foreach (var bx in b.Normals())
            {
                if (bx.sqrMagnitude > E && !Intersect(bx, a.Vertices(), b.Vertices()))
                {
                    return(false);
                }
            }

            foreach (var ae in a.Edges())
            {
                foreach (var be in b.Edges())
                {
                    var cx = Vector3.Cross(ae, be);
                    if (cx.sqrMagnitude > E && !Intersect(cx, a.Vertices(), b.Vertices()))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #5
0
 public static IEnumerable <Volume> Find(IConvex3Polytope conv, System.Func <Volume, bool> NarrowFilter)
 {
     return(Find(conv, NarrowFilter, Pass));
 }
Example #6
0
 public static IEnumerable <Volume> Find(IConvex3Polytope conv)
 {
     return(Find(conv, Pass, Pass));
 }