List of usage examples for com.badlogic.gdx.maps.objects PolygonMapObject getPolygon
public Polygon getPolygon()
From source file:com.siondream.core.physics.MapBodyManager.java
License:Open Source License
private Shape getPolygon(PolygonMapObject polygonObject) { PolygonShape polygon = new PolygonShape(); float[] vertices = polygonObject.getPolygon().getTransformedVertices(); float[] worldVertices = new float[vertices.length]; for (int i = 0; i < vertices.length; ++i) { worldVertices[i] = vertices[i] / units; }//from w ww . j a v a 2 s.c om polygon.set(worldVertices); return polygon; }
From source file:genuini.world.WorldManager.java
private PolygonShape getPolygon(PolygonMapObject polygonObject) { PolygonShape polygon = new PolygonShape(); 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] / PPM; }// www . j ava 2 s . c o m polygon.set(worldVertices); return polygon; }
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;// w w w. jav a 2s .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:rosthouse.rosty.loader.MapLoader.java
private void createPolygon(PolygonMapObject polygon, PhysicsSystem physicsSystem, Entity entity, boolean isSensor) { Polygon ply = polygon.getPolygon(); PolygonComponent plyCmp = new PolygonComponent(ply); ChainShape polygonShape = new ChainShape(); Vector2[] vertices = new Vector2[plyCmp.polygon.getVertices().length / 2]; for (int i = 0; i < plyCmp.polygon.getTransformedVertices().length; i += 2) { vertices[i / 2] = new Vector2(plyCmp.polygon.getVertices()[i], plyCmp.polygon.getVertices()[i + 1]); }//w w w. j a v a 2s . c o m try { polygonShape.createLoop(vertices); } catch (Exception e) { System.out.println(e.getMessage()); } FixtureDef fixtureDef = new FixtureDef(); fixtureDef.density = 0; fixtureDef.friction = 1; fixtureDef.restitution = 0.2f; PhysicsComponent<ChainShape> cmpPhys; if (isSensor) { cmpPhys = physicsSystem.createSensorComponent(BodyDef.BodyType.StaticBody, polygonShape, new Vector2(ply.getX(), ply.getY()), fixtureDef); } else { cmpPhys = physicsSystem.createPhysicsComponent(BodyDef.BodyType.StaticBody, polygonShape, new Vector2(ply.getX(), ply.getY()), fixtureDef); } entity.add(plyCmp); entity.add(cmpPhys); cmpPhys.fixture.setUserData(entity.getId()); }
From source file:se.angergard.game.util.Box2DUtils.java
License:Apache License
private static PolygonShape getPolygon(PolygonMapObject object) { PolygonShape shape = new PolygonShape(); float[] vertices = object.getPolygon().getTransformedVertices(); float[] worldVertices = new float[vertices.length]; for (int i = 0; i < vertices.length; ++i) { worldVertices[i] = Pixels.toMeters(vertices[i]); }/*www . ja v a 2s . com*/ shape.set(worldVertices); return shape; }