Search in sources :

Example 6 with BaseVector3i

use of org.terasology.math.geom.BaseVector3i in project Terasology by MovingBlocks.

the class TreeRasterizer method relativeToWorld.

// TODO: JAVA8 - move the two conversion methods from SparseFacet3D to default methods in WorldFacet3D
protected final Vector3i relativeToWorld(SparseFacet3D facet, BaseVector3i pos) {
    Region3i worldRegion = facet.getWorldRegion();
    Region3i relativeRegion = facet.getRelativeRegion();
    return new Vector3i(pos.x() - relativeRegion.minX() + worldRegion.minX(), pos.y() - relativeRegion.minY() + worldRegion.minY(), pos.z() - relativeRegion.minZ() + worldRegion.minZ());
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) BaseVector3i(org.terasology.math.geom.BaseVector3i) Region3i(org.terasology.math.Region3i)

Example 7 with BaseVector3i

use of org.terasology.math.geom.BaseVector3i in project Terasology by MovingBlocks.

the class FloraFacetLayer method getWorldText.

@Override
public String getWorldText(Region region, int wx, int wy) {
    FloraFacet floraFacet = region.getFacet(FloraFacet.class);
    Region3i worldRegion = floraFacet.getWorldRegion();
    Region3i relativeRegion = floraFacet.getRelativeRegion();
    int rx = wx - worldRegion.minX() + relativeRegion.minX();
    int rz = wy - worldRegion.minZ() + relativeRegion.minZ();
    for (Entry<BaseVector3i, FloraType> entry : floraFacet.getRelativeEntries().entrySet()) {
        BaseVector3i treePos = entry.getKey();
        if (treePos.getX() == rx && treePos.getZ() == rz) {
            FloraType flora = entry.getValue();
            return labelFunc.apply(flora);
        }
    }
    return "-no vegetation-";
}
Also used : FloraType(org.terasology.core.world.generator.rasterizers.FloraType) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) BaseVector3i(org.terasology.math.geom.BaseVector3i) Region3i(org.terasology.math.Region3i)

Example 8 with BaseVector3i

use of org.terasology.math.geom.BaseVector3i in project Terasology by MovingBlocks.

the class TreeFacetLayer method render.

@Override
public void render(BufferedImage img, Region region) {
    TreeFacet treeFacet = region.getFacet(TreeFacet.class);
    Graphics2D g = img.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    for (Entry<BaseVector3i, TreeGenerator> entry : treeFacet.getRelativeEntries().entrySet()) {
        TreeGenerator treeGen = entry.getValue();
        int wx = entry.getKey().getX();
        int wz = entry.getKey().getZ();
        int r = radiusFunc.apply(treeGen);
        Color color = colorFunc.apply(treeGen);
        // the fill area is offset by +1/+1 pixel
        // otherwise it will bleed out at the top left corner
        g.setColor(color);
        g.fillOval(wx - r + 1, wz - r + 1, r * 2 - 1, r * 2 - 1);
        g.setColor(color.darker());
        g.drawOval(wx - r, wz - r, r * 2, r * 2);
    }
    g.dispose();
}
Also used : Color(java.awt.Color) TreeFacet(org.terasology.core.world.generator.facets.TreeFacet) BaseVector3i(org.terasology.math.geom.BaseVector3i) Graphics2D(java.awt.Graphics2D) TreeGenerator(org.terasology.core.world.generator.trees.TreeGenerator)

Example 9 with BaseVector3i

use of org.terasology.math.geom.BaseVector3i in project Terasology by MovingBlocks.

the class TreeFacetLayer method getWorldText.

@Override
public String getWorldText(Region region, int wx, int wy) {
    TreeFacet treeFacet = region.getFacet(TreeFacet.class);
    Region3i worldRegion = treeFacet.getWorldRegion();
    Region3i relativeRegion = treeFacet.getRelativeRegion();
    int rx = wx - worldRegion.minX() + relativeRegion.minX();
    int rz = wy - worldRegion.minZ() + relativeRegion.minZ();
    Vector2f relCursor = new Vector2f(rx, rz);
    CirclePicker<TreeGenerator> picker = new CirclePickerAll<>(relCursor, radiusFunc);
    for (Entry<BaseVector3i, TreeGenerator> entry : treeFacet.getRelativeEntries().entrySet()) {
        TreeGenerator treeGen = entry.getValue();
        BaseVector3i treePos = entry.getKey();
        picker.offer(treePos.getX(), treePos.getZ(), treeGen);
    }
    Set<TreeGenerator> picked = picker.getAll();
    // try to exit early first
    if (picked.isEmpty()) {
        return null;
    }
    if (picked.size() == 1) {
        TreeGenerator first = picked.iterator().next();
        return labelFunc.apply(first);
    }
    // convert to a stream of labels
    Stream<String> labels = picked.stream().map(labelFunc);
    // collect identical String elements and collect the count in a map
    Map<String, Long> counters = labels.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    // define a mapping from a map entry to a String representation
    // TODO: treat 1x occurrences like above (e.g. Tree instead of 1x Tree)
    Function<Entry<String, Long>, String> toStringFunc = e -> String.format("%dx %s", e.getValue(), e.getKey());
    // apply that mapping and join the Strings with a comma
    return counters.entrySet().stream().map(toStringFunc).collect(Collectors.joining(", "));
}
Also used : Color(java.awt.Color) Region(org.terasology.world.generation.Region) Region3i(org.terasology.math.Region3i) BufferedImage(java.awt.image.BufferedImage) TreeGenerator(org.terasology.core.world.generator.trees.TreeGenerator) Set(java.util.Set) RenderingHints(java.awt.RenderingHints) Vector2f(org.terasology.math.geom.Vector2f) CirclePickerAll(org.terasology.world.viewer.picker.CirclePickerAll) Renders(org.terasology.world.viewer.layers.Renders) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) AbstractFacetLayer(org.terasology.world.viewer.layers.AbstractFacetLayer) Stream(java.util.stream.Stream) TreeFacet(org.terasology.core.world.generator.facets.TreeFacet) BaseVector3i(org.terasology.math.geom.BaseVector3i) Graphics2D(java.awt.Graphics2D) Map(java.util.Map) Entry(java.util.Map.Entry) CirclePicker(org.terasology.world.viewer.picker.CirclePicker) ZOrder(org.terasology.world.viewer.layers.ZOrder) CirclePickerAll(org.terasology.world.viewer.picker.CirclePickerAll) TreeFacet(org.terasology.core.world.generator.facets.TreeFacet) TreeGenerator(org.terasology.core.world.generator.trees.TreeGenerator) Entry(java.util.Map.Entry) Vector2f(org.terasology.math.geom.Vector2f) BaseVector3i(org.terasology.math.geom.BaseVector3i) Region3i(org.terasology.math.Region3i)

Example 10 with BaseVector3i

use of org.terasology.math.geom.BaseVector3i in project Terasology by MovingBlocks.

the class SparseObjectFacet3D method getWorldEntries.

/**
 * @return a <b>new</b> map with world-based position entries
 */
public Map<BaseVector3i, T> getWorldEntries() {
    Map<BaseVector3i, T> result = Maps.newLinkedHashMap();
    for (Entry<BaseVector3i, T> entry : relData.entrySet()) {
        BaseVector3i relPos = entry.getKey();
        BaseVector3i worldPos = relativeToWorld(relPos.x(), relPos.y(), relPos.z());
        result.put(worldPos, entry.getValue());
    }
    return result;
}
Also used : BaseVector3i(org.terasology.math.geom.BaseVector3i)

Aggregations

BaseVector3i (org.terasology.math.geom.BaseVector3i)15 Vector3i (org.terasology.math.geom.Vector3i)8 Graphics2D (java.awt.Graphics2D)3 Map (java.util.Map)3 FloraFacet (org.terasology.core.world.generator.facets.FloraFacet)3 TreeFacet (org.terasology.core.world.generator.facets.TreeFacet)3 TreeGenerator (org.terasology.core.world.generator.trees.TreeGenerator)3 Region3i (org.terasology.math.Region3i)3 Color (java.awt.Color)2 FloraType (org.terasology.core.world.generator.rasterizers.FloraType)2 Region (org.terasology.world.generation.Region)2 ImmutableList (com.google.common.collect.ImmutableList)1 Maps (com.google.common.collect.Maps)1 RenderingHints (java.awt.RenderingHints)1 BufferedImage (java.awt.image.BufferedImage)1 ColorModel (java.awt.image.ColorModel)1 DataBufferInt (java.awt.image.DataBufferInt)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1