Пример #1
0
 public static void Draw(this BoundingFrustumD frustum, Vector4 color, float thickness, MyStringId?material = null)
 {
     Draw(frustum.GetLines(), color, thickness, material);
 }
Пример #2
0
        static ContainmentType ContainsAdv(this MyOrientedBoundingBoxD obb, BoundingFrustumD frust, HashSet <Vector3D> internalPoints, out bool noCorners)
        {
            var points = new Vector3D[8];

            obb.GetCorners(points, 0);
            int inside = 0;

            for (int i = 0; i < points.Length; i++)
            {
                if (frust.Contains(points[i]) != ContainmentType.Disjoint)
                {
                    inside++;
                    internalPoints.Add(points[i]);
                }
            }
            noCorners = false;
            switch (inside)
            {
            case (8):
                return(ContainmentType.Contains);

            default:
                if (internalPoints.Count != 0 || frust.Contains(obb.GetAABB()) != ContainmentType.Disjoint)
                {
                    noCorners = true;
                    var res   = new HashSet <Vector3D>();
                    var lines = frust.GetLines();
                    for (int i = 0; i < lines.Length; i++)
                    {
                        var from = obb.Contains(ref lines[i].From);
                        var to   = obb.Contains(ref lines[i].To);
                        if (from && to)
                        {
                            res.Add(lines[i].From);
                            res.Add(lines[i].To);
                        }
                        else if (from)
                        {
                            res.Add(lines[i].From);
                            res.Add(lines[i].GetPoint(obb.Intersects(ref lines[i]).Value));
                        }
                        else if (to)
                        {
                            res.Add(lines[i].To);
                            var back = lines[i].Reverse();
                            res.Add(back.GetPoint(obb.Intersects(ref back).Value));
                        }
                        else
                        {
                            var first  = obb.Intersects(ref lines[i]);
                            var back   = lines[i].Reverse();
                            var second = obb.Intersects(ref back);
                            if (first != null)
                            {
                                res.Add(lines[i].GetPoint(first.Value));
                            }
                            if (second != null)
                            {
                                res.Add(back.GetPoint(second.Value));
                            }
                        }
                    }
                    lines = obb.GetLines();
                    for (int i = 0; i < lines.Length; i++)
                    {
                        var from = frust.Contains(lines[i].From) != ContainmentType.Disjoint;
                        var to   = frust.Contains(lines[i].To) != ContainmentType.Disjoint;
                        if (from && to)
                        {
                            res.Add(lines[i].From);
                            res.Add(lines[i].To);
                        }
                        else if (from)
                        {
                            res.Add(lines[i].From);
                            res.Add(lines[i].GetPoint(frust.Intersects(lines[i].ToRay()).Value));
                        }
                        else if (to)
                        {
                            res.Add(lines[i].To);
                            res.Add(lines[i].Reverse().GetPoint(frust.Intersects(lines[i].ToReversedRay()).Value));
                        }
                        else
                        {
                            var first  = frust.Intersects(lines[i].ToRay());
                            var second = frust.Intersects(lines[i].ToReversedRay());
                            if (first != null)
                            {
                                res.Add(lines[i].GetPoint(first.Value));
                            }
                            if (second != null)
                            {
                                res.Add(lines[i].Reverse().GetPoint(second.Value));
                            }
                        }
                    }

                    foreach (var r in res)
                    {
                        internalPoints.Add(r);
                    }
                    if (internalPoints.Count > 0)
                    {
                        return(ContainmentType.Intersects);
                    }
                }
                return(ContainmentType.Disjoint);
            }
        }