Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @param concave the concave PolygonShape to triangulate
- * @return an array of PolygonShape triangles describing the given concave PolygonShape
- * @see EarClippingTriangulator#computeTriangles(float[]) */
- public static PolygonShape[] triangulate(PolygonShape concave) {
- tmpVecArr = vertices(concave);
- ShortArray indices = new EarClippingTriangulator().computeTriangles(toFloatArray(tmpVecArr));
- PolygonShape[] convexes = new PolygonShape[indices.size / 6];
- Vector2[] tmpVecArr2 = new Vector2[3];
- for(int i = 0, ii = -1; i < convexes.length; i++) {
- convexes[i] = new PolygonShape();
- tmpVecArr2[0] = tmpVecArr[indices.get(++ii)];
- tmpVecArr2[1] = tmpVecArr[indices.get(++ii)];
- tmpVecArr2[2] = tmpVecArr[indices.get(++ii)];
- convexes[i].set(tmpVecArr2);
- }
- return convexes;
- }
- /** @param concave the concave PolygonShape to decompose
- * @return an array of PolygonShapes describing the given concave PolygonShape
- * @see BayazitDecomposer#convexPartition(Array) */
- public static PolygonShape[] decomposeIntoConvex(PolygonShape concave) {
- Array<Array<Vector2>> convexPolys = BayazitDecomposer.convexPartition(new Array<Vector2>(vertices(concave)));
- PolygonShape[] convexPolygons = new PolygonShape[convexPolys.size];
- for(int i = 0; i < convexPolygons.length; i++) {
- convexPolygons[i] = new PolygonShape();
- convexPolygons[i].set((Vector2[]) convexPolys.get(i).toArray(Vector2.class));
- }
- return convexPolygons;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement