Search in sources :

Example 11 with BaseVector3i

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

the class Region3i method move.

/**
 * @param offset
 * @return A copy of the region offset by the given value
 */
public Region3i move(BaseVector3i offset) {
    Vector3i newMin = min();
    newMin.add(offset);
    return Region3i.createFromMinAndSize(newMin, size);
}
Also used : BaseVector3i(org.terasology.math.geom.BaseVector3i) Vector3i(org.terasology.math.geom.Vector3i)

Example 12 with BaseVector3i

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

the class Region3i method createFromCenterExtents.

/**
 * Create a region with center point and x,y,z coordinate extents size
 * @param center the center point of region
 * @param extents the extents size of each side of region
 * @return a new region base on the center point and extents size
 */
public static Region3i createFromCenterExtents(BaseVector3i center, BaseVector3i extents) {
    Vector3i min = new Vector3i(center.x() - extents.x(), center.y() - extents.y(), center.z() - extents.z());
    Vector3i max = new Vector3i(center.x() + extents.x(), center.y() + extents.y(), center.z() + extents.z());
    return createFromMinMax(min, max);
}
Also used : BaseVector3i(org.terasology.math.geom.BaseVector3i) Vector3i(org.terasology.math.geom.Vector3i)

Example 13 with BaseVector3i

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

the class Region3i method getNearestPointTo.

/**
 * @param pos
 * @return The nearest position within the region to the given pos.
 */
public Vector3i getNearestPointTo(BaseVector3i pos) {
    Vector3i result = new Vector3i(pos);
    result.min(max());
    result.max(min);
    return result;
}
Also used : BaseVector3i(org.terasology.math.geom.BaseVector3i) Vector3i(org.terasology.math.geom.Vector3i)

Example 14 with BaseVector3i

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

the class TreeRasterizer method generateChunk.

@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
    TreeFacet facet = chunkRegion.getFacet(TreeFacet.class);
    for (Map.Entry<BaseVector3i, TreeGenerator> entry : facet.getRelativeEntries().entrySet()) {
        BaseVector3i pos = entry.getKey();
        TreeGenerator treeGen = entry.getValue();
        int seed = relativeToWorld(facet, pos).hashCode();
        Random random = new FastRandom(seed);
        treeGen.generate(blockManager, chunk, random, pos.x(), pos.y(), pos.z());
    }
}
Also used : FastRandom(org.terasology.utilities.random.FastRandom) Random(org.terasology.utilities.random.Random) TreeFacet(org.terasology.core.world.generator.facets.TreeFacet) BaseVector3i(org.terasology.math.geom.BaseVector3i) FastRandom(org.terasology.utilities.random.FastRandom) Map(java.util.Map) TreeGenerator(org.terasology.core.world.generator.trees.TreeGenerator)

Example 15 with BaseVector3i

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

the class FloraFacetLayer method render.

@Override
public void render(BufferedImage img, Region region) {
    FloraFacet treeFacet = region.getFacet(FloraFacet.class);
    Graphics2D g = img.createGraphics();
    int width = img.getWidth();
    ColorModel colorModel = img.getColorModel();
    ColorBlender blender = ColorBlenders.forColorModel(ColorModels.RGBA, colorModel);
    DataBufferInt dataBuffer = (DataBufferInt) img.getRaster().getDataBuffer();
    for (Entry<BaseVector3i, FloraType> entry : treeFacet.getRelativeEntries().entrySet()) {
        FloraType treeGen = entry.getValue();
        int wx = entry.getKey().getX();
        int wz = entry.getKey().getZ();
        Color color = colorFunc.apply(treeGen);
        int src = color.rgba();
        int dst = dataBuffer.getElem(wz * width + wx);
        int mix = blender.blend(src, dst);
        dataBuffer.setElem(wz * width + wx, mix);
    }
    g.dispose();
}
Also used : FloraType(org.terasology.core.world.generator.rasterizers.FloraType) ColorBlender(org.terasology.world.viewer.color.ColorBlender) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) ColorModel(java.awt.image.ColorModel) Color(org.terasology.rendering.nui.Color) BaseVector3i(org.terasology.math.geom.BaseVector3i) DataBufferInt(java.awt.image.DataBufferInt) Graphics2D(java.awt.Graphics2D)

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