나는 볼록한 다각형을 삼각형으로 만들려고한다. 오른쪽 삼각없이 볼록 다각형 동안 왼쪽에서 삼각형의 엉망진 삼각형
float[] vertices = polygonObject.getPolygon().getTransformedVertices();
float[] worldVertices = new float[vertices.length];
for (int i = 0; i < vertices.length; ++i) {
System.out.println(vertices[i]);
worldVertices[i] = vertices[i]/ppt;
}
// Make triangles
Vector<float[]> trianglesVertices = new Vector<float[]>();
EarClippingTriangulator triangulator = new EarClippingTriangulator();
ArrayList<PolygonShape> triangles = new ArrayList<PolygonShape>();
ShortArray pointsCoords = triangulator.computeTriangles(worldVertices);
for (int i = 0; i < pointsCoords.size/6; i++)
{
trianglesVertices.add(new float[] {
pointsCoords.get(i*6), pointsCoords.get(i*6 + 1),
pointsCoords.get(i*6 + 2), pointsCoords.get(i*6 + 3),
pointsCoords.get(i*6 + 4), pointsCoords.get(i*6 + 5),
});
PolygonShape triangleShape = new PolygonShape();
triangleShape.set(trianglesVertices.get(i));
triangles.add(triangleShape);
}
나중에 나는 그 arraylist를 반복하고 시체를 만들지 만, 어떻게 든 libgdx (아마 나, libgdx가 아님)가 완전히 엉망으로 만듭니다.
여기 for(PolygonShape triangle:triangles){
BodyDef bd = new BodyDef();
bd.type = BodyDef.BodyType.StaticBody;
Body body = world.createBody(bd);
body.createFixture(triangle, 1);
bodies.add(body);
triangle.dispose();
}
나는 또 다른 예를 발견하고는 일
을 주셔서 감사하다 질문을 편집했지만, libgdx 프레임 워크에서 EarClippingTriangulator 클래스를 사용하기 때문에 제목에 libgdx를 넣었습니다. 그 점을 언급하는 것이 중요하다고 생각했습니다. – Mars