List of usage examples for com.badlogic.gdx.maps.objects PolygonMapObject getProperties
public MapProperties getProperties()
From source file:com.rubentxu.juegos.core.utils.dermetfan.box2d.Box2DMapObjectParser.java
License:Apache License
/** * creates {@link Fixture Fixtures} from a {@link MapObject} * * @param mapObject the {@link MapObject} to parse * @return an array of parsed {@link Fixture Fixtures} *///from ww w . j av a2s. com 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; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** creates {@link Fixture Fixtures} from a {@link MapObject} * @param mapObject the {@link MapObject} to parse * @param body the {@link Body} to create the {@link Fixture Fixtures} on * @return an array of parsed {@link Fixture Fixtures} */ public Fixture[] createFixtures(MapObject mapObject, Body body) { if ((mapObject = listener.createFixtures(mapObject)) == null) return null; Polygon polygon;//from ww w. j av a 2 s . co m if (!(mapObject instanceof PolygonMapObject) || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon()) && (!Box2DUtils.checkPreconditions || polygon.getVertices().length / 2 <= Box2DUtils.maxPolygonVertices)) return new Fixture[] { createFixture(mapObject, body) }; Polygon[] convexPolygons = triangulate ? triangulate(polygon) : decompose(polygon); 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, body); } return fixtures; }
From source file:headmade.arttag.utils.MapUtils.java
License:Apache License
private static void createConeLight(ArtTagScreen artTagScreen, PolygonMapObject mapObject, float unitScale) { final Polygon poly = mapObject.getPolygon(); Float objRot = 0f;/*from w w w . j ava 2 s .co m*/ if (null != mapObject.getProperties()) { objRot = mapObject.getProperties().get("rotation", Float.class); } if (objRot == null) { objRot = 0f; } final float[] vertices = poly.getVertices();// getTransformedVertices(); if (vertices.length < 6) { Gdx.app.error(TAG, "Invalid Polygon for conelight. It has less than 3 vertices " + mapObject); return; } final Array<Vector2> vecs = new Array<Vector2>(); for (int i = 0; i < 6; i += 2) { vecs.add(new Vector2(vertices[i] * unitScale, vertices[i + 1] * unitScale)); } final Color color = getColor(mapObject); final Vector2 halfBetweenV1AndV2 = vecs.get(2).cpy().add(vecs.get(1).cpy().sub(vecs.get(2)).scl(0.5f)); final float length = vecs.get(2).dst(vecs.first()); final float angle = Math.abs(vecs.get(1).angle(vecs.get(2))); final float rotation = halfBetweenV1AndV2.cpy().sub(vecs.first()).angle() - objRot; // final float rotation = poly.getRotation(); // Gdx.app.log(TAG, "rotation " + rotation + " length: " + length + " angle:" + angle); final ConeLight light = new ConeLight(artTagScreen.rayHandler, ArtTag.gameSettings.rays, color, length, unitScale * poly.getX(), unitScale * poly.getY(), rotation, angle); light.setSoftnessLength(0.5f); light.setContactFilter(ArtTag.CAT_LIGHT, ArtTag.GROUP_LIGHT, ArtTag.MASK_LIGHT); artTagScreen.lights.add(light); }
From source file:net.dermetfan.gdx.physics.box2d.Box2DMapObjectParser.java
License:Apache License
/** creates {@link Fixture Fixtures} from a {@link MapObject} * @param mapObject the {@link MapObject} to parse * @param body the {@link Body} to create the {@link Fixture Fixtures} on * @return an array of parsed {@link Fixture Fixtures} */ public Fixture[] createFixtures(MapObject mapObject, Body body) { if ((mapObject = listener.createFixtures(mapObject)) == null) return null; Polygon polygon;// www . ja va2 s. co m if (!(mapObject instanceof PolygonMapObject) || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon()) && Box2DUtils.check.isValidPolygonShape(polygon.getVertices())) return new Fixture[] { createFixture(mapObject, body) }; Polygon[] convexPolygons = toPolygonArray(triangulate ? triangulate(polygon.getTransformedVertices()) : decompose(polygon.getTransformedVertices())); 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, body); } return fixtures; }
From source file:net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** creates {@link Fixture Fixtures} from a {@link MapObject} * @param mapObject the {@link MapObject} to parse * @param body the {@link Body} to create the {@link Fixture Fixtures} on * @return an array of parsed {@link Fixture Fixtures} */ public Fixture[] createFixtures(MapObject mapObject, Body body) { Polygon polygon;//from www. j ava 2 s . c om if (!(mapObject instanceof PolygonMapObject) || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon())) return new Fixture[] { createFixture(mapObject, body) }; 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 = triangulate(polygon); } else convexPolygons = decompose(polygon); // 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, body); } return fixtures; }