Example #1
0
        public bool Intersects(BoundingBoxXna boxXna)
        {
            var result = false;

            this.Intersects(ref boxXna, out result);
            return(result);
        }
Example #2
0
        public ContainmentType Contains(BoundingBoxXna boxXna)
        {
            //check if all corner is in sphere
            bool inside = true;

            foreach (Vector3 corner in boxXna.GetCorners())
            {
                if (this.Contains(corner) == ContainmentType.Disjoint)
                {
                    inside = false;
                    break;
                }
            }

            if (inside)
            {
                return(ContainmentType.Contains);
            }

            //check if the distance from sphere center to cube face < radius
            double dmin = 0;

            if (Center.X < boxXna.Min.X)
            {
                dmin += (Center.X - boxXna.Min.X) * (Center.X - boxXna.Min.X);
            }

            else if (Center.X > boxXna.Max.X)
            {
                dmin += (Center.X - boxXna.Max.X) * (Center.X - boxXna.Max.X);
            }

            if (Center.Y < boxXna.Min.Y)
            {
                dmin += (Center.Y - boxXna.Min.Y) * (Center.Y - boxXna.Min.Y);
            }

            else if (Center.Y > boxXna.Max.Y)
            {
                dmin += (Center.Y - boxXna.Max.Y) * (Center.Y - boxXna.Max.Y);
            }

            if (Center.Z < boxXna.Min.Z)
            {
                dmin += (Center.Z - boxXna.Min.Z) * (Center.Z - boxXna.Min.Z);
            }

            else if (Center.Z > boxXna.Max.Z)
            {
                dmin += (Center.Z - boxXna.Max.Z) * (Center.Z - boxXna.Max.Z);
            }

            if (dmin <= Radius * Radius)
            {
                return(ContainmentType.Intersects);
            }

            //else disjoint
            return(ContainmentType.Disjoint);
        }
Example #3
0
        public void Intersects(ref BoundingBoxXna boxXna, out bool result)
        {
            var containment = ContainmentType.Disjoint;

            this.Contains(ref boxXna, out containment);
            result = containment != ContainmentType.Disjoint;
        }
Example #4
0
        public ContainmentType Contains(BoundingBoxXna boxXna)
        {
            ContainmentType result;

            this.Contains(ref boxXna, out result);
            return(result);
        }
Example #5
0
        public static BoundingSphere CreateFromBoundingBox(BoundingBoxXna boxXna)
        {
            // Find the center of the boxXna.
            Vector3 center = new Vector3((boxXna.Min.X + boxXna.Max.X) / 2.0f,
                                         (boxXna.Min.Y + boxXna.Max.Y) / 2.0f,
                                         (boxXna.Min.Z + boxXna.Max.Z) / 2.0f);

            // Find the distance between the center and one of the corners of the boxXna.
            double radius = Vector3.Distance(center, boxXna.Max);

            return(new BoundingSphere(center, radius));
        }
Example #6
0
 public void Intersects(ref BoundingBoxXna boxXna, out bool result)
 {
     result = Intersects(boxXna);
 }
Example #7
0
 public bool Intersects(BoundingBoxXna boxXna)
 {
     return(boxXna.Intersects(this));
 }
Example #8
0
 public static void CreateFromBoundingBox(ref BoundingBoxXna boxXna, out BoundingSphere result)
 {
     result = CreateFromBoundingBox(boxXna);
 }
Example #9
0
 public void Contains(ref BoundingBoxXna boxXna, out ContainmentType result)
 {
     result = this.Contains(boxXna);
 }
Example #10
0
        public void Contains(ref BoundingBoxXna boxXna, out ContainmentType result)
        {
            var intersects = false;

            PlaneIntersectionType type;

            boxXna.Intersects(ref near, out type);
            if (type == PlaneIntersectionType.Front)
            {
                result = ContainmentType.Disjoint;
                return;
            }
            if (type == PlaneIntersectionType.Intersecting)
            {
                intersects = true;
            }

            boxXna.Intersects(ref left, out type);
            if (type == PlaneIntersectionType.Front)
            {
                result = ContainmentType.Disjoint;
                return;
            }
            if (type == PlaneIntersectionType.Intersecting)
            {
                intersects = true;
            }

            boxXna.Intersects(ref right, out type);
            if (type == PlaneIntersectionType.Front)
            {
                result = ContainmentType.Disjoint;
                return;
            }
            if (type == PlaneIntersectionType.Intersecting)
            {
                intersects = true;
            }

            boxXna.Intersects(ref top, out type);
            if (type == PlaneIntersectionType.Front)
            {
                result = ContainmentType.Disjoint;
                return;
            }
            if (type == PlaneIntersectionType.Intersecting)
            {
                intersects = true;
            }

            boxXna.Intersects(ref bottom, out type);
            if (type == PlaneIntersectionType.Front)
            {
                result = ContainmentType.Disjoint;
                return;
            }
            if (type == PlaneIntersectionType.Intersecting)
            {
                intersects = true;
            }

            boxXna.Intersects(ref far, out type);
            if (type == PlaneIntersectionType.Front)
            {
                result = ContainmentType.Disjoint;
                return;
            }
            if (type == PlaneIntersectionType.Intersecting)
            {
                intersects = true;
            }

            result = intersects ? ContainmentType.Intersects : ContainmentType.Contains;
        }
