Search in sources :

Example 31 with Vector2f

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

the class WorldAtlasImpl method createTextureAtlas.

private void createTextureAtlas(final Texture texture) {
    final Map<Name, Map<Name, SubtextureData>> textureAtlases = Maps.newHashMap();
    final Vector2f texSize = new Vector2f(getRelativeTileSize(), getRelativeTileSize());
    tileIndexes.forEachEntry((tileUri, index) -> {
        Vector2f coords = getTexCoords(index);
        SubtextureData subtextureData = new SubtextureData(texture, Rect2f.createFromMinAndSize(coords, texSize));
        Map<Name, SubtextureData> textureAtlas = textureAtlases.get(tileUri.getModuleName());
        if (textureAtlas == null) {
            textureAtlas = Maps.newHashMap();
            textureAtlases.put(tileUri.getModuleName(), textureAtlas);
        }
        textureAtlas.put(tileUri.getResourceName(), subtextureData);
        return true;
    });
    for (Map.Entry<Name, Map<Name, SubtextureData>> atlas : textureAtlases.entrySet()) {
        AtlasData data = new AtlasData(atlas.getValue());
        Assets.generateAsset(new ResourceUrn(atlas.getKey(), new Name("terrain")), data, Atlas.class);
    }
}
Also used : AtlasData(org.terasology.rendering.assets.atlas.AtlasData) Vector2f(org.terasology.math.geom.Vector2f) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) ResourceUrn(org.terasology.assets.ResourceUrn) TObjectIntMap(gnu.trove.map.TObjectIntMap) Map(java.util.Map) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Name(org.terasology.naming.Name)

Example 32 with Vector2f

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

the class TextureOffsetGeneratorFunction method onEmission.

@Override
public void onEmission(TextureOffsetGeneratorComponent component, ParticleData particleData, Random random) {
    if (component.validOffsets.size() == 0) {
        return;
    }
    final int randomOffsetIndex = random.nextInt(component.validOffsets.size());
    final Vector2f randomOffset = component.validOffsets.get(randomOffsetIndex);
    particleData.textureOffset.set(randomOffset.getX(), randomOffset.getY());
}
Also used : Vector2f(org.terasology.math.geom.Vector2f)

Example 33 with Vector2f

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

the class BehaviorEditor method copyNode.

public void copyNode(RenderableNode node) {
    BehaviorTreeBuilder treeBuilder = CoreRegistry.get(BehaviorTreeBuilder.class);
    String json = treeBuilder.toJson(node.getNode());
    BehaviorNode nodeCopy = treeBuilder.fromJson(json);
    List<RenderableNode> renderables = createRenderables(nodeCopy);
    if (renderables.size() > 0) {
        newNode = renderables.get(0);
        Vector2f oldPos = newNode.getPosition();
        layout(newNode);
        oldPos.sub(newNode.getPosition());
        newNode.move(oldPos);
    }
}
Also used : BehaviorTreeBuilder(org.terasology.logic.behavior.core.BehaviorTreeBuilder) Vector2f(org.terasology.math.geom.Vector2f) BehaviorNode(org.terasology.logic.behavior.core.BehaviorNode)

Example 34 with Vector2f

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

the class BehaviorEditor method onDraw.

