Example usage for com.badlogic.gdx.utils MathUtils degreesToRadians

List of usage examples for com.badlogic.gdx.utils MathUtils degreesToRadians

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils MathUtils degreesToRadians.

Prototype

float degreesToRadians

To view the source code for com.badlogic.gdx.utils MathUtils degreesToRadians.

Click Source Link

Usage

From source file:com.cmein.tilemap.utils.TexturePacker.java

License:Apache License

private int insert(BufferedImage canvas, ArrayList<Image> images, int width, int height) throws IOException {
    if (settings.debug && canvas != null) {
        Graphics g = canvas.getGraphics();
        g.setColor(Color.green);/*from www.  j a  v a 2s . co m*/
        g.drawRect(0, 0, width - 1, height - 1);
    }
    // Pretend image is larger so padding on right and bottom edges is ignored.
    if (!filter.direction.isX())
        width += xPadding;
    if (!filter.direction.isY())
        height += yPadding;
    Node root = new Node(0, 0, width, height);
    int usedPixels = 0;
    for (int i = images.size() - 1; i >= 0; i--) {
        Image image = images.get(i);
        Node node = root.insert(image, false);
        if (node == null) {
            if (settings.rotate)
                node = root.insert(image, true);
            if (node == null)
                continue;
        }
        usedPixels += image.getWidth() * image.getHeight();
        images.remove(i);
        if (canvas != null) {
            node.writePackEntry();
            Graphics2D g = (Graphics2D) canvas.getGraphics();
            if (image.rotate) {
                g.translate(node.left, node.top);
                g.rotate(-90 * MathUtils.degreesToRadians);
                g.translate(-node.left, -node.top);
                g.translate(-image.getWidth(), 0);
            }
            if (settings.duplicatePadding) {
                int amount = settings.padding / 2;
                int imageWidth = image.getWidth();
                int imageHeight = image.getHeight();
                g.drawImage(image, node.left, node.top - amount, node.left + imageWidth, node.top, 0, 0,
                        imageWidth, 1, null);
                g.drawImage(image, node.left, node.top + imageHeight, node.left + imageWidth,
                        node.top + imageHeight + amount, 0, imageHeight - 1, imageWidth, imageHeight, null);
                g.drawImage(image, node.left - amount, node.top, node.left, node.top + imageHeight, 0, 0, 1,
                        imageHeight, null);
                g.drawImage(image, node.left + imageWidth, node.top, node.left + imageWidth + amount,
                        node.top + imageHeight, imageWidth - 1, 0, imageWidth, imageHeight, null);
            }
            g.drawImage(image, node.left, node.top, null);
            if (image.rotate) {
                g.translate(image.getWidth(), 0);
                g.translate(node.left, node.top);
                g.rotate(90 * MathUtils.degreesToRadians);
                g.translate(-node.left, -node.top);
            }
            if (settings.debug) {
                g.setColor(Color.magenta);
                int imageWidth = image.getWidth();
                int imageHeight = image.getHeight();
                if (image.rotate)
                    g.drawRect(node.left, node.top, imageHeight - 1, imageWidth - 1);
                else
                    g.drawRect(node.left, node.top, imageWidth - 1, imageHeight - 1);
            }
        }
    }
    return images.isEmpty() ? -1 : usedPixels;
}