Search in sources :

Example 31 with Vector2f

use of org.joml.Vector2f in project Terasology by MovingBlocks.

the class TessellatorHelper method addBlockMesh.

public static void addBlockMesh(Tessellator tessellator, Vector4f color, Vector2f[] texOffsets, Vector2f[] texSizes, float size, float light1, float light2, float posX, float posY, float posZ) {
    final float sizeHalf = size / 2;
    tessellator.resetParams();
    tessellator.setColor(new Vector4f(light1 * color.x, light1 * color.y, light1 * color.z, color.w));
    tessellator.setNormal(new Vector3f(0, 1, 0));
    tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[0].x, texOffsets[0].y), new Vector2f(texOffsets[0].x + texSizes[0].x, texOffsets[0].y), new Vector2f(texOffsets[0].x + texSizes[0].x, texOffsets[0].y + texSizes[0].y), new Vector2f(texOffsets[0].x, texOffsets[0].y + texSizes[0].y) });
    tessellator.setNormal(new Vector3f(-1, 0, 0));
    tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[1].x, texOffsets[1].y + texSizes[1].y), new Vector2f(texOffsets[1].x + texSizes[1].x, texOffsets[1].y + texSizes[1].y), new Vector2f(texOffsets[1].x + texSizes[1].x, texOffsets[1].y), new Vector2f(texOffsets[1].x, texOffsets[1].y) });
    tessellator.setNormal(new Vector3f(1, 0, 0));
    tessellator.addPoly(new Vector3f[] { new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[2].x, texOffsets[2].y), new Vector2f(texOffsets[2].x + texSizes[2].x, texOffsets[2].y), new Vector2f(texOffsets[2].x + texSizes[2].x, texOffsets[2].y + texSizes[2].y), new Vector2f(texOffsets[2].x, texOffsets[2].y + texSizes[2].y) });
    tessellator.setColor(new Vector4f(light2 * color.x, light2 * color.y, light2 * color.z, color.w));
    tessellator.setNormal(new Vector3f(0, 0, -1));
    tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[3].x, texOffsets[3].y), new Vector2f(texOffsets[3].x + texSizes[3].x, texOffsets[3].y), new Vector2f(texOffsets[3].x + texSizes[3].x, texOffsets[3].y + texSizes[3].y), new Vector2f(texOffsets[3].x, texOffsets[3].y + texSizes[3].y) });
    tessellator.setNormal(new Vector3f(0, 0, 1));
    tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[4].x, texOffsets[4].y + texSizes[4].y), new Vector2f(texOffsets[4].x + texSizes[4].x, texOffsets[4].y + texSizes[4].y), new Vector2f(texOffsets[4].x + texSizes[4].x, texOffsets[4].y), new Vector2f(texOffsets[4].x, texOffsets[4].y) });
    tessellator.setNormal(new Vector3f(0, -1, 0));
    tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[5].x, texOffsets[5].y), new Vector2f(texOffsets[5].x + texSizes[5].x, texOffsets[5].y), new Vector2f(texOffsets[5].x + texSizes[5].x, texOffsets[5].y + texSizes[5].y), new Vector2f(texOffsets[5].x, texOffsets[5].y + texSizes[5].y) });
}
Also used : Vector4f(org.joml.Vector4f) Vector2f(org.joml.Vector2f) Vector3f(org.joml.Vector3f)

Example 32 with Vector2f

use of org.joml.Vector2f in project Terasology by MovingBlocks.

the class Port method mid.

public Vector2f mid() {
    Vector2f mid = rect.getSize(new Vector2f());
    mid.mul(0.5f);
    mid.add(rect.minX(), rect.minY());
    return mid;
}
Also used : Vector2f(org.joml.Vector2f)

Example 33 with Vector2f

use of org.joml.Vector2f in project Terasology by MovingBlocks.

the class BehaviorEditor method drawConnection.

private void drawConnection(Canvas canvas, Port from, Vector2f to, Color color) {
    Vector2f start = new Vector2f(from.node.getPosition());
    start.add(from.mid());
    drawConnection(canvas, start, to, color);
}
Also used : Vector2f(org.joml.Vector2f)

Example 34 with Vector2f

use of org.joml.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 = new Vector2f(selectedNode.getSize());
            Vector2f topLeft = new Vector2f(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.joml.Vector2f) SubRegion(org.terasology.nui.SubRegion) UIWidget(org.terasology.nui.UIWidget)

Example 35 with Vector2f

use of org.joml.Vector2f in project Terasology by MovingBlocks.

the class BehaviorEditor method drawConnection.

private void drawConnection(Canvas canvas, Port from, Port to, Color color) {
    Vector2f start = new Vector2f(from.node.getPosition());
    start.add(from.mid());
    Vector2f end = new Vector2f(to.node.getPosition());
    end.add(to.mid());
    drawConnection(canvas, start, end, color);
}
Also used : Vector2f(org.joml.Vector2f)

Aggregations

Vector2f (org.joml.Vector2f)47 Vector3f (org.joml.Vector3f)13 Test (org.junit.jupiter.api.Test)6 Vector2i (org.joml.Vector2i)5 Vector4f (org.joml.Vector4f)5 Rectanglei (org.terasology.joml.geom.Rectanglei)5 Rectanglef (org.terasology.joml.geom.Rectanglef)4 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 Vector3i (org.joml.Vector3i)3 SubtextureData (org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData)3 Name (org.terasology.gestalt.naming.Name)3 Vector2fc (org.joml.Vector2fc)2 Vector3d (org.joml.Vector3d)2 MeshBuilder (org.terasology.engine.rendering.assets.mesh.MeshBuilder)2 TFloatList (gnu.trove.list.TFloatList)1 TObjectIntMap (gnu.trove.map.TObjectIntMap)1 TObjectIntHashMap (gnu.trove.map.hash.TObjectIntHashMap)1 Location (io.xol.chunkstories.api.Location)1 Controller (io.xol.chunkstories.api.entity.Controller)1