@Override
public void onDraw(final Canvas canvas) {
    super.onDraw(canvas);
    canvas.addInteractionRegion(mouseInteractionListener);
    try (SubRegion subRegion = canvas.subRegion(canvas.getRegion(), false)) {
        canvas.setDrawOnTop(true);
        for (UIWidget widget : getWidgets()) {
            if (!widget.isVisible()) {
                continue;
            }
            if (widget instanceof RenderableNode) {
                RenderableNode renderableNode = (RenderableNode) widget;
                for (Port port : renderableNode.getPorts()) {
                    Port targetPort = port.getTargetPort();
                    if (port.isInput() || targetPort == null || !targetPort.node.isVisible()) {
                        continue;
                    }
                    drawConnection(canvas, port, targetPort, port == activeConnectionStart ? Color.BLACK : Color.GREY);
                }
            }
        }
        if (activeConnectionStart != null) {
            drawConnection(canvas, activeConnectionStart, mouseWorldPosition, Color.WHITE);
        }
        if (selectedNode != null) {
            Vector2f size = selectedNode.getSize();
            Vector2f topLeft = selectedNode.getPosition();
            Vector2f topRight = new Vector2f(topLeft);
            topRight.add(new Vector2f(size.x + .1f, 0));
            Vector2f bottomLeft = new Vector2f(topLeft);
            bottomLeft.add(new Vector2f(0, size.y + .1f));
            Vector2f bottomRight = new Vector2f(topLeft);
            bottomRight.add(new Vector2f(size.x + 0.1f, size.y + 0.1f));
            drawConnection(canvas, topLeft, topRight, Color.GREEN);
            drawConnection(canvas, topRight, bottomRight, Color.GREEN);
            drawConnection(canvas, bottomRight, bottomLeft, Color.GREEN);
            drawConnection(canvas, bottomLeft, topLeft, Color.GREEN);
        }
        if (newNode != null) {
            newNode.visit(node -> drawWidget(canvas, node));
        }
        canvas.setDrawOnTop(false);
    }
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) SubRegion(org.terasology.rendering.nui.SubRegion) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 35 with Vector2f

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

the class ZoomableLayoutTest method testZoomOut.

@Test
public void testZoomOut() throws Exception {
    zoomableLayout.onDraw(canvas);
    // zoom out 2x from top left corner
    zoomableLayout.zoom(2, 2, new Vector2i(0, 0));
    zoomableLayout.onDraw(canvas);
    // world size doubled
    assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH * 2 * 2, WORLD_HEIGHT * 2));
    assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
    assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / (WORLD_WIDTH * 2 * 2), CANVAS_HEIGHT / (WORLD_HEIGHT * 2)));
    verify(canvas).drawWidget(item1, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos1.x / 4), ceilToInt(pos1.y / 4)), new Vector2i(ceilToInt((pos1.x + size1.x) / 4), ceilToInt((pos1.y + size1.y) / 4))));
    verify(canvas).drawWidget(item2, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos2.x / 4), ceilToInt(pos2.y / 4)), new Vector2i(ceilToInt((pos2.x + size2.x) / 4), ceilToInt((pos2.y + size2.y) / 4))));
    verify(canvas).drawWidget(item3, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos3.x / 4), ceilToInt(pos3.y / 4)), new Vector2i(ceilToInt((pos3.x + size3.x) / 4), ceilToInt((pos3.y + size3.y) / 4))));
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Vector2i(org.terasology.math.geom.Vector2i) Test(org.junit.Test)

Aggregations

Vector2f (org.terasology.math.geom.Vector2f)41 Vector3f (org.terasology.math.geom.Vector3f)8 IOException (java.io.IOException)5 TIntList (gnu.trove.list.TIntList)4 Vector2i (org.terasology.math.geom.Vector2i)4 TFloatList (gnu.trove.list.TFloatList)3 Map (java.util.Map)3 Test (org.junit.Test)3 Name (org.terasology.naming.Name)3 SubtextureData (org.terasology.rendering.assets.texture.subtexture.SubtextureData)3 BrownianNoise (org.terasology.utilities.procedural.BrownianNoise)3 PerlinNoise (org.terasology.utilities.procedural.PerlinNoise)3 SubSampledNoise (org.terasology.utilities.procedural.SubSampledNoise)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 InputStream (java.io.InputStream)2 Vector4f (org.terasology.math.geom.Vector4f)2 Bone (org.terasology.rendering.assets.skeletalmesh.Bone)2 BoneWeight (org.terasology.rendering.assets.skeletalmesh.BoneWeight)2 SkeletalMeshDataBuilder (org.terasology.rendering.assets.skeletalmesh.SkeletalMeshDataBuilder)2 BlockAppearance (org.terasology.world.block.BlockAppearance)2