internal static void DrawFrustum(BoundingFrustum frustum, Color color, float alpha) { var corners = frustum.GetCorners(); Color c = color; c.A = (byte)(alpha * 255); DrawQuad(corners[0], corners[1], corners[2], corners[3], c); DrawQuad(corners[4], corners[5], corners[6], corners[7], c); // top left bottom right DrawQuad(corners[0], corners[1], corners[5], corners[4], c); DrawQuad(corners[0], corners[3], corners[7], corners[4], c); DrawQuad(corners[3], corners[2], corners[6], corners[7], c); DrawQuad(corners[2], corners[1], corners[5], corners[6], c); }
public BoundingBox Include(ref BoundingFrustum frustum) { if (m_frustumPoints == null) { m_frustumPoints = new Vector3[8]; } frustum.GetCorners(m_frustumPoints); Include(ref m_frustumPoints[0]); Include(ref m_frustumPoints[1]); Include(ref m_frustumPoints[2]); Include(ref m_frustumPoints[3]); Include(ref m_frustumPoints[4]); Include(ref m_frustumPoints[5]); Include(ref m_frustumPoints[6]); Include(ref m_frustumPoints[7]); return(this); }
internal void AddFrustum(BoundingFrustum bf, Color color) { Add6FacedConvex(bf.GetCorners(), color); }
internal static void DrawFrustum(BoundingFrustum frustum, Color color, float alpha) { var corners = frustum.GetCorners(); Draw6FacedConvex(corners, color, alpha); }
internal static void DrawFrustum(BoundingFrustum frustum, Color color, float alpha) { var corners = frustum.GetCorners(); Draw6FacedConvexZ(corners, color, alpha); }
/// <summary> /// Creates bounding sphere from bounding frustum. /// Implementation taken from XNA source, replace IEnumerable with array /// </summary> /// <param name="frustum">The bounding frustum.</param> /// <param name="corners">Temporary memory to save corner when getting from frustum.</param> /// <returns>BoundingSphere</returns> public static BoundingSphere ToBoundingSphere(this BoundingFrustum frustum, Vector3[] corners) { float num; float num2; Vector3 vector2; float num4; float num5; BoundingSphere sphere; Vector3 vector5; Vector3 vector6; Vector3 vector7; Vector3 vector8; Vector3 vector9; if (corners.Length < 8) { throw new ArgumentException("Corners length must be at least 8"); } frustum.GetCorners(corners); Vector3 vector4 = vector5 = vector6 = vector7 = vector8 = vector9 = corners[0]; for (int i = 0; i < corners.Length; i++) { Vector3 vector = corners[i]; if (vector.X < vector4.X) { vector4 = vector; } if (vector.X > vector5.X) { vector5 = vector; } if (vector.Y < vector6.Y) { vector6 = vector; } if (vector.Y > vector7.Y) { vector7 = vector; } if (vector.Z < vector8.Z) { vector8 = vector; } if (vector.Z > vector9.Z) { vector9 = vector; } } Vector3.Distance(ref vector5, ref vector4, out num5); Vector3.Distance(ref vector7, ref vector6, out num4); Vector3.Distance(ref vector9, ref vector8, out num2); if (num5 > num4) { if (num5 > num2) { Vector3.Lerp(ref vector5, ref vector4, 0.5f, out vector2); num = num5 * 0.5f; } else { Vector3.Lerp(ref vector9, ref vector8, 0.5f, out vector2); num = num2 * 0.5f; } } else if (num4 > num2) { Vector3.Lerp(ref vector7, ref vector6, 0.5f, out vector2); num = num4 * 0.5f; } else { Vector3.Lerp(ref vector9, ref vector8, 0.5f, out vector2); num = num2 * 0.5f; } for (int i = 0; i < corners.Length; i++) { Vector3 vector10 = corners[i]; Vector3 vector3; vector3.X = vector10.X - vector2.X; vector3.Y = vector10.Y - vector2.Y; vector3.Z = vector10.Z - vector2.Z; float num3 = vector3.Length(); if (num3 > num) { num = (num + num3) * 0.5f; vector2 += (Vector3)((1f - (num / num3)) * vector3); } } sphere.Center = vector2; sphere.Radius = num; return(sphere); }
internal void AddFrustum(BoundingFrustum bf, Color color) { Add6FacedConvex(bf.GetCorners(), color); }
public static BoundingSphere ToBoundingSphere(this BoundingFrustum frustum, Vector3[] corners) { float num; float num2; Vector3 vector; float num3; float num4; BoundingSphere sphere; Vector3 vector2; Vector3 vector3; Vector3 vector4; Vector3 vector5; Vector3 vector6; if (corners.Length < 8) { throw new ArgumentException("Corners length must be at least 8"); } frustum.GetCorners(corners); Vector3 vector7 = vector2 = vector3 = vector4 = vector5 = vector6 = corners[0]; for (int i = 0; i < corners.Length; i++) { Vector3 vector8 = corners[i]; if (vector8.X < vector7.X) { vector7 = vector8; } if (vector8.X > vector2.X) { vector2 = vector8; } if (vector8.Y < vector3.Y) { vector3 = vector8; } if (vector8.Y > vector4.Y) { vector4 = vector8; } if (vector8.Z < vector5.Z) { vector5 = vector8; } if (vector8.Z > vector6.Z) { vector6 = vector8; } } Vector3.Distance(ref vector2, ref vector7, out num4); Vector3.Distance(ref vector4, ref vector3, out num3); Vector3.Distance(ref vector6, ref vector5, out num2); if (num4 > num3) { if (num4 > num2) { Vector3.Lerp(ref vector2, ref vector7, 0.5f, out vector); num = num4 * 0.5f; } else { Vector3.Lerp(ref vector6, ref vector5, 0.5f, out vector); num = num2 * 0.5f; } } else if (num3 > num2) { Vector3.Lerp(ref vector4, ref vector3, 0.5f, out vector); num = num3 * 0.5f; } else { Vector3.Lerp(ref vector6, ref vector5, 0.5f, out vector); num = num2 * 0.5f; } for (int j = 0; j < corners.Length; j++) { Vector3 vector10; Vector3 vector9 = corners[j]; vector10.X = vector9.X - vector.X; vector10.Y = vector9.Y - vector.Y; vector10.Z = vector9.Z - vector.Z; float num7 = vector10.Length(); if (num7 > num) { num = (num + num7) * 0.5f; vector += (Vector3)((1f - (num / num7)) * vector10); } } sphere.Center = vector; sphere.Radius = num; return(sphere); }
internal static void DrawFrustum(BoundingFrustum frustum, Color color, float alpha) { var corners = frustum.GetCorners(); Color c = color; c.A = (byte)(alpha * 255); DrawQuad(corners[0], corners[1], corners[2], corners[3], c); DrawQuad(corners[4], corners[5], corners[6], corners[7], c); // top left bottom right DrawQuad(corners[0], corners[1], corners[5], corners[4], c); DrawQuad(corners[0], corners[3], corners[7], corners[4], c); DrawQuad(corners[3], corners[2], corners[6], corners[7], c); DrawQuad(corners[2], corners[1], corners[5], corners[6], c); }