Example usage for java.awt.geom AffineTransform setTransform

List of usage examples for java.awt.geom AffineTransform setTransform

Introduction

In this page you can find the example usage for java.awt.geom AffineTransform setTransform.

Prototype

public void setTransform(double m00, double m10, double m01, double m11, double m02, double m12) 

Source Link

Document

Sets this transform to the matrix specified by the 6 double precision values.

Usage

From source file:org.jcurl.core.base.Collider.java

/**
 * Compute the trafo to the right handed coordinate-system with origin
 * <code>orig</code> and positive y-axis pointing from <code>a</code> to
 * <code>b</code>./*from  w  ww  . j a v a  2  s.  com*/
 * 
 * @param orig
 * @param a
 * @param b
 * @param mat
 * @return the given matrix
 */
public static AffineTransform getInverseTrafo(final Point2D orig, final Point2D a, final Point2D b,
        final AffineTransform mat) {
    double dx = b.getX() - a.getX();
    double dy = b.getY() - a.getY();
    final double d = Math.sqrt(dx * dx + dy * dy);
    dx /= d;
    dy /= d;
    mat.setTransform(dy, -dx, dx, dy, 0, 0);
    mat.translate(-orig.getX(), -orig.getY());
    return mat;
}

From source file:org.jcurl.core.impl.ColliderBase.java

/**
 * Compute the inverse speed transformation to the right handed, moving
 * coordinate-system with relative speed <code>v0</code> and positive
 * y-axis pointing from <code>a</code> to <code>b</code>.
 * /*from w w  w  .  j ava2 s.  c o m*/
 * TODO Maybe thios should operate on {@link Rock}s rather than
 * {@link Point2D}s?
 * 
 * @param v0
 * @param a
 * @param b
 * @param mat
 * @return the given matrix
 */
public static AffineTransform getInverseTrafo(final Point2D v0, final Point2D a, final Point2D b,
        final AffineTransform mat) {
    double dx = b.getX() - a.getX();
    double dy = b.getY() - a.getY();
    final double d = Math.sqrt(dx * dx + dy * dy);
    dx /= d;
    dy /= d;
    mat.setTransform(dy, -dx, dx, dy, 0, 0);
    mat.translate(-v0.getX(), -v0.getY());
    return mat;
}

From source file:org.openstreetmap.gui.jmapviewer.Tile.java

/**
 * Tries to get tiles of a lower or higher zoom level (one or two level
 * difference) from cache and use it as a placeholder until the tile has
 * been loaded.//from   www .  j a v  a2  s.  c o  m
 */
public void loadPlaceholderFromCache(TileCache cache) {
    BufferedImage tmpImage = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = (Graphics2D) tmpImage.getGraphics();
    // g.drawImage(image, 0, 0, null);
    for (int zoomDiff = 1; zoomDiff < 5; zoomDiff++) {
        // first we check if there are already the 2^x tiles
        // of a higher detail level
        int zoom_high = zoom + zoomDiff;
        if (zoomDiff < 3 && zoom_high <= JMapViewer.MAX_ZOOM) {
            int factor = 1 << zoomDiff;
            int xtile_high = xtile << zoomDiff;
            int ytile_high = ytile << zoomDiff;
            double scale = 1.0 / factor;
            g.setTransform(AffineTransform.getScaleInstance(scale, scale));
            int paintedTileCount = 0;
            for (int x = 0; x < factor; x++) {
                for (int y = 0; y < factor; y++) {
                    Tile tile = cache.getTile(source, xtile_high + x, ytile_high + y, zoom_high);
                    if (tile != null && tile.isLoaded()) {
                        paintedTileCount++;
                        tile.paint(g, x * SIZE, y * SIZE);
                    }
                }
            }
            if (paintedTileCount == factor * factor) {
                image = tmpImage;
                return;
            }
        }

        int zoom_low = zoom - zoomDiff;
        if (zoom_low >= JMapViewer.MIN_ZOOM) {
            int xtile_low = xtile >> zoomDiff;
            int ytile_low = ytile >> zoomDiff;
            int factor = (1 << zoomDiff);
            double scale = factor;
            AffineTransform at = new AffineTransform();
            int translate_x = (xtile % factor) * SIZE;
            int translate_y = (ytile % factor) * SIZE;
            at.setTransform(scale, 0, 0, scale, -translate_x, -translate_y);
            g.setTransform(at);
            Tile tile = cache.getTile(source, xtile_low, ytile_low, zoom_low);
            if (tile != null && tile.isLoaded()) {
                tile.paint(g, 0, 0);
                image = tmpImage;
                return;
            }
        }
    }
}