Geom
nape.geom.Geom (final class)
Geom class provides interface to collision detection routines in nape.
Static Members
nape
distanceBody(body1: nape.phys.Body, body2: nape.phys.Body, out1: Vec2, out2: Vec2): Float
Determine distance and closest points between two Bodies.
If the bodies are intersecting, then a negative value is returned
equal to the penetration of the bodies, and the out1/out2 vectors
will still be meaningful with their difference being the minimum
translational vector to seperate the intersecting shapes of the bodies.
(This may not be a global seperation vector as it is considering only
one pair of shapes at a time).
As the out1/out2 vectors are used to return values from the function,
this is one of the rare cases where should out1/out2 be weak Vec2's
they will 'not' be sent to the global object pool on being passed to
this function.
var closest1 = Vec2.get();
var closest2 = Vec2.get();
var distance = Geom.distanceBody(body1, body2, out1, out2);
if (distance < 0) {
trace("Bodies intersect and penetration distance is " +
(-distance) + " with witness points " + closest1.toString() +
" <-> " + closest2.toString());
}else {
trace("Bodies do not intersect and distance betweem them is " +
distance + " with closest points " + closest1.toString() +
" <-> " + closest2.toString());
}
This algorithm is able to take shortcuts in culling pair tests between Shapes
based on the current state of the search, and will be more effecient than
a custom implementation that uses Geom.distance(..) method.
Name |
Type |
Description |
body1 |
nape.phys.Body |
First input Body. |
body2 |
nape.phys.Body |
Second input Body. |
out1 |
Vec2 |
This Vec2 object will be populated with coordinates of closest point on body1. |
out2 |
Vec2 |
This Vec2 object will be populated with coordinates of closest point on body2. |
Returns |
Description |
Float |
The distance between the two bodies if seperated, or the penetration distance (negative) if intersecting. |
Determine distance and closest points between two Shapes.
The input Shapes must belong to a Body so that their world positions
and orientations are defined; these Bodies need not be different nor
part of any Space.
If the shapes are intersecting, then a negative value is returned
equal to the penetration of the shapes, and the out1/out2 vectors
will still be meaningful with their difference being the minimum
translational vector to seperate the Shapes.
As the out1/out2 vectors are used to return values from the function,
this is one of the rare cases where should out1/out2 be weak Vec2's
they will 'not' be sent to the global object pool on being passed to
this function.
var closest1 = Vec2.get();
var closest2 = Vec2.get();
var distance = Geom.distance(shape1, shape2, out1, out2);
if (distance < 0) {
trace("Shapes intersect and penetration distance is " +
(-distance) + " with witness points " + closest1.toString() +
" <-> " + closest2.toString());
}else {
trace("Shapes do not intersect and distance betweem them is " +
distance + " with closest points " + closest1.toString() +
" <-> " + closest2.toString());
}
Name |
Type |
Description |
shape1 |
nape.shape.Shape |
this shape must belong to a Body. |
shape2 |
nape.shape.Shape |
this shape must belong to a Body. |
out1 |
Vec2 |
This Vec2 object will be populated with coordinates of closest point on shape1. |
out2 |
Vec2 |
This Vec2 object will be populated with coordinates of closest point on shape2. |
Returns |
Description |
Float |
The distance between the two shapes if seperated, or the penetration distance (negative) if intersecting. |
nape
intersectsBody(body1: nape.phys.Body, body2: nape.phys.Body): Bool
Determine if two Bodies intersect.
If you do not need distance/penetration information,
then using this method will be more effecient than testing for a negative
value using the distance method.
Returns |
Description |
Bool |
True if the Bodies are intersecting. |
Determine if two Shapes intersect.
The input Shapes must belong to a Body so that their world positions
and orientations are defined; these Bodies need not be different nor
part of any Space.
If you do not need distance/penetration information,
then using this method will be more effecient than testing for a negative
value using the distance method.
Returns |
Description |
Bool |
True if the shapes are intersecting in world space. |
Determine if one Shape is entirely contained within another.
The input Shapes must belong to a Body so that their world positions
and orientations are defined; these Bodies need not be different nor
part of any Space.
Returns |
Description |
Bool |
True if shape2 is completely contained within shape1. |