mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[libgdx] Clipper assumes counter clockwise order, easier to adapt decomposition algorithm that way
This commit is contained in:
parent
a665b0e598
commit
dc53f8d293
@ -137,7 +137,7 @@ public class SoftwareClippingTest extends ApplicationAdapter {
|
||||
// edge normals
|
||||
shapes.setColor(Color.YELLOW);
|
||||
if (clippingPolygon.size > 2) {
|
||||
boolean clockwise = SutherlandHodgmanClipper.clockwise(clippingPolygon);
|
||||
boolean clockwise = SutherlandHodgmanClipper.counterClockwise(clippingPolygon);
|
||||
for (int i = 0; i < clippingPolygon.size; i += 2) {
|
||||
float x = clippingPolygon.get(i);
|
||||
float y = clippingPolygon.get(i + 1);
|
||||
@ -183,7 +183,7 @@ public class SoftwareClippingTest extends ApplicationAdapter {
|
||||
|
||||
// must duplicate first vertex at end of polygon
|
||||
// so we can avoid module/branch in clipping code
|
||||
SutherlandHodgmanClipper.makeClockwise(clippingPolygon);
|
||||
SutherlandHodgmanClipper.makeCounterClockwise(clippingPolygon);
|
||||
clippingPolygon.add(clippingPolygon.get(0));
|
||||
clippingPolygon.add(clippingPolygon.get(1));
|
||||
|
||||
|
||||
@ -406,9 +406,9 @@ public class SkeletonRenderer {
|
||||
int n = clip.getWorldVerticesLength();
|
||||
float[] vertices = this.clippingArea.setSize(n);
|
||||
clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
|
||||
clippingAreaClockwise = SutherlandHodgmanClipper.clockwise(this.clippingArea);
|
||||
clippingAreaClockwise = SutherlandHodgmanClipper.counterClockwise(this.clippingArea);
|
||||
if (!clippingAreaClockwise) {
|
||||
SutherlandHodgmanClipper.makeClockwise(clippingArea);
|
||||
SutherlandHodgmanClipper.makeCounterClockwise(clippingArea);
|
||||
}
|
||||
clippingArea.add(clippingArea.items[0]);
|
||||
clippingArea.add(clippingArea.items[1]);
|
||||
|
||||
@ -35,10 +35,10 @@ public class SutherlandHodgmanClipper {
|
||||
final float[] clippingVertices = clippingArea.items;
|
||||
final int clippingVerticesLength = clippingArea.size - 2;
|
||||
for (int i = 0; i < clippingVerticesLength; i += 2) {
|
||||
float edgeX = clippingVertices[i];
|
||||
float edgeY = clippingVertices[i + 1];
|
||||
float edgeX2 = clippingVertices[i + 2];
|
||||
float edgeY2 = clippingVertices[i + 3];
|
||||
float edgeX2 = clippingVertices[i];
|
||||
float edgeY2 = clippingVertices[i + 1];
|
||||
float edgeX = clippingVertices[i + 2];
|
||||
float edgeY = clippingVertices[i + 3];
|
||||
|
||||
final float deltaX = edgeX - edgeX2;
|
||||
final float deltaY = edgeY - edgeY2;
|
||||
@ -129,8 +129,8 @@ public class SutherlandHodgmanClipper {
|
||||
return clipped;
|
||||
}
|
||||
|
||||
public static void makeClockwise (FloatArray poly) {
|
||||
if (clockwise(poly)) return;
|
||||
public static void makeCounterClockwise (FloatArray poly) {
|
||||
if (counterClockwise(poly)) return;
|
||||
|
||||
int lastX = poly.size - 2;
|
||||
final float[] polygon = poly.items;
|
||||
@ -145,8 +145,8 @@ public class SutherlandHodgmanClipper {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean clockwise (FloatArray poly) {
|
||||
return area(poly) < 0;
|
||||
public static boolean counterClockwise (FloatArray poly) {
|
||||
return area(poly) > 0;
|
||||
}
|
||||
|
||||
public static float area (FloatArray poly) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user