Java 类com.badlogic.gdx.math.EarClippingTriangulator 实例源码

项目:LD38-Compo    文件:TileData.java   
public void setColor(int color) {
    Pixmap pix = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    pix.setColor(color);
    pix.fill();
    Texture tex = new Texture(pix);
    TextureRegion region = new TextureRegion(tex);

    Point p1 = (Point) parent.getPoints().toArray()[0];
    Point p2 = (Point) parent.getPoints().toArray()[1];
    Point p3 = (Point) parent.getPoints().toArray()[2];
    Point p4 = (Point) parent.getPoints().toArray()[3];
    Point p5 = (Point) parent.getPoints().toArray()[4];
    Point p6 = (Point) parent.getPoints().toArray()[5];

    float[] vertices = new float[]{(
            float) p1.getCoordinateX(), (float)p1.getCoordinateY(),
            (float)p2.getCoordinateX(), (float)p2.getCoordinateY(),
            (float)p3.getCoordinateX(), (float)p3.getCoordinateY(),
            (float) p4.getCoordinateX(), (float)p4.getCoordinateY(),
            (float)p5.getCoordinateX(), (float)p5.getCoordinateY(),
            (float)p6.getCoordinateX(), (float)p6.getCoordinateY()};
    EarClippingTriangulator triangulator = new EarClippingTriangulator();
    ShortArray triangleIndices = triangulator.computeTriangles(vertices);
    PolygonRegion polygonRegion = new PolygonRegion(region, vertices, triangleIndices.toArray());
    sprite = new PolygonSprite(polygonRegion);
}
项目:NoRiskNoFun    文件:GameObjectMap.java   
private void initPolygonRegions() {

        polygonRegions = new ArrayList<>(assetMap.getRegions().size());


        for (AssetMap.Region region : assetMap.getRegions()) {
            PolygonRegion polyReg = new PolygonRegion(new TextureRegion(texture),
                    region.getVertices(),
                    new EarClippingTriangulator().computeTriangles(region.getVertices()).toArray());

            regionMap.put(region, polyReg);
            regionNameMap.put(region.getName(), region);
            polygonRegions.add(polyReg);
        }
    }
项目:evilrain    文件:Ground.java   
@Override
public void prepareActor() {
    float[] verticesFloat = new float[vertices.size() * 2];
    for(int i = 0; i < vertices.size(); i++) {
        verticesFloat[i*2] = vertices.get(i).x;
        verticesFloat[i*2+1] = vertices.get(i).y;
    }

    PolygonRegion polyReg = new PolygonRegion(textureRegion, verticesFloat,
            new EarClippingTriangulator().computeTriangles(verticesFloat).toArray());

    poly = new PolygonSprite(polyReg);
    poly.setOrigin(200, 200);
}
项目:DreamsLibGdx    文件:Box2DMapObjectParser.java   
/**
 * creates {@link Fixture Fixtures} from a {@link MapObject}
 *
 * @param mapObject the {@link MapObject} to parse
 * @return an array of parsed {@link Fixture Fixtures}
 */
public Fixture[] createFixtures(MapObject mapObject) {
    Polygon polygon;

    if (!(mapObject instanceof PolygonMapObject) || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon()))
        return new Fixture[]{createFixture(mapObject)};

    Polygon[] convexPolygons;
    if (triangulate) {
        if (areVerticesClockwise(polygon)) { // ensure the vertices are in counterclockwise order (not really necessary according to EarClippingTriangulator's javadoc, but sometimes better)
            Array<Vector2> vertices = new Array<Vector2>(toVector2Array(polygon.getVertices()));
            Vector2 first = vertices.removeIndex(0);
            vertices.reverse();
            vertices.insert(0, first);
            polygon.setVertices(toFloatArray(vertices.items));
        }
        convexPolygons = toPolygonArray(toVector2Array(new EarClippingTriangulator().computeTriangles(polygon.getTransformedVertices()).toArray()), 3);
    } else {
        Array<Array<Vector2>> convexPolys = BayazitDecomposer.convexPartition(new Array<Vector2>(toVector2Array(polygon.getTransformedVertices())));
        convexPolygons = new Polygon[convexPolys.size];
        for (int i = 0; i < convexPolygons.length; i++)
            convexPolygons[i] = new Polygon(toFloatArray((Vector2[]) convexPolys.get(i).toArray(Vector2.class)));
    }

    // create the fixtures using the convex polygons
    Fixture[] fixtures = new Fixture[convexPolygons.length];
    for (int i = 0; i < fixtures.length; i++) {
        PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]);
        convexObject.setColor(mapObject.getColor());
        convexObject.setName(mapObject.getName());
        convexObject.setOpacity(mapObject.getOpacity());
        convexObject.setVisible(mapObject.isVisible());
        convexObject.getProperties().putAll(mapObject.getProperties());
        fixtures[i] = createFixture(convexObject);
    }

    return fixtures;
}
项目:mini2Dx    文件:Polygon.java   
/**
 * Constructor. Note that vertices must be in a clockwise order for
 * performance and accuracy.
 * 
 * @param vertices
 *            All points in x,y pairs. E.g. x1,y1,x2,y2,etc.
 */
public Polygon(float[] vertices) {
    super();
    this.vertices = vertices;

    triangulator = new EarClippingTriangulator();
    getNumberOfSides();
}
项目:fabulae    文件:FilledPolygonRenderer.java   
protected PolygonRegion createdPolygonRegion(TextureRegion pixel, float[] vertices) {
    return new PolygonRegion(pixel, vertices,
            new EarClippingTriangulator().computeTriangles(vertices)
            .toArray());
}