The CollisionUtils object provides an interface to the Physics2D collision detection routines, this object can be constructed seperately and used without any physics.
A CollisionUtils object can be constructed with Physics2DDevice.createCollisionUtils.
Summary
Determine if the given point in world coordinates is contained within the given Shape.
Syntax
var result = collisionUtils.containsPoint(shape, point);
The shape to test point containment.
This shape must be assigned to a RigidBody object to define it’s position and rotation in world coordinates.
Summary
Determine the signed distance between two Shape objects, together with the witness points and axis between them.
Syntax
var witnessA = [];
var witnessB = [];
var axis = [];
var distance = collisionUtils.signedDistance(shapeA, shapeB, witnessA, witnessB, axis);
The first shape in distance query.
This shape must be assigned to a RigidBody object to define it’s position and rotation in world coordinates.
The second shape in distance query.
This shape must be assigned to a RigidBody object to define it’s position and rotation in world coordinates.
In the case that the two shapes are seperating (positive distance), the witness points will correspond to the closest points between the two shapes, and the axis corresponding to the seperating axis from shapeA to shapeB.
In the case that the two shapes are penetrating (negative distance), the witness points and axis will correspond to the MTV (Minimum translational vector) for the two shapes from shapeA to shapeB.
Summary
Determine if two Shape objects are intersecting.
Syntax
var result = collisionUtils.intersects(shapeA, shapeB);
The first shape to test intersection with.
This shape must be assigned to a RigidBody object to define it’s position and rotation in world coordinates.
The second shape to test intersection with.
This shape must be assigned to a RigidBody object to define it’s position and rotation in world coordinates.
Summary
Determine the intersection of a given Shape and parametric ray.
Syntax
var normal = [];
var ray = {
origin : [-1, 0],
direction : [10, 0],
maxFactor : 1
};
var ignoreInnerSurfaces = false;
var factor = collisionUtils.rayTest(shape, ray, normal, ignoreInnerSurfaces);
The shape to test ray intersection with.
This shape must be assigned to a RigidBody object to define it’s position and rotation in world coordinates.
The parametric ray to test for intersection with.
The ray will not be cast beyond its maxFactor.
When true, the ray will not be intersected against the inner surfaces of a shape.
Default value is false.
This method returns either undefined indicating that no intersection occured, or the factor of the intersection with which one can compute the intersection point using:
mathDevice.v2AddScalarMul(ray.origin, ray.direction, factor);
Summary
Determine the time of impact between two Shape objects with point of impact and normal.
Syntax
var point = [];
var normal = [];
var timeOfImpact = collisionUtils.sweepTest(shapeA, shapeB, deltaTime, point, normal);
The first shape to be swept for time of impact.
This shape must be assigned to a RigidBody object to define it’s position and rotation in world coordinates, with the body velocities used to define the sweep for this shape.
The second shape to be swept for time of impact.
This shape must be assigned to a RigidBody object to define it’s position and rotation in world coordinates, with the body velocities used to define the sweep for this shape.
The amount of time in seconds through which the shapes will be swept before returning with failure.
This value should be strictly positive.
This method returns either undefined indicating that no collision occured in the given time frame, or the time of impact of the collision.