Class CollisionsHelper
Contains static methods to help in determining intersections, containment, etc.
Inheritance
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
public static class CollisionsHelper : Object
Methods
BoxContainsBox(ref BoundingBox, ref BoundingBox)
Determines whether a BoundingBox contains a BoundingBox.
Declaration
public static ContainmentType BoxContainsBox(ref BoundingBox box1, ref BoundingBox box2)
Parameters
BoundingBox
box1
The first box to test. |
BoundingBox
box2
The second box to test. |
Returns
ContainmentType
The type of containment the two objects have. |
BoxContainsPoint(ref BoundingBox, ref Vector3)
Determines whether a BoundingBox contains a point.
Declaration
public static ContainmentType BoxContainsPoint(ref BoundingBox box, ref Vector3 point)
Parameters
BoundingBox
box
The box to test. |
Vector3
point
The point to test. |
Returns
ContainmentType
The type of containment the two objects have. |
BoxContainsSphere(ref BoundingBox, ref BoundingSphere)
Determines whether a BoundingBox contains a BoundingSphere.
Declaration
public static ContainmentType BoxContainsSphere(ref BoundingBox box, ref BoundingSphere sphere)
Parameters
BoundingBox
box
The box to test. |
BoundingSphere
sphere
The sphere to test. |
Returns
ContainmentType
The type of containment the two objects have. |
BoxIntersectsBox(ref BoundingBox, ref BoundingBox)
Determines whether there is an intersection between a BoundingBox and a BoundingBox.
Declaration
public static bool BoxIntersectsBox(ref BoundingBox box1, ref BoundingBox box2)
Parameters
BoundingBox
box1
The first box to test. |
BoundingBox
box2
The second box to test. |
Returns
System.Boolean
Whether the two objects intersected. |
BoxIntersectsSphere(ref BoundingBox, ref BoundingSphere)
Determines whether there is an intersection between a BoundingBox and a BoundingSphere.
Declaration
public static bool BoxIntersectsSphere(ref BoundingBox box, ref BoundingSphere sphere)
Parameters
BoundingBox
box
The box to test. |
BoundingSphere
sphere
The sphere to test. |
Returns
System.Boolean
Whether the two objects intersected. |
ClosestPointBoxPoint(ref BoundingBox, ref Vector3, out Vector3)
Determines the closest point between a BoundingBox and a point.
Declaration
public static void ClosestPointBoxPoint(ref BoundingBox box, ref Vector3 point, out Vector3 result)
Parameters
BoundingBox
box
The box to test. |
Vector3
point
The point to test. |
Vector3
result
When the method completes, contains the closest point between the two objects. |
ClosestPointPlanePoint(ref Plane, ref Vector3, out Vector3)
Determines the closest point between a Plane and a point.
Declaration
public static void ClosestPointPlanePoint(ref Plane plane, ref Vector3 point, out Vector3 result)
Parameters
Plane
plane
The plane to test. |
Vector3
point
The point to test. |
Vector3
result
When the method completes, contains the closest point between the two objects. |
ClosestPointPointLine(ref Float2, ref Float2, ref Float2, out Float2)
Determines the closest point between a point and a line segment.
Declaration
public static void ClosestPointPointLine(ref Float2 point, ref Float2 p0, ref Float2 p1, out Float2 result)
Parameters
Float2
point
The point to test. |
Float2
p0
The line first point. |
Float2
p1
The line second point. |
Float2
result
When the method completes, contains the closest point between the two objects. |
ClosestPointPointLine(ref Vector3, ref Vector3, ref Vector3, out Vector3)
Determines the closest point between a point and a line.
Declaration
public static void ClosestPointPointLine(ref Vector3 point, ref Vector3 p0, ref Vector3 p1, out Vector3 result)
Parameters
Vector3
point
The point to test. |
Vector3
p0
The line first point. |
Vector3
p1
The line second point. |
Vector3
result
When the method completes, contains the closest point between the two objects. |
ClosestPointPointTriangle(ref Vector3, ref Vector3, ref Vector3, ref Vector3, out Vector3)
Determines the closest point between a point and a triangle.
Declaration
public static void ClosestPointPointTriangle(ref Vector3 point, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out Vector3 result)
Parameters
Vector3
point
The point to test. |
Vector3
vertex1
The first vertex to test. |
Vector3
vertex2
The second vertex to test. |
Vector3
vertex3
The third vertex to test. |
Vector3
result
When the method completes, contains the closest point between the two objects. |
ClosestPointRectanglePoint(ref Rectangle, ref Float2, out Float2)
Determines the closest point between a Rectangle and a point.
Declaration
public static void ClosestPointRectanglePoint(ref Rectangle rect, ref Float2 point, out Float2 result)
Parameters
Rectangle
rect
The rectangle to test. |
Float2
point
The point to test. |
Float2
result
When the method completes, contains the closest point between the two objects. |
ClosestPointSpherePoint(ref BoundingSphere, ref Vector3, out Vector3)
Determines the closest point between a BoundingSphere and a point.
Declaration
public static void ClosestPointSpherePoint(ref BoundingSphere sphere, ref Vector3 point, out Vector3 result)
Parameters
BoundingSphere
sphere
|
Vector3
point
The point to test. |
Vector3
result
When the method completes, contains the closest point between the two objects; or, if the point is directly in the center of the sphere, contains Zero. |
ClosestPointSphereSphere(ref BoundingSphere, ref BoundingSphere, out Vector3)
Determines the closest point between a BoundingSphere and a BoundingSphere.
Declaration
public static void ClosestPointSphereSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2, out Vector3 result)
Parameters
BoundingSphere
sphere1
The first sphere to test. |
BoundingSphere
sphere2
The second sphere to test. |
Vector3
result
When the method completes, contains the closest point between the two objects; or, if the point is directly in the center of the sphere, contains Zero. |
Remarks
If the two spheres are overlapping, but not directly on top of each other, the closest point is the 'closest' point of intersection. This can also be considered is the deepest point of intersection.
DistanceBoxBox(ref BoundingBox, ref BoundingBox)
Determines the distance between a BoundingBox and a BoundingBox.
Declaration
public static float DistanceBoxBox(ref BoundingBox box1, ref BoundingBox box2)
Parameters
BoundingBox
box1
The first box to test. |
BoundingBox
box2
The second box to test. |
Returns
System.Single
The distance between the two objects. |
DistanceBoxPoint(ref BoundingBox, ref Vector3)
Determines the distance between a BoundingBox and a point.
Declaration
public static float DistanceBoxPoint(ref BoundingBox box, ref Vector3 point)
Parameters
BoundingBox
box
The box to test. |
Vector3
point
The point to test. |
Returns
System.Single
The distance between the two objects. |
DistancePlanePoint(ref Plane, ref Vector3)
Determines the distance between a Plane and a point.
Declaration
public static float DistancePlanePoint(ref Plane plane, ref Vector3 point)
Parameters
Plane
plane
The plane to test. |
Vector3
point
The point to test. |
Returns
System.Single
The distance between the two objects. |
DistanceSpherePoint(ref BoundingSphere, ref Vector3)
Determines the distance between a BoundingSphere and a point.
Declaration
public static float DistanceSpherePoint(ref BoundingSphere sphere, ref Vector3 point)
Parameters
BoundingSphere
sphere
The sphere to test. |
Vector3
point
The point to test. |
Returns
System.Single
The distance between the two objects. |
DistanceSphereSphere(ref BoundingSphere, ref BoundingSphere)
Determines the distance between a BoundingSphere and a BoundingSphere.
Declaration
public static float DistanceSphereSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2)
Parameters
BoundingSphere
sphere1
The first sphere to test. |
BoundingSphere
sphere2
The second sphere to test. |
Returns
System.Single
The distance between the two objects. |
IsPointInTriangle(ref Float2, ref Float2, ref Float2, ref Float2)
Determines whether the given 2D point is inside the specified triangle.
Declaration
public static bool IsPointInTriangle(ref Float2 point, ref Float2 a, ref Float2 b, ref Float2 c)
Parameters
Float2
point
The point to check. |
Float2
a
The first vertex of the triangle. |
Float2
b
The second vertex of the triangle. |
Float2
c
The third vertex of the triangle. |
Returns
System.Boolean
|
LineIntersectsLine(ref Float2, ref Float2, ref Float2, ref Float2)
Determines whether a line intersects with the other line.
Declaration
public static bool LineIntersectsLine(ref Float2 l1p1, ref Float2 l1p2, ref Float2 l2p1, ref Float2 l2p2)
Parameters
Float2
l1p1
The first line point 0. |
Float2
l1p2
The first line point 1. |
Float2
l2p1
The second line point 0. |
Float2
l2p2
The second line point 1. |
Returns
System.Boolean
True if line intersects with the other line |
LineIntersectsRect(ref Float2, ref Float2, ref Rectangle)
Determines whether a line intersects with the rectangle.
Declaration
public static bool LineIntersectsRect(ref Float2 p1, ref Float2 p2, ref Rectangle rect)
Parameters
Float2
p1
The line point 0. |
Float2
p2
The line point 1. |
Rectangle
rect
The rectangle. |
Returns
System.Boolean
True if line intersects with the rectangle |
PlaneIntersectsBox(ref Plane, ref BoundingBox)
Determines whether there is an intersection between a Plane and a BoundingBox.
Declaration
public static PlaneIntersectionType PlaneIntersectsBox(ref Plane plane, ref BoundingBox box)
Parameters
Plane
plane
The plane to test. |
BoundingBox
box
The box to test. |
Returns
PlaneIntersectionType
Whether the two objects intersected. |
PlaneIntersectsPlane(ref Plane, ref Plane)
Declaration
public static bool PlaneIntersectsPlane(ref Plane plane1, ref Plane plane2)
Parameters
Plane
plane1
The first plane to test. |
Plane
plane2
The second plane to test. |
Returns
System.Boolean
Whether the two objects intersected. |
PlaneIntersectsPlane(ref Plane, ref Plane, out Ray)
Declaration
public static bool PlaneIntersectsPlane(ref Plane plane1, ref Plane plane2, out Ray line)
Parameters
Plane
plane1
The first plane to test. |
Plane
plane2
The second plane to test. |
Ray
line
When the method completes, contains the line of intersection as a Ray, or a zero ray if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersected. |
Remarks
Although a ray is set to have an origin, the ray returned by this method is really a line in three dimensions which has no real origin. The ray is considered valid when both the positive direction is used and when the negative direction is used.
PlaneIntersectsPoint(ref Plane, ref Vector3)
Determines whether there is an intersection between a Plane and a point.
Declaration
public static PlaneIntersectionType PlaneIntersectsPoint(ref Plane plane, ref Vector3 point)
Parameters
Plane
plane
The plane to test. |
Vector3
point
The point to test. |
Returns
PlaneIntersectionType
Whether the two objects intersected. |
PlaneIntersectsSphere(ref Plane, ref BoundingSphere)
Determines whether there is an intersection between a Plane and a BoundingSphere.
Declaration
public static PlaneIntersectionType PlaneIntersectsSphere(ref Plane plane, ref BoundingSphere sphere)
Parameters
Plane
plane
The plane to test. |
BoundingSphere
sphere
The sphere to test. |
Returns
PlaneIntersectionType
Whether the two objects intersected. |
PlaneIntersectsTriangle(ref Plane, ref Vector3, ref Vector3, ref Vector3)
Determines whether there is an intersection between a Plane and a triangle.
Declaration
public static PlaneIntersectionType PlaneIntersectsTriangle(ref Plane plane, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
Parameters
Plane
plane
The plane to test. |
Vector3
vertex1
The first vertex of the triangle to test. |
Vector3
vertex2
The second vertex of the triangle to test. |
Vector3
vertex3
The third vertex of the triangle to test. |
Returns
PlaneIntersectionType
Whether the two objects intersected. |
RayIntersectsBox(ref Ray, ref BoundingBox, out Vector3)
Declaration
public static bool RayIntersectsBox(ref Ray ray, ref BoundingBox box, out Vector3 point)
Parameters
Ray
ray
The ray to test. |
BoundingBox
box
The box to test. |
Vector3
point
When the method completes, contains the point of intersection, or Zero if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersected. |
RayIntersectsBox(ref Ray, ref BoundingBox, out Single)
Determines whether there is an intersection between a Ray and a BoundingBox.
Declaration
public static bool RayIntersectsBox(ref Ray ray, ref BoundingBox box, out float distance)
Parameters
Ray
ray
The ray to test. |
BoundingBox
box
The box to test. |
System.Single
distance
When the method completes, contains the distance of the intersection, or 0 if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersected. |
RayIntersectsPlane(ref Ray, ref Plane, out Vector3)
Declaration
public static bool RayIntersectsPlane(ref Ray ray, ref Plane plane, out Vector3 point)
Parameters
Ray
ray
The ray to test. |
Plane
plane
The plane to test |
Vector3
point
When the method completes, contains the point of intersection, or Zero if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersected. |
RayIntersectsPlane(ref Ray, ref Plane, out Single)
Declaration
public static bool RayIntersectsPlane(ref Ray ray, ref Plane plane, out float distance)
Parameters
Ray
ray
The ray to test. |
Plane
plane
The plane to test. |
System.Single
distance
When the method completes, contains the distance of the intersection, or 0 if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersect. |
RayIntersectsPoint(ref Ray, ref Vector3)
Determines whether there is an intersection between a Ray and a point.
Declaration
public static bool RayIntersectsPoint(ref Ray ray, ref Vector3 point)
Parameters
Ray
ray
The ray to test. |
Vector3
point
The point to test. |
Returns
System.Boolean
Whether the two objects intersect. |
RayIntersectsRay(ref Ray, ref Ray, out Vector3)
Declaration
public static bool RayIntersectsRay(ref Ray ray1, ref Ray ray2, out Vector3 point)
Parameters
Ray
ray1
The first ray to test. |
Ray
ray2
The second ray to test. |
Vector3
point
When the method completes, contains the point of intersection, or Zero if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersect. |
Remarks
This method performs a ray vs ray intersection test based on the following formula from Goldman.
s = det([o_2 - o_1, d_2, d_1 x d_2]) / ||d_1 x d_2||^2
t = det([o_2 - o_1, d_1, d_1 x d_2]) / ||d_1 x d_2||^2
Where o_1 is the position of the first ray, o_2 is the position of the second ray, d_1 is the normalized direction of the first ray, d_2 is the normalized direction of the second ray, det denotes the determinant of a matrix, x denotes the cross product, [ ] denotes a matrix, and || || denotes the length or magnitude of a vector.
RayIntersectsSphere(ref Ray, ref BoundingSphere, out Vector3)
Determines whether there is an intersection between a Ray and a BoundingSphere.
Declaration
public static bool RayIntersectsSphere(ref Ray ray, ref BoundingSphere sphere, out Vector3 point)
Parameters
Ray
ray
The ray to test. |
BoundingSphere
sphere
The sphere to test. |
Vector3
point
When the method completes, contains the point of intersection, or Zero if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersected. |
RayIntersectsSphere(ref Ray, ref BoundingSphere, out Single)
Determines whether there is an intersection between a Ray and a BoundingSphere.
Declaration
public static bool RayIntersectsSphere(ref Ray ray, ref BoundingSphere sphere, out float distance)
Parameters
Ray
ray
The ray to test. |
BoundingSphere
sphere
The sphere to test. |
System.Single
distance
When the method completes, contains the distance of the intersection, or 0 if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersected. |
RayIntersectsTriangle(ref Ray, ref Vector3, ref Vector3, ref Vector3, out Vector3)
Determines whether there is an intersection between a Ray and a triangle.
Declaration
public static bool RayIntersectsTriangle(ref Ray ray, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out Vector3 point)
Parameters
Ray
ray
The ray to test. |
Vector3
vertex1
The first vertex of the triangle to test. |
Vector3
vertex2
The second vertex of the triangle to test. |
Vector3
vertex3
The third vertex of the triangle to test. |
Vector3
point
When the method completes, contains the point of intersection, or Zero if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersected. |
RayIntersectsTriangle(ref Ray, ref Vector3, ref Vector3, ref Vector3, out Single)
Determines whether there is an intersection between a Ray and a triangle.
Declaration
public static bool RayIntersectsTriangle(ref Ray ray, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out float distance)
Parameters
Ray
ray
The ray to test. |
Vector3
vertex1
The first vertex of the triangle to test. |
Vector3
vertex2
The second vertex of the triangle to test. |
Vector3
vertex3
The third vertex of the triangle to test. |
System.Single
distance
When the method completes, contains the distance of the intersection, or 0 if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersected. |
Remarks
This method tests if the ray intersects either the front or back of the triangle. If the ray is parallel to the triangle's plane, no intersection is assumed to have happened. If the intersection of the ray and the triangle is behind the origin of the ray, no intersection is assumed to have happened. In both cases of assumptions, this method returns false.
SphereContainsBox(ref BoundingSphere, ref BoundingBox)
Determines whether a BoundingSphere contains a BoundingBox.
Declaration
public static ContainmentType SphereContainsBox(ref BoundingSphere sphere, ref BoundingBox box)
Parameters
BoundingSphere
sphere
The sphere to test. |
BoundingBox
box
The box to test. |
Returns
ContainmentType
The type of containment the two objects have. |
SphereContainsPoint(ref BoundingSphere, ref Vector3)
Determines whether a BoundingSphere contains a point.
Declaration
public static ContainmentType SphereContainsPoint(ref BoundingSphere sphere, ref Vector3 point)
Parameters
BoundingSphere
sphere
The sphere to test. |
Vector3
point
The point to test. |
Returns
ContainmentType
The type of containment the two objects have. |
SphereContainsSphere(ref BoundingSphere, ref BoundingSphere)
Determines whether a BoundingSphere contains a BoundingSphere.
Declaration
public static ContainmentType SphereContainsSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2)
Parameters
BoundingSphere
sphere1
The first sphere to test. |
BoundingSphere
sphere2
The second sphere to test. |
Returns
ContainmentType
The type of containment the two objects have. |
SphereContainsTriangle(ref BoundingSphere, ref Vector3, ref Vector3, ref Vector3)
Determines whether a BoundingSphere contains a triangle.
Declaration
public static ContainmentType SphereContainsTriangle(ref BoundingSphere sphere, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
Parameters
BoundingSphere
sphere
The sphere to test. |
Vector3
vertex1
The first vertex of the triangle to test. |
Vector3
vertex2
The second vertex of the triangle to test. |
Vector3
vertex3
The third vertex of the triangle to test. |
Returns
ContainmentType
The type of containment the two objects have. |
SphereIntersectsSphere(ref BoundingSphere, ref BoundingSphere)
Determines whether there is an intersection between a BoundingSphere and a BoundingSphere.
Declaration
public static bool SphereIntersectsSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2)
Parameters
BoundingSphere
sphere1
First sphere to test. |
BoundingSphere
sphere2
Second sphere to test. |
Returns
System.Boolean
Whether the two objects intersected. |
SphereIntersectsTriangle(ref BoundingSphere, ref Vector3, ref Vector3, ref Vector3)
Determines whether there is an intersection between a BoundingSphere and a triangle.
Declaration
public static bool SphereIntersectsTriangle(ref BoundingSphere sphere, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
Parameters
BoundingSphere
sphere
The sphere to test. |
Vector3
vertex1
The first vertex of the triangle to test. |
Vector3
vertex2
The second vertex of the triangle to test. |
Vector3
vertex3
The third vertex of the triangle to test. |
Returns
System.Boolean
Whether the two objects intersected. |