예제 #1
0
        public static List <V3d> ComputeCorners(this Hull3d hull)
        {
            List <V3d> Corners = new List <V3d>();
            int        count   = hull.PlaneArray.Length;

            for (int i0 = 0; i0 < count; i0++)
            {
                for (int i1 = 0; i1 < count; i1++)
                {
                    for (int i2 = 0; i2 < count; i2++)
                    {
                        if (i0 != i1 && i1 != i2 && i0 != i2)
                        {
                            V3d temp;
                            if (hull.PlaneArray[0].Intersects(hull.PlaneArray[i1], hull.PlaneArray[i2], out temp))
                            {
                                if (!temp.IsNaN && !temp.AnyInfinity)
                                {
                                    Corners.Add(temp);
                                }
                            }
                        }
                    }
                }
            }

            return(Corners);
        }
예제 #2
0
        /// <summary>
        /// Builds a hull from the given view-projection transformation (left, right, top, bottom, near, far).
        /// The normals of the hull planes point to the inside.
        /// A point inside the visual hull will have positive height to all planes.
        /// </summary>
        public static Hull3d GetVisualHull(this Trafo3d vpTrafo)
        {
            var frustumCorners = new Box3d(-V3d.IIO, V3d.III).ComputeCorners();

            //Min,                             0 near left bottom
            //new V3d(Max.X, Min.Y, Min.Z),    1 near right bottom
            //new V3d(Min.X, Max.Y, Min.Z),    2 near left top
            //new V3d(Max.X, Max.Y, Min.Z),    3 near right top
            //new V3d(Min.X, Min.Y, Max.Z),    4 far left bottom
            //new V3d(Max.X, Min.Y, Max.Z),    5 far right bottom
            //new V3d(Min.X, Max.Y, Max.Z),    6 far left top
            //Max                              7 far right top

            // use inverse view-projection to get vertices in world space
            frustumCorners.Apply(c => vpTrafo.Backward.TransformPosProj(c));

            // hull planes should point inward, assume right-handed transformation to build planes
            var hull = new Hull3d(new[]
            {
                new Plane3d(frustumCorners[0], frustumCorners[4], frustumCorners[2]), // left
                new Plane3d(frustumCorners[1], frustumCorners[3], frustumCorners[5]), // right
                new Plane3d(frustumCorners[2], frustumCorners[6], frustumCorners[3]), // top
                new Plane3d(frustumCorners[0], frustumCorners[1], frustumCorners[4]), // bottom
                new Plane3d(frustumCorners[0], frustumCorners[2], frustumCorners[1]), // near
                new Plane3d(frustumCorners[4], frustumCorners[5], frustumCorners[6]), // far
            });

            return(hull);
        }
예제 #3
0
        public void TransformInto(Trafo3d trafo, ref Hull3d hull)
        {
            int count = PlaneCount;
            var invTr = trafo.Backward.Transposed;

            for (int i = 0; i < count; i++)
            {
                hull.PlaneArray[i]
                    = new Plane3d(
                          invTr.TransformDir(PlaneArray[i].Normal).Normalized,
                          trafo.Forward.TransformPos(PlaneArray[i].Point));
            }
        }
예제 #4
0
        public Hull3d Transformed(Trafo3d trafo)
        {
            int count = PlaneCount;
            var hull  = new Hull3d(count);
            var invTr = trafo.Backward.Transposed;

            for (int i = 0; i < count; i++)
            {
                hull.PlaneArray[i]
                    = new Plane3d(
                          invTr.TransformDir(PlaneArray[i].Normal).Normalized,
                          trafo.Forward.TransformPos(PlaneArray[i].Point));
            }
            return(hull);
        }
예제 #5
0
        /// <summary>
        /// Returns unordered set of corners of this hull.
        /// </summary>
        public static HashSet <V3d> ComputeCorners(this Hull3d hull)
        {
            var corners = new HashSet <V3d>();
            int count   = hull.PlaneArray.Length;

            for (var i0 = 0; i0 < count; i0++)
            {
                for (var i1 = i0 + 1; i1 < count; i1++)
                {
                    for (var i2 = i1 + 1; i2 < count; i2++)
                    {
                        if (hull.PlaneArray[i0].Intersects(hull.PlaneArray[i1], hull.PlaneArray[i2], out V3d temp))
                        {
                            if (temp.IsNaN || temp.AnyInfinity)
                            {
                                continue;
                            }

                            var inside = true;
                            for (var j = 0; j < count; j++)
                            {
                                if (j == i0 || j == i1 || j == i2)
                                {
                                    continue;
                                }
                                var h = hull.PlaneArray[j].Height(temp);
                                if (h > 0)
                                {
                                    inside = false; break;
                                }
                            }

                            if (inside)
                            {
                                corners.Add(temp);
                            }
                        }
                    }
                }
            }

            return(corners);
        }
예제 #6
0
 public FastHull3d(Hull3d hull)
 {
     Hull = hull;
     MinCornerIndexArray = ComputeMinCornerIndexArray(Hull.PlaneArray);
 }
예제 #7
0
 public FastHull3d(FastHull3d fastHull)
 {
     Hull = new Hull3d(fastHull.Hull);
     MinCornerIndexArray = fastHull.MinCornerIndexArray.Copy();
 }
예제 #8
0
 /// <summary>
 /// Create an empty FastHull3d with count planes.
 /// </summary>
 public FastHull3d(int count)
 {
     Hull = new Hull3d(count);
     MinCornerIndexArray = new int[count];
 }
예제 #9
0
 public Hull3d(Hull3d hull)
 {
     PlaneArray = hull.PlaneArray.Copy();
 }