Example #1
0
        /// <summary>
        /// Test whether a <see cref="OBBf"/> intersects this plane.
        /// See: Ericson 2005, Real Time Collision Detection, p. 161 - 164
        /// </summary>
        /// <param name="obb">The axis aligned bounding box.</param>
        public bool Intersects(OBBf obb)
        {
            var r = BoxExtendInNormalDirection(obb);
            var s = SignedDistanceFromPoint(obb.Center);

            return(System.Math.Abs(s) <= r);
        }
Example #2
0
        /// <summary>
        /// Calculates the projection interval radius of obb onto line L(t) = aabb.Center + t * plane.Normal (extend (radius) in direction of the plane normal).
        /// <param name="obb">The object oriented bounding box.</param>
        /// </summary>
        private float BoxExtendInNormalDirection(OBBf obb)
        {
            var transformationMat = obb.Rotation * float4x4.CreateTranslation(obb.Translation); //without scale!

            var xAxis = (float3.UnitX * transformationMat).Normalize();
            var yAxis = (float3.UnitY * transformationMat).Normalize();
            var zAxis = (float3.UnitZ * transformationMat).Normalize();

            var boxExtend = obb.Size * 0.5f;

            return(boxExtend.x * System.Math.Abs(float3.Dot(Normal, xAxis)) +
                   boxExtend.y * System.Math.Abs(float3.Dot(Normal, yAxis)) +
                   boxExtend.z * System.Math.Abs(float3.Dot(Normal, zAxis)));
        }
Example #3
0
        /// <summary>
        /// Test whether a <see cref="AABBf"/> intersects this plane.
        /// See: Ericson 2005, Real Time Collision Detection, p. 161 - 164
        /// CAREFUL: the definition whats completely inside and outside is flipped in comparison to Ericson,
        /// because FUSEE defines a point with a negative signed distance to be inside.
        /// </summary>
        /// <param name="obb">The object oriented bounding box.</param>
        public bool InsideOrIntersecting(OBBf obb)
        {
            var r = BoxExtendInNormalDirection(obb);
            //Distance from obb center to plane
            var s = SignedDistanceFromPoint(obb.Center);

            //Completely outside
            if (s <= -r)
            {
                return(true);
            }
            //Completely inside
            else if (r <= s)
            {
                return(false);
            }
            //else intersecting
            return(true);
        }