Example usage for com.badlogic.gdx.math DelaunayTriangulator computeTriangles

List of usage examples for com.badlogic.gdx.math DelaunayTriangulator computeTriangles

Introduction

In this page you can find the example usage for com.badlogic.gdx.math DelaunayTriangulator computeTriangles.

Prototype

public ShortArray computeTriangles(float[] points, int offset, int count, boolean sorted) 

Source Link

Document

Triangulates the given point cloud to a list of triangle indices that make up the Delaunay triangulation.

Usage

From source file:io.piotrjastrzebski.dungen.DungeonGenerator.java

License:Apache License

private void triangulate() {
    DelaunayTriangulator triangulator = new DelaunayTriangulator();

    float[] points = new float[mainRooms.size * 2];
    for (int i = 0; i < points.length; i += 2) {
        Room room = mainRooms.get(i / 2);
        points[i] = room.cx();/*w  w  w.  j  a v  a  2  s  .  c  o m*/
        points[i + 1] = room.cy();
    }

    ShortArray indicies = triangulator.computeTriangles(points, 0, points.length, false);

    graph.clear();

    for (int i = 0; i < indicies.size; i += 3) {
        int p1 = indicies.get(i) * 2;
        int p2 = indicies.get(i + 1) * 2;
        int p3 = indicies.get(i + 2) * 2;
        // this is pretty dumb...
        Room roomA = getRoom(points[p1], points[p1 + 1]);
        Room roomB = getRoom(points[p2], points[p2 + 1]);
        Room roomC = getRoom(points[p3], points[p3 + 1]);
        graph.add(roomA, roomB);
        graph.add(roomA, roomC);
        graph.add(roomB, roomC);
    }

    createMST();
}