|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.phys2d.raw.collide.PenetrationSweep
This class will, given an intersection pair (an ingoing and outgoing intersection), calculate the penetration depth. This is the minimum distance that A and B need to be separated to get rid of any overlap.
The penetration depth or separation is calculated by running a sweepline between the two points of an intersection pair. We keep track of the upper bound defined by edges of polygon A and the lower bound defined by B. The maximum distance between these bounds is the value we are searching for.
-<---- |B | | | out| |in -----+--.---+------- |A | ! / | | \ ! / | | \!/ | | . | ->------------------
The sweepline always runs from the ingoing to the outgoing intersection. Usually the normal is perpendicular to the sweepline.
We cannot always use the whole intersection area. Take a look at the following example. If we would allow the vertex marked with to be included in the sweep, the penetration depth would be far too big. Therefore we 'cut off' the intersection area with two lines through the intersection points perpendicular to the sweep direction. Unfortunately this will break the algorithm for collision normals other than those perpendicular to the sweepline (it's should still be usable). The lines are called the borders of the intersection area.
+--/---/---------------------* +-|-/-+ / A | \|/ B|/ | x / | /|\ /| | +-x--------------------------+ / \|Convexity
This algorithm should always work well for convex intersection areas. When the intersection area is not convex, the resulting separation might be erroneous.
Since colliding two convex polygons will always result in convex intersection areas, they should be used if possible. Colliding non-convex polygons seems to work pretty well in practice too, but more testing is needed.
Nested Class Summary | |
class |
PenetrationSweep.ContourWalker
The contour walker walks over the edges or vertices of a polygon. |
Constructor Summary | |
PenetrationSweep(Vector2f normal,
Vector2f sweepDir,
Vector2f intersectionStart,
Vector2f intersectionEnd)
Constructs a Penetration Sweep object, with all its attributes set. |
Method Summary | |
static float |
getPenetrationDepth(Intersection in,
Intersection out,
Vector2f normal,
Vector2f[] vertsA,
Vector2f[] vertsB)
Given two intersecting polygons, the intersection points and a collision normal, get the maximum penetration distance along the normal. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PenetrationSweep(Vector2f normal, Vector2f sweepDir, Vector2f intersectionStart, Vector2f intersectionEnd)
getPenetrationDepth(Intersection, Intersection, Vector2f, Vector2f[], Vector2f[])
should be called to get the penetration depth.
normal
- The collision normalsweepDir
- The sweep directionintersectionStart
- The start bound of the intersection areaintersectionEnd
- The end bound of the intersection area.Method Detail |
public static float getPenetrationDepth(Intersection in, Intersection out, Vector2f normal, Vector2f[] vertsA, Vector2f[] vertsB)
in
- The ingoing intersectionout
- The outgoing intersectionnormal
- The collision normalvertsA
- The vertices of polygon AvertsB
- The vertices of polygon B
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |