/// <summary> /// Gets whether or not a specified <see cref="PlaneD"/> intersects with this sphere. /// </summary> /// <param name="plane">The plane for testing.</param> /// <returns>Type of intersection.</returns> public PlaneIntersectionTypeD Intersects(PlaneD plane) { PlaneIntersectionTypeD result = default(PlaneIntersectionTypeD); // TODO: We might want to inline this for performance reasons. this.Intersects(ref plane, out result); return(result); }
/// <summary> /// Gets type of intersection between specified <see cref="PlaneD"/> and this <see cref="BoundingFrustumD"/>. /// </summary> /// <param name="plane">A <see cref="PlaneD"/> for intersection test.</param> /// <param name="result">A plane intersection type as an output parameter.</param> public void Intersects(ref PlaneD plane, out PlaneIntersectionTypeD result) { result = plane.Intersects(ref corners[0]); for (int i = 1; i < corners.Length; i += 1) { if (plane.Intersects(ref corners[i]) != result) { result = PlaneIntersectionTypeD.Intersecting; } } }
/// <summary> /// Gets whether or not a specified <see cref="PlaneD"/> intersects with this sphere. /// </summary> /// <param name="plane">The plane for testing.</param> /// <param name="result">Type of intersection as an output parameter.</param> public void Intersects(ref PlaneD plane, out PlaneIntersectionTypeD result) { double distance = default(double); // TODO: We might want to inline this for performance reasons. Vector3D.Dot(ref plane.Normal, ref this.Center, out distance); distance += plane.D; if (distance > this.Radius) { result = PlaneIntersectionTypeD.Front; } else if (distance < -this.Radius) { result = PlaneIntersectionTypeD.Back; } else { result = PlaneIntersectionTypeD.Intersecting; } }
/// <summary> /// Containment test between this <see cref="BoundingFrustumD"/> and specified <see cref="BoundingBoxD"/>. /// </summary> /// <param name="box">A <see cref="BoundingBoxD"/> for testing.</param> /// <param name="result">Result of testing for containment between this <see cref="BoundingFrustumD"/> and specified <see cref="BoundingBoxD"/> as an output parameter.</param> public void Contains(ref BoundingBoxD box, out ContainmentType result) { bool intersects = false; for (int i = 0; i < PlaneCount; i += 1) { PlaneIntersectionTypeD planeIntersectionType = default(PlaneIntersectionTypeD); box.Intersects(ref this.planes[i], out planeIntersectionType); switch (planeIntersectionType) { case PlaneIntersectionTypeD.Front: result = ContainmentType.Disjoint; return; case PlaneIntersectionTypeD.Intersecting: intersects = true; break; } } result = intersects ? ContainmentType.Intersects : ContainmentType.Contains; }
/// <summary> /// Containment test between this <see cref="BoundingFrustumD"/> and specified <see cref="BoundingSphereD"/>. /// </summary> /// <param name="sphere">A <see cref="BoundingSphereD"/> for testing.</param> /// <param name="result">Result of testing for containment between this <see cref="BoundingFrustumD"/> and specified <see cref="BoundingSphereD"/> as an output parameter.</param> public void Contains(ref BoundingSphereD sphere, out ContainmentType result) { bool intersects = false; for (int i = 0; i < PlaneCount; i += 1) { PlaneIntersectionTypeD planeIntersectionType = default(PlaneIntersectionTypeD); // TODO: We might want to inline this for performance reasons. sphere.Intersects(ref this.planes[i], out planeIntersectionType); switch (planeIntersectionType) { case PlaneIntersectionTypeD.Front: result = ContainmentType.Disjoint; return; case PlaneIntersectionTypeD.Intersecting: intersects = true; break; } } result = intersects ? ContainmentType.Intersects : ContainmentType.Contains; }
public void Intersects(ref PlaneD plane, out PlaneIntersectionTypeD result) { // See http://zach.in.tu-clausthal.de/teaching/cg_literatur/lighthouse3d_view_frustum_culling/index.html Vector3D positiveVertex; Vector3D negativeVertex; if (plane.Normal.X >= 0) { positiveVertex.X = Max.X; negativeVertex.X = Min.X; } else { positiveVertex.X = Min.X; negativeVertex.X = Max.X; } if (plane.Normal.Y >= 0) { positiveVertex.Y = Max.Y; negativeVertex.Y = Min.Y; } else { positiveVertex.Y = Min.Y; negativeVertex.Y = Max.Y; } if (plane.Normal.Z >= 0) { positiveVertex.Z = Max.Z; negativeVertex.Z = Min.Z; } else { positiveVertex.Z = Min.Z; negativeVertex.Z = Max.Z; } // Inline Vector3D.Dot(plane.Normal, negativeVertex) + plane.D; double distance = ( plane.Normal.X * negativeVertex.X + plane.Normal.Y * negativeVertex.Y + plane.Normal.Z * negativeVertex.Z + plane.D ); if (distance > 0) { result = PlaneIntersectionTypeD.Front; return; } // Inline Vector3D.Dot(plane.Normal, positiveVertex) + plane.D; distance = ( plane.Normal.X * positiveVertex.X + plane.Normal.Y * positiveVertex.Y + plane.Normal.Z * positiveVertex.Z + plane.D ); if (distance < 0) { result = PlaneIntersectionTypeD.Back; return; } result = PlaneIntersectionTypeD.Intersecting; }
public void Intersects(ref BoundingSphereD sphere, out PlaneIntersectionTypeD result) { sphere.Intersects(ref this, out result); }
public void Intersects(ref BoundingBoxD box, out PlaneIntersectionTypeD result) { box.Intersects(ref this, out result); }