/// <summary> /// Constructs a <see cref="MyBoundingBox"/> from a given sphere. /// </summary> /// <param name="sphere">The sphere that will designate the extents of the box.</param> /// <returns>The newly constructed bounding box.</returns> public static MyBoundingBox FromSphere(MyBoundingSphere sphere) { MyBoundingBox box; box.Minimum = new MyVector3(sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius); box.Maximum = new MyVector3(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius); return(box); }
/// <summary> /// Determines the intersection relationship between the frustum and a bounding sphere. /// </summary> /// <param name="sphere">The sphere.</param> /// <returns>Type of the containment</returns> public MyContainmentType Contains(ref MyBoundingSphere sphere) { var result = MyPlaneIntersectionType.Front; var planeResult = MyPlaneIntersectionType.Front; for (int i = 0; i < 6; i++) { switch (i) { case 0: planeResult = pNear.Intersects(ref sphere); break; case 1: planeResult = pFar.Intersects(ref sphere); break; case 2: planeResult = pLeft.Intersects(ref sphere); break; case 3: planeResult = pRight.Intersects(ref sphere); break; case 4: planeResult = pTop.Intersects(ref sphere); break; case 5: planeResult = pBottom.Intersects(ref sphere); break; } switch (planeResult) { case MyPlaneIntersectionType.Back: return(MyContainmentType.Disjoint); case MyPlaneIntersectionType.Intersecting: result = MyPlaneIntersectionType.Intersecting; break; } } switch (result) { case MyPlaneIntersectionType.Intersecting: return(MyContainmentType.Intersects); default: return(MyContainmentType.Contains); } }
/// <summary> /// Determines whether a <see cref="MyOrientedBoundingBox"/> contains a <see cref="MyBoundingSphere"/>. /// </summary> /// <param name="sphere">The sphere to test.</param> /// <param name="IgnoreScale">Optimize the check operation by assuming that <see cref="MyOrientedBoundingBox"/> has no scaling applied</param> /// <returns>The type of containment the two objects have.</returns> /// <remarks> /// This method is not designed for <see cref="MyOrientedBoundingBox"/> which has a non-uniform scaling applied to its transformation matrix. /// But any type of scaling applied using Scale method will keep this method accurate. /// </remarks> public MyContainmentType Contains(MyBoundingSphere sphere, bool IgnoreScale = false) { MyMatrix invTrans; MyMatrix.Invert(ref Transformation, out invTrans); // Transform sphere center into the obb coordinates MyVector3 locCenter; MyVector3.TransformCoordinate(ref sphere.Center, ref invTrans, out locCenter); float locRadius; if (IgnoreScale) locRadius = sphere.Radius; else { // Transform sphere radius into the obb coordinates MyVector3 vRadius = MyVector3.UnitX * sphere.Radius; MyVector3.TransformNormal(ref vRadius, ref invTrans, out vRadius); locRadius = vRadius.Length(); } //Perform regular BoundingBox to BoundingSphere containment check MyVector3 minusExtens = -Extents; MyVector3 vector; MyVector3.Clamp(ref locCenter, ref minusExtens, ref Extents, out vector); float distance = MyVector3.DistanceSquared(locCenter, vector); if (distance > locRadius * locRadius) return MyContainmentType.Disjoint; if ((((minusExtens.X + locRadius <= locCenter.X) && (locCenter.X <= Extents.X - locRadius)) && ((Extents.X - minusExtens.X > locRadius) && (minusExtens.Y + locRadius <= locCenter.Y))) && (((locCenter.Y <= Extents.Y - locRadius) && (Extents.Y - minusExtens.Y > locRadius)) && (((minusExtens.Z + locRadius <= locCenter.Z) && (locCenter.Z <= Extents.Z - locRadius)) && (Extents.Z - minusExtens.Z > locRadius)))) { return MyContainmentType.Contains; } return MyContainmentType.Intersects; }
/// <summary> /// Constructs a <see cref="MyBoundingBox"/> from a given sphere. /// </summary> /// <param name="sphere">The sphere that will designate the extents of the box.</param> /// <param name="result">When the method completes, contains the newly constructed bounding box.</param> public static void FromSphere(ref MyBoundingSphere sphere, out MyBoundingBox result) { result.Minimum = new MyVector3(sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius); result.Maximum = new MyVector3(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius); }
/// <summary> /// Determines whether the current objects contains a <see cref="MyBoundingSphere"/>. /// </summary> /// <param name="sphere">The sphere to test.</param> /// <returns>The type of containment the two objects have.</returns> public MyContainmentType Contains(MyBoundingSphere sphere) { return(Contains(ref sphere)); }
/// <summary> /// Determines whether the current objects contains a <see cref="MyBoundingSphere"/>. /// </summary> /// <param name="sphere">The sphere to test.</param> /// <returns>The type of containment the two objects have.</returns> public MyContainmentType Contains(ref MyBoundingSphere sphere) { return(MyCollision.BoxContainsSphere(ref this, ref sphere)); }
/// <summary> /// Determines if there is an intersection between the current object and a <see cref="MyBoundingSphere"/>. /// </summary> /// <param name="sphere">The sphere to test.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(MyBoundingSphere sphere) { return(Intersects(ref sphere)); }
/// <summary> /// Determines if there is an intersection between the current object and a <see cref="MyBoundingSphere"/>. /// </summary> /// <param name="sphere">The sphere to test.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref MyBoundingSphere sphere) { return(MyCollision.BoxIntersectsSphere(ref this, ref sphere)); }
/// <summary> /// Checks whether the current BoundingFrustum intersects a BoundingSphere. /// </summary> /// <param name="sphere">The sphere.</param> /// <param name="result">Set to <c>true</c> if the current BoundingFrustum intersects a BoundingSphere.</param> public void Intersects(ref MyBoundingSphere sphere, out bool result) { result = Contains(ref sphere) != MyContainmentType.Disjoint; }
/// <summary> /// Checks whether the current BoundingFrustum intersects a BoundingSphere. /// </summary> /// <param name="sphere">The sphere.</param> /// <returns>Type of the containment</returns> public bool Intersects(ref MyBoundingSphere sphere) { return(Contains(ref sphere) != MyContainmentType.Disjoint); }
/// <summary> /// Determines the intersection relationship between the frustum and a bounding sphere. /// </summary> /// <param name="sphere">The sphere.</param> /// <param name="result">Type of the containment.</param> public void Contains(ref MyBoundingSphere sphere, out MyContainmentType result) { result = Contains(ref sphere); }
/// <summary> /// Determines if there is an intersection between the current object and a <see cref="MyBoundingSphere"/>. /// </summary> /// <param name="sphere">The sphere to test.</param> /// <returns>Whether the two objects intersected.</returns> public MyPlaneIntersectionType Intersects(ref MyBoundingSphere sphere) { return(MyCollision.PlaneIntersectsSphere(ref this, ref sphere)); }
/// <summary> /// Determines if there is an intersection between the current object and a <see cref="MyBoundingSphere"/>. /// </summary> /// <param name="sphere">The sphere to test.</param> /// <param name="point">When the method completes, contains the point of intersection, /// or <see cref="MyVector3.Zero"/> if there was no intersection.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref MyBoundingSphere sphere, out MyVector3 point) { return(MyCollision.RayIntersectsSphere(ref this, ref sphere, out point)); }
/// <summary> /// Determines if there is an intersection between the current object and a <see cref="MyBoundingSphere"/>. /// </summary> /// <param name="sphere">The sphere to test.</param> /// <param name="distance">When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref MyBoundingSphere sphere, out float distance) { return(MyCollision.RayIntersectsSphere(ref this, ref sphere, out distance)); }