/// <summary> /// Determines whether there is an intersection between a <see cref="SharpDX.Plane"/> and a point. /// </summary> /// <param name="plane">The plane to test.</param> /// <param name="point">The point to test.</param> /// <returns>Whether the two objects intersected.</returns> private static PlaneIntersectionType PlaneIntersectsPoint(ref PlaneD plane, ref Vector3D point) { double distance; Vector3D.Dot(ref plane.Normal, ref point, out distance); distance += plane.D; if (distance > 0f) { return(PlaneIntersectionType.Front); } if (distance < 0f) { return(PlaneIntersectionType.Back); } return(PlaneIntersectionType.Intersecting); }
/// <summary> /// Determines whether there is an intersection between a <see cref="SharpDX.Plane"/> and a point. /// </summary> /// <param name="plane">The plane to test.</param> /// <param name="point">The point to test.</param> /// <returns>Whether the two objects intersected.</returns> private static PlaneIntersectionType PlaneIntersectsPoint(ref PlaneD plane, ref Vector3D point) { double distance; Vector3D.Dot(ref plane.Normal, ref point, out distance); distance += plane.D; if (distance > 0f) return PlaneIntersectionType.Front; if (distance < 0f) return PlaneIntersectionType.Back; return PlaneIntersectionType.Intersecting; }
private static void GetPlanesFromMatrix(ref MatrixD matrix, out PlaneD near, out PlaneD far, out PlaneD left, out PlaneD right, out PlaneD top, out PlaneD bottom) { //http://www.chadvernon.com/blog/resources/directx9/frustum-culling/ // Left plane left.Normal.X = matrix.M14 + matrix.M11; left.Normal.Y = matrix.M24 + matrix.M21; left.Normal.Z = matrix.M34 + matrix.M31; left.D = matrix.M44 + matrix.M41; left.Normalize(); // Right plane right.Normal.X = matrix.M14 - matrix.M11; right.Normal.Y = matrix.M24 - matrix.M21; right.Normal.Z = matrix.M34 - matrix.M31; right.D = matrix.M44 - matrix.M41; right.Normalize(); // Top plane top.Normal.X = matrix.M14 - matrix.M12; top.Normal.Y = matrix.M24 - matrix.M22; top.Normal.Z = matrix.M34 - matrix.M32; top.D = matrix.M44 - matrix.M42; top.Normalize(); // Bottom plane bottom.Normal.X = matrix.M14 + matrix.M12; bottom.Normal.Y = matrix.M24 + matrix.M22; bottom.Normal.Z = matrix.M34 + matrix.M32; bottom.D = matrix.M44 + matrix.M42; bottom.Normalize(); // Near plane near.Normal.X = matrix.M13; near.Normal.Y = matrix.M23; near.Normal.Z = matrix.M33; near.D = matrix.M43; near.Normalize(); // Far plane far.Normal.X = matrix.M14 - matrix.M13; far.Normal.Y = matrix.M24 - matrix.M23; far.Normal.Z = matrix.M34 - matrix.M33; far.D = matrix.M44 - matrix.M43; far.Normalize(); }