/// <summary> /// Calculates the angle between this plane and another one. /// </summary> /// <param name="other">The other plane to calculate the angle with.</param> public float AngleBetween(PlaneF other) { var numerator = System.Math.Abs((A * other.A) + (B * other.B) + (C * other.C)); var denominator = Normal.Length * other.Normal.Length; var cosAlpha = numerator / denominator; return((float)System.Math.Acos(cosAlpha)); }
/// <summary> /// (Re)Calculates the frustum planes. /// If feeded with a projection matrix, the frustum planes are in View Space. /// If feeded with a view projection matrix, the frustum planes are in World Space. /// If feeded with a model view projection matrix, the frustum planes are in Model Space. /// See: http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf /// </summary> /// <param name="mat">The matrix from which to extract the planes.</param> public void CalculateFrustumPlanes(float4x4 mat) { // left var left = new PlaneF() { A = mat.M41 + mat.M11, B = mat.M42 + mat.M12, C = mat.M43 + mat.M13, D = mat.M44 + mat.M14 }; // right var right = new PlaneF() { A = mat.M41 - mat.M11, B = mat.M42 - mat.M12, C = mat.M43 - mat.M13, D = mat.M44 - mat.M14 }; // bottom var bottom = new PlaneF() { A = mat.M41 + mat.M21, B = mat.M42 + mat.M22, C = mat.M43 + mat.M23, D = mat.M44 + mat.M24 }; // top var top = new PlaneF() { A = mat.M41 - mat.M21, B = mat.M42 - mat.M22, C = mat.M43 - mat.M23, D = mat.M44 - mat.M24 }; // near var near = new PlaneF() { A = mat.M41 + mat.M31, B = mat.M42 + mat.M32, C = mat.M43 + mat.M33, D = mat.M44 + mat.M34 }; // far var far = new PlaneF() { A = mat.M41 - mat.M31, B = mat.M42 - mat.M32, C = mat.M43 - mat.M33, D = mat.M44 - mat.M34 }; //Negate D because Fusee uses ax +by + cz = d left.D *= -1; right.D *= -1; near.D *= -1; far.D *= -1; top.D *= -1; bottom.D *= -1; //Invert plane to get the normal to face outwards. left *= -1; right *= -1; near *= -1; far *= -1; top *= -1; bottom *= -1; Left = left; Right = right; Top = top; Bottom = bottom; Near = near; Far = far; }
/// <summary> /// Checks if a viewing frustum lies within or intersects this AABB. /// </summary> /// <param name="plane">The plane to test against.</param> /// <returns>false if fully outside, true if inside or intersecting.</returns> public bool InsideOrIntersectingPlane(PlaneF plane) { return(plane.InsideOrIntersecting(this)); }