@@ 11,6 11,7 @@ import com.badlogic.gdx.graphics.glutils
import com.badlogic.gdx.math.Polygon;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.utils.UIUtils;
+import com.badlogic.gdx.utils.FloatArray;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import net.dermetfan.gdx.math.GeometryUtils;
@@ 21,6 22,7 @@ public class SutherlandHodgmanTest exten
ShapeRenderer sr = new ShapeRenderer();
Polygon polygon = new Polygon(new float[] {0, 0, 125f, 125f, 250, 0, 250, 250, 0, 500} /* ccw */), clipPolygon = new Polygon(new float[] {0, 0, 0, 250, 250, 250, 250, 0} /* cw */);
+ FloatArray clipped = new FloatArray(polygon.getVertices().length);
public SutherlandHodgmanTest() {
Vector2 centroid = new Vector2();
@@ 36,11 38,11 @@ public class SutherlandHodgmanTest exten
@Override
public boolean keyTyped(char character) {
if(character == 'c') {
- float[] clipped = GeometryUtils.clip(polygon.getTransformedVertices(), clipPolygon.getTransformedVertices());
+ GeometryUtils.clip(polygon.getTransformedVertices(), clipPolygon.getTransformedVertices(), clipped);
GeometryUtils.reset(polygon);
- polygon.setVertices(clipped);
+ polygon.setVertices(clipped.toArray());
Vector2 centroid = new Vector2();
- com.badlogic.gdx.math.GeometryUtils.polygonCentroid(clipped, 0, clipped.length, centroid);
+ com.badlogic.gdx.math.GeometryUtils.polygonCentroid(polygon.getVertices(), 0, polygon.getVertices().length, centroid);
polygon.setOrigin(centroid.x, centroid.y);
return true;
}