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

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

Introduction

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

Prototype

DelaunayTriangulator

Source Link

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();/*  ww  w . j a va  2s. 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();
}