Package org.terasology.math

Examples of org.terasology.math.Rect2i


        return TeraMath.biLerp(q00, q10, q01, q11, xMod / sampleRate, yMod / sampleRate);
    }

    public float[] noise(Rect2i region) {
        Rect2i fullRegion = determineRequiredRegion(region);
        float[] keyData = getKeyValues(fullRegion);
        float[] fullData = mapExpand(keyData, fullRegion);
        return getSubset(fullData, fullRegion, region);
    }
View Full Code Here


    public void process(GeneratingRegion region) {
        SurfaceHeightFacet surfaceHeight = region.getRegionFacet(SurfaceHeightFacet.class);
        DensityFacet facet = new DensityFacet(region.getRegion(), region.getBorderForFacet(DensityFacet.class));

        Region3i area = region.getRegion();
        Rect2i rect = Rect2i.createFromMinAndMax(facet.getRelativeRegion().minX(), facet.getRelativeRegion().minZ(),
                facet.getRelativeRegion().maxX(), facet.getRelativeRegion().maxZ());
        for (Vector2i pos : rect) {
            float height = surfaceHeight.get(pos);
            for (int y = facet.getRelativeRegion().minY(); y <= facet.getRelativeRegion().maxY(); ++y) {
                facet.set(pos.x, y, pos.y, height - area.minY() - y);
View Full Code Here

            double p00 = heightmap[hmX][hmZ] * scaleFactor;
            double p10 = heightmap[(hmX - 1 + 512) % 512][(hmZ) % 512] * scaleFactor;
            double p11 = heightmap[(hmX - 1 + 512) % 512][(hmZ + 1 + 512) % 512] * scaleFactor;
            double p01 = heightmap[(hmX) % 512][(hmZ + 1 + 512) % 512] * scaleFactor;

            Rect2i worldRegion = Rect2i.createFromMinAndSize(chunkWorldRegion.minX(),
                    chunkWorldRegion.minZ(),
                    chunkWorldRegion.sizeX(),
                    chunkWorldRegion.sizeZ());

            for (Vector2i pos : worldRegion) {
View Full Code Here

    public static BufferedImage convertToImage(TextureRegion textureRegion) {
        final int width = textureRegion.getWidth();
        final int height = textureRegion.getHeight();

        final Rect2i pixelRegion = textureRegion.getPixelRegion();
        final Texture texture = textureRegion.getTexture();
        ByteBuffer textureBytes = texture.getData().getBuffers()[0];
        int stride = texture.getWidth() * 4;
        int posX = pixelRegion.minX();
        int posY = pixelRegion.minY();

        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                int r = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4));
 
View Full Code Here

        TreeFacet facet = new TreeFacet(region.getRegion(), borderForTreeFacet.extendBy(0, 15, 10));
        SurfaceHeightFacet surface = region.getRegionFacet(SurfaceHeightFacet.class);
        DensityFacet density = region.getRegionFacet(DensityFacet.class);
        SeaLevelFacet seaLevel = region.getRegionFacet(SeaLevelFacet.class);

        Rect2i worldRegion2D = Rect2i.createFromMinAndMax(facet.getWorldRegion().minX(),
                facet.getWorldRegion().minZ(),
                facet.getWorldRegion().maxX(),
                facet.getWorldRegion().maxZ());

        for (Vector2i pos : worldRegion2D) {
View Full Code Here

public class Rect2iTest {

    @Test
    public void testSubtraction0() {
        Rect2i a = Rect2i.createFromMinAndSize(1, 2, 3, 3);
        Rect2i b = Rect2i.createFromMinAndSize(0, 4, 3, 3);

        List<Rect2i> sub = Rect2i.difference(a, b);

        assertEquals(2, sub.size());
View Full Code Here

        assertTrue(sub.contains(Rect2i.createFromMinAndSize(3, 4, 1, 1)));
    }

    @Test
    public void testSubtraction1() {
        Rect2i a = Rect2i.createFromMinAndSize(1, 2, 3, 3);
        Rect2i b = Rect2i.createFromMinAndSize(3, 2, 3, 3);

        List<Rect2i> sub = Rect2i.difference(a, b);

        assertEquals(1, sub.size());
        assertEquals(Rect2i.createFromMinAndSize(1, 2, 2, 3), sub.get(0));
View Full Code Here

        assertTrue(Rect2i.createFromMinAndSize(5, 5, 472, 17).overlaps(Rect2i.createFromMinAndSize(5, 5, 1, 16)));
    }

    @Test
    public void testContains() {
        Rect2i a = Rect2i.createFromMinAndMax(0, 0, 0, 0);
        assertTrue(a.contains(0, 0));

        assertFalse(a.contains(1, 0));
        assertFalse(a.contains(0, 1));
        assertFalse(a.contains(1, 1));
        assertFalse(a.contains(-1, 0));
        assertFalse(a.contains(0, -1));
        assertFalse(a.contains(-1, 1));
        assertFalse(a.contains(1, -1));
        assertFalse(a.contains(-1, -1));
    }
View Full Code Here

    }

    public static Mesh generateIconMesh(AssetUri uri, TextureRegion tex, int alphaLimit, boolean withContour, Vector4f colorContour) {
        ByteBuffer buffer = tex.getTexture().getData().getBuffers()[0];

        Rect2i pixelRegion = tex.getPixelRegion();
        int posX = pixelRegion.minX();
        int posY = pixelRegion.minY();

        int stride = tex.getTexture().getWidth() * 4;

        float textureSize = Math.max(tex.getWidth(), tex.getHeight());

View Full Code Here

        int tickerWidth = canvas.getCurrentStyle().getFont().getWidth(display);
        tickerWidth += canvas.getCurrentStyle().getMargin().getTotalWidth();

        sliderWidth = canvas.size().x - tickerWidth;
        int drawLocation = pixelOffsetFor(getValue(), sliderWidth);
        Rect2i tickerRegion = Rect2i.createFromMinAndSize(drawLocation, 0, tickerWidth, canvas.size().y);
        try (SubRegion ignored = canvas.subRegion(tickerRegion, false)) {
            canvas.drawBackground();
            canvas.drawText(display);
            canvas.addInteractionRegion(tickerListener);
        }
View Full Code Here

TOP

Related Classes of org.terasology.math.Rect2i

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.