Example #11
0
        public double?Intersects(BoundingBoxXna boxXna)
        {
            //first test if start in boxXna
            if (Position.X >= boxXna.Min.X &&
                Position.X <= boxXna.Max.X &&
                Position.Y >= boxXna.Min.Y &&
                Position.Y <= boxXna.Max.Y &&
                Position.Z >= boxXna.Min.Z &&
                Position.Z <= boxXna.Max.Z)
            {
                return(0.0f);// here we concidere cube is full and origine is in cube so intersect at origine
            }
            //Second we check each face
            Vector3 maxT = new Vector3(-1.0f);

            //Vector3 minT = new Vector3(-1.0f);
            //calcul intersection with each faces
            if (Position.X < boxXna.Min.X && Direction.X != 0.0f)
            {
                maxT.X = (boxXna.Min.X - Position.X) / Direction.X;
            }
            else if (Position.X > boxXna.Max.X && Direction.X != 0.0f)
            {
                maxT.X = (boxXna.Max.X - Position.X) / Direction.X;
            }
            if (Position.Y < boxXna.Min.Y && Direction.Y != 0.0f)
            {
                maxT.Y = (boxXna.Min.Y - Position.Y) / Direction.Y;
            }
            else if (Position.Y > boxXna.Max.Y && Direction.Y != 0.0f)
            {
                maxT.Y = (boxXna.Max.Y - Position.Y) / Direction.Y;
            }
            if (Position.Z < boxXna.Min.Z && Direction.Z != 0.0f)
            {
                maxT.Z = (boxXna.Min.Z - Position.Z) / Direction.Z;
            }
            else if (Position.Z > boxXna.Max.Z && Direction.Z != 0.0f)
            {
                maxT.Z = (boxXna.Max.Z - Position.Z) / Direction.Z;
            }


            //get the maximum maxT
            if (maxT.X > maxT.Y && maxT.X > maxT.Z)
            {
                if (maxT.X < 0.0f)
                {
                    return(null);// ray go on opposite of face
                }
                //coordonate of hit point of face of cube
                double coord = Position.Z + maxT.X * Direction.Z;
                // if hit point coord ( intersect face with ray) is out of other plane coord it miss
                if (coord < boxXna.Min.Z || coord > boxXna.Max.Z)
                {
                    return(null);
                }
                coord = Position.Y + maxT.X * Direction.Y;
                if (coord < boxXna.Min.Y || coord > boxXna.Max.Y)
                {
                    return(null);
                }
                return(maxT.X);
            }
            if (maxT.Y > maxT.X && maxT.Y > maxT.Z)
            {
                if (maxT.Y < 0.0f)
                {
                    return(null);// ray go on opposite of face
                }
                //coordonate of hit point of face of cube
                double coord = Position.Z + maxT.Y * Direction.Z;
                // if hit point coord ( intersect face with ray) is out of other plane coord it miss
                if (coord < boxXna.Min.Z || coord > boxXna.Max.Z)
                {
                    return(null);
                }
                coord = Position.X + maxT.Y * Direction.X;
                if (coord < boxXna.Min.X || coord > boxXna.Max.X)
                {
                    return(null);
                }
                return(maxT.Y);
            }
            else //Z
            {
                if (maxT.Z < 0.0f)
                {
                    return(null);// ray go on opposite of face
                }
                //coordonate of hit point of face of cube
                double coord = Position.X + maxT.Z * Direction.X;
                // if hit point coord ( intersect face with ray) is out of other plane coord it miss
                if (coord < boxXna.Min.X || coord > boxXna.Max.X)
                {
                    return(null);
                }
                coord = Position.Y + maxT.Z * Direction.Y;
                if (coord < boxXna.Min.Y || coord > boxXna.Max.Y)
                {
                    return(null);
                }
                return(maxT.Z);
            }
        }
Example #12
0
 public void Intersects(ref BoundingBoxXna boxXna, out PlaneIntersectionType result)
 {
     result = Intersects(boxXna);
 }
Example #13
0
 public PlaneIntersectionType Intersects(BoundingBoxXna boxXna)
 {
     return(boxXna.Intersects(this));
 }