/// <summary> /// Determines whether there is an intersection between a <see cref="Ray" /> and a <see cref="OrientedBoundingBox" />. /// </summary> /// <param name="ray">The ray to test.</param> /// <param name="point">When the method completes, contains the point of intersection, or <see cref="Vector3.Zero" /> if there was no intersection.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref Ray ray, out Vector3 point) { // Put ray in box space Ray bRay; Transformation.WorldToLocalVector(ref ray.Direction, out bRay.Direction); Transformation.WorldToLocal(ref ray.Position, out bRay.Position); // Perform a regular ray to BoundingBox check var bb = new BoundingBox(-Extents, Extents); bool intersects = CollisionsHelper.RayIntersectsBox(ref bRay, ref bb, out point); // Put the result intersection back to world if (intersects) { Transformation.LocalToWorld(ref point, out point); } return(intersects); }
/// <summary> /// Determines whether there is an intersection between a <see cref="Ray" /> and a <see cref="OrientedBoundingBox" />. /// </summary> /// <param name="ray">The ray to test.</param> /// <param name="point"> /// When the method completes, contains the point of intersection, /// or <see cref="Vector3.Zero" /> if there was no intersection. /// </param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref Ray ray, out Vector3 point) { // Put ray in box space Matrix.Invert(ref Transformation, out Matrix invTrans); Ray bRay; Vector3.TransformNormal(ref ray.Direction, ref invTrans, out bRay.Direction); Vector3.TransformCoordinate(ref ray.Position, ref invTrans, out bRay.Position); //Perform a regular ray to BoundingBox check var bb = new BoundingBox(-Extents, Extents); bool intersects = CollisionsHelper.RayIntersectsBox(ref bRay, ref bb, out point); //Put the result intersection back to world if (intersects) { Vector3.TransformCoordinate(ref point, ref Transformation, out point); } return(intersects); }
/// <summary> /// Determines if there is an intersection between the current object and a <see cref="BoundingBox" />. /// </summary> /// <param name="box">The box to test.</param> /// <param name="point"> /// When the method completes, contains the point of intersection, /// or <see cref="Vector3.Zero" /> if there was no intersection. /// </param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref BoundingBox box, out Vector3 point) { return(CollisionsHelper.RayIntersectsBox(ref this, ref box, out point)); }
/// <summary> /// Determines if there is an intersection between the current object and a <see cref="BoundingBox" />. /// </summary> /// <param name="box">The box to test.</param> /// <param name="distance"> /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// </param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref BoundingBox box, out float distance) { return(CollisionsHelper.RayIntersectsBox(ref this, ref box, out distance)); }