List of usage examples for com.badlogic.gdx.math EarClippingTriangulator computeTriangles
public ShortArray computeTriangles(float[] vertices)
From source file:com.hajnar.GravityShip.GameObjects.Terrain.java
License:Apache License
public void generateMeshes() { ArrayList<Fixture> terrainFixtures = objectBody.getFixtureList(); Vector2 boxVertex = new Vector2(); meshes = new ArrayList<Mesh>(); boundingBoxes = new ArrayList<BoundingBox>(); EarClippingTriangulator ear = new EarClippingTriangulator(); for (Fixture terrainFixture : terrainFixtures) { PolygonShape shape = (PolygonShape) terrainFixture.getShape(); boxVertex = new Vector2(); int vc = shape.getVertexCount(); ArrayList<Vector2> boxVertices = new ArrayList<Vector2>(); ArrayList<Vector2> triaBoxVertices = new ArrayList<Vector2>(); for (int i = 0; i < vc; i++) { shape.getVertex(i, boxVertex); boxVertex = objectBody.getWorldPoint(boxVertex).mul(Helper.BOX_TO_WORLD); boxVertices.add(boxVertex.cpy()); }//ww w .ja v a2s . com triaBoxVertices = (ArrayList<Vector2>) ear.computeTriangles(boxVertices); float[] meshVertices = new float[triaBoxVertices.size() * 4]; short[] meshIndices = new short[triaBoxVertices.size()]; for (int i = 0; i < triaBoxVertices.size(); i++) { meshVertices[i * 4] = triaBoxVertices.get(i).x; meshVertices[i * 4 + 1] = triaBoxVertices.get(i).y; meshVertices[i * 4 + 2] = triaBoxVertices.get(i).x * TEXTURE_SCALE; meshVertices[i * 4 + 3] = triaBoxVertices.get(i).y * TEXTURE_SCALE; meshIndices[i] = (short) i; } Mesh mesh = new Mesh(true, triaBoxVertices.size(), triaBoxVertices.size(), new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); mesh.setVertices(meshVertices); mesh.setIndices(meshIndices); meshes.add(mesh); boundingBoxes.add(mesh.calculateBoundingBox()); } }
From source file:dk.gruppeseks.bodtrd.engine.Game.java
private void drawFoV(float[] shape) { EarClippingTriangulator triangulator = new EarClippingTriangulator(); ShortArray triangleIndices = triangulator.computeTriangles(shape); PolygonRegion polyReg = new PolygonRegion(_textureRegion, shape, triangleIndices.toArray()); PolygonSprite polySprite = new PolygonSprite(polyReg); _polyBatch.begin();//from w ww. j a v a2 s . co m polySprite.draw(_polyBatch); _polyBatch.end(); _shapeRenderer.setProjectionMatrix(_gameCamera.combined); _shapeRenderer.begin(ShapeType.Line); _shapeRenderer.setColor(Color.BROWN); _shapeRenderer.polygon(shape); _shapeRenderer.end(); }