class nape.geom.Geom
Available on all platforms
Geom class provides interface to collision detection routines in nape.
Class Fields
static function contains(shape1:Shape, shape2:Shape):Bool
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.
*
*
shape1 | this shape must belong to a Body. * |
shape2 | this shape must belong to a Body. * |
returns | True if shape2 is completely contained within shape1. * |
static function distance(shape1:Shape, shape2:Shape, out1:Vec2, out2:Vec2):Float
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()); * } ** *
shape1 | this shape must belong to a Body. * |
shape2 | this shape must belong to a Body. * |
out1 | This Vec2 object will be populated with coordinates of * closest point on shape1. * |
out2 | This Vec2 object will be populated with coordinates of * closest point on shape2. * |
returns | The distance between the two shapes if seperated, or the penetration distance (negative) if intersecting. |
static function distanceBody(body1:Body, body2: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. * *
body1 | First input Body. * |
body2 | Second input Body. * |
out1 | This Vec2 object will be populated with coordinates of * closest point on body1. * |
out2 | This Vec2 object will be populated with coordinates of * closest point on body2. * |
returns | The distance between the two bodies if seperated, or the penetration distance (negative) if intersecting. |
static function intersects(shape1:Shape, shape2:Shape):Bool
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.
*
*
shape1 | this shape must belong to a Body. * |
shape2 | this shape must belong to a Body. * |
returns | True if the shapes are intersecting in world space. * |
static function intersectsBody(body1:Body, body2: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.
*
*
body1 | First input Body . * |
body2 | Second input Body. * |
returns | True if the Bodies are intersecting. * |