コード例 #1
0
        public void Intersects(AABox box, out bool result)
        {
            if ((Max.X >= box.Min.X) && (Min.X <= box.Max.X))
            {
                if ((Max.Y < box.Min.Y) || (Min.Y > box.Max.Y))
                {
                    result = false;
                    return;
                }

                result = (Max.Z >= box.Min.Z) && (Min.Z <= box.Max.Z);
                return;
            }

            result = false;
            return;
        }
コード例 #2
0
ファイル: LinqUtil.cs プロジェクト: dmk-rib/Open.Vim.Sdk
 public static AABox ToAABox(this IEnumerable <Vector3> self)
 => AABox.Create(self);
コード例 #3
0
 /// <summary>
 /// Gets whether or not a specified <see cref="AABox"/> intersects with this sphere.
 /// </summary>
 public bool Intersects(AABox box)
 {
     return(box.Intersects(this));
 }
コード例 #4
0
        public float?Intersects(AABox box)
        {
            const float Epsilon = 1e-6f;

            float?tMin = null, tMax = null;

            if (Math.Abs(Direction.X) < Epsilon)
            {
                if (Position.X < box.Min.X || Position.X > box.Max.X)
                {
                    return(null);
                }
            }
            else
            {
                tMin = (box.Min.X - Position.X) / Direction.X;
                tMax = (box.Max.X - Position.X) / Direction.X;

                if (tMin > tMax)
                {
                    var temp = tMin;
                    tMin = tMax;
                    tMax = temp;
                }
            }

            if (Math.Abs(Direction.Y) < Epsilon)
            {
                if (Position.Y < box.Min.Y || Position.Y > box.Max.Y)
                {
                    return(null);
                }
            }
            else
            {
                var tMinY = (box.Min.Y - Position.Y) / Direction.Y;
                var tMaxY = (box.Max.Y - Position.Y) / Direction.Y;

                if (tMinY > tMaxY)
                {
                    var temp = tMinY;
                    tMinY = tMaxY;
                    tMaxY = temp;
                }

                if ((tMin.HasValue && tMin > tMaxY) || (tMax.HasValue && tMinY > tMax))
                {
                    return(null);
                }

                if (!tMin.HasValue || tMinY > tMin)
                {
                    tMin = tMinY;
                }
                if (!tMax.HasValue || tMaxY < tMax)
                {
                    tMax = tMaxY;
                }
            }

            if (Math.Abs(Direction.Z) < Epsilon)
            {
                if (Position.Z < box.Min.Z || Position.Z > box.Max.Z)
                {
                    return(null);
                }
            }
            else
            {
                var tMinZ = (box.Min.Z - Position.Z) / Direction.Z;
                var tMaxZ = (box.Max.Z - Position.Z) / Direction.Z;

                if (tMinZ > tMaxZ)
                {
                    var temp = tMinZ;
                    tMinZ = tMaxZ;
                    tMaxZ = temp;
                }

                if ((tMin.HasValue && tMin > tMaxZ) || (tMax.HasValue && tMinZ > tMax))
                {
                    return(null);
                }

                if (!tMin.HasValue || tMinZ > tMin)
                {
                    tMin = tMinZ;
                }
                if (!tMax.HasValue || tMaxZ < tMax)
                {
                    tMax = tMaxZ;
                }
            }

            // having a positive tMin and a negative tMax means the ray is inside the box
            // we expect the intesection distance to be 0 in that case
            if (tMin.HasValue && tMin < 0 && tMax > 0)
            {
                return(0);
            }

            // a negative tMin means that the intersection point is behind the ray's origin
            // we discard these as not hitting the AABB
            if (tMin < 0)
            {
                return(null);
            }

            return(tMin);
        }
コード例 #5
0
 public static AABox ToBox(this IEnumerable <Vector3> points)
 => AABox.Create(points);
コード例 #6
0
 public AABox Merge(AABox box)
 => new AABox(Min.Min(box.Min), Max.Max(box.Max));
コード例 #7
0
 public bool Intersects(AABox box)
 {
     Intersects(box, out var result);
     return(result);
 }