Search in sources :

Example 16 with Vector4f

use of org.joml.Vector4f in project chunkstories by Hugobros3.

the class TrianglesClipper method cullLeft.

private static int cullLeft(Vector4f vert1, Vector4f vert2, Vector4f vert3) {
    // Sort
    Vector4f v1, v2, v3;
    if (vert1.x() > vert2.x()) {
        if (vert1.x() > vert3.x()) {
            v3 = vert1;
            if (vert2.x() > vert3.x()) {
                v2 = vert2;
                v1 = vert3;
            } else {
                v2 = vert3;
                v1 = vert2;
            }
        } else {
            v2 = vert1;
            if (vert2.x() > vert3.x()) {
                v3 = vert2;
                v1 = vert3;
            } else {
                v3 = vert3;
                v1 = vert2;
            }
        }
    } else {
        if (vert2.x() > vert3.x()) {
            v3 = vert2;
            if (vert1.x() > vert3.x()) {
                v2 = vert1;
                v1 = vert3;
            } else {
                v2 = vert3;
                v1 = vert1;
            }
        } else {
            v2 = vert2;
            v3 = vert3;
            v1 = vert1;
        }
    }
    if (v1.x() <= v2.x() && v2.x() <= v3.x()) {
    } else {
        System.out.println("cullLeft: X ordering is fucked: " + v1.x() + " " + v2.x() + " " + v3.x());
        System.out.println("Input was: " + vert1.x() + " " + vert2.x() + " " + vert3.x());
        System.out.println("Input aka: " + vert1 + " " + vert2 + " " + vert3);
        return 0;
    }
    // Actual culling here
    float border = 0.0f;
    // One point is clipping
    if (v1.x() < border && v2.x() > border && v3.x() > border) {
        float d2to1 = v2.x() - v1.x();
        float d2tb = v2.x();
        Vector4f v2to1 = new Vector4f(v1).sub(v2);
        v2to1.mul((d2tb) / d2to1);
        v2to1.add(v2);
        int t = cullRight(v2to1, v2, v3);
        float d3to1 = v3.x() - v1.x();
        float d3tb = v3.x();
        Vector4f v3to1 = new Vector4f(v1).sub(v3);
        v3to1.mul((d3tb) / d3to1);
        v3to1.add(v3);
        return t + cullRight(v2to1, v3, v3to1);
    } else // Two points are
    if (v1.x() < border && v2.x() < border && v3.x() > border) {
        float d3tb = v3.x();
        float d3to1 = v3.x() - v1.x();
        Vector4f v3to1 = new Vector4f(v1).sub(v3);
        v3to1.mul((d3tb) / d3to1);
        v3to1.add(v3);
        float d3to2 = v3.x() - v2.x();
        Vector4f v3to2 = new Vector4f(v2).sub(v3);
        v3to2.mul((d3tb) / d3to2);
        v3to2.add(v3);
        return cullRight(v3to1, v3, v3to2);
    } else // All are
    if (v1.x() < border && v2.x() < border && v3.x() < border) {
        // System.out.println("all out !");
        return 0;
    } else // None are
    {
        return cullRight(v1, v2, v3);
    }
}
Also used : Vector4f(org.joml.Vector4f)

Example 17 with Vector4f

use of org.joml.Vector4f in project chunkstories by Hugobros3.

the class TrianglesClipper method cullBot.

private static int cullBot(Vector4f v1, Vector4f v2, Vector4f v3) {
    float border = 0.0f;
    // One point is clipping
    if (v1.y() < border && v2.y() > border && v3.y() > border) {
        float d2to1 = v2.y() - v1.y();
        float d2tb = v2.y();
        Vector4f v2to1 = new Vector4f(v1).sub(v2);
        v2to1.mul((d2tb) / d2to1);
        v2to1.add(v2);
        int t = cullDone(v2to1, v2, v3);
        float d3to1 = v3.y() - v1.y();
        float d3tb = v3.y();
        Vector4f v3to1 = new Vector4f(v1).sub(v3);
        v3to1.mul((d3tb) / d3to1);
        v3to1.add(v3);
        return t + cullDone(v2to1, v3, v3to1);
    } else // Two points are
    if (v1.y() < border && v2.y() < border && v3.y() > border) {
        float d3tb = v3.y();
        float d3to1 = v3.y() - v1.y();
        Vector4f v3to1 = new Vector4f(v1).sub(v3);
        v3to1.mul((d3tb) / d3to1);
        v3to1.add(v3);
        float d3to2 = v3.y() - v2.y();
        Vector4f v3to2 = new Vector4f(v2).sub(v3);
        v3to2.mul((d3tb) / d3to2);
        v3to2.add(v3);
        return cullDone(v3to1, v3, v3to2);
    } else // All are
    if (v1.y() < border && v2.y() < border && v3.y() < border) {
        return 0;
    // System.out.println("all out !");
    } else // None are
    {
        return cullDone(v1, v2, v3);
    }
}
Also used : Vector4f(org.joml.Vector4f)

Example 18 with Vector4f

use of org.joml.Vector4f in project chunkstories by Hugobros3.

the class TrianglesClipper method cullRight.

private static int cullRight(Vector4f v1, Vector4f v2, Vector4f v3) {
    float border = 1.0f;
    // One point is clipping
    if (v1.x() < border && v2.x() < border && v3.x() > border) {
        // System.out.println("clipping...");
        // Continue the two segments up to the border
        float d2t3 = v3.x() - v2.x();
        float d2tb = border - v2.x();
        Vector4f v2to3 = new Vector4f(v3).sub(v2);
        v2to3.mul((d2tb) / d2t3);
        v2to3.add(v2);
        // System.out.println(v2to3+" is in of clip ("+v2to3.x+")");
        // other one
        float d1t3 = v3.x() - v1.x();
        float d1tb = border - v1.x();
        Vector4f v1to3 = new Vector4f(v3).sub(v1);
        v1to3.mul((d1tb) / d1t3);
        v1to3.add(v1);
        return cullTop(v1, v2, v1to3) + cullTop(v2to3, v2, v1to3);
    } else // Two points are
    if (v1.x() < border && v2.x() > border && v3.x() > border) {
        float d1t3 = v3.x() - v1.x();
        float d1tb = border - v1.x();
        Vector4f v1to3 = new Vector4f(v3).sub(v1);
        v1to3.mul((d1tb) / d1t3);
        v1to3.add(v1);
        // other one
        float d1t2 = v2.x() - v1.x();
        // float d1tb = border - v1.x;
        Vector4f v1to2 = new Vector4f(v2).sub(v1);
        v1to2.mul((d1tb) / d1t2);
        v1to2.add(v1);
        return cullTop(v1, v1to2, v1to3);
    } else if (v1.x() > border && v2.x() > border && v3.x() > border) {
        // System.out.println("all out !");
        return 0;
    } else {
        return cullTop(v1, v2, v3);
    }
}
Also used : Vector4f(org.joml.Vector4f)

Example 19 with Vector4f

use of org.joml.Vector4f in project chunkstories by Hugobros3.

the class InventoryGridRenderer method drawInventory.

public void drawInventory(RenderingInterface renderer, int x, int y, int scale, boolean summary, int blankLines, int highlightSlot) {
    Mouse mouse = renderer.getClient().getInputsManager().getMouse();
    if (getInventory() == null)
        return;
    int cornerSize = 8 * scale;
    int internalWidth = getInventory().getWidth() * 24 * scale;
    int height = summary ? 1 : getInventory().getHeight();
    int internalHeight = (height + (summary ? 0 : 1) + blankLines) * 24 * scale;
    int slotSize = 24 * scale;
    Texture2D inventoryTexture = renderer.textures().getTexture("./textures/gui/inventory/inventory.png");
    inventoryTexture.setLinearFiltering(false);
    Vector4f color = new Vector4f(1f, 1f, 1f, summary ? 0.5f : 1f);
    // All 8 corners
    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x, y + internalHeight + cornerSize, cornerSize, cornerSize, 0, 0.03125f, 0.03125f, 0, inventoryTexture, true, true, color);
    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize, y + internalHeight + cornerSize, internalWidth, cornerSize, 0.03125f, 0.03125f, 0.96875f, 0, inventoryTexture, true, true, color);
    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + internalWidth, y + internalHeight + cornerSize, cornerSize, cornerSize, 0.96875f, 0.03125f, 1f, 0, inventoryTexture, true, true, color);
    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x, y, cornerSize, cornerSize, 0, 1f, 0.03125f, 248 / 256f, inventoryTexture, true, true, color);
    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize, y, internalWidth, cornerSize, 0.03125f, 1f, 0.96875f, 248 / 256f, inventoryTexture, true, true, color);
    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + internalWidth, y, cornerSize, cornerSize, 0.96875f, 1f, 1f, 248 / 256f, inventoryTexture, true, true, color);
    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x, y + cornerSize, cornerSize, internalHeight, 0, 248f / 256f, 0.03125f, 8f / 256f, inventoryTexture, true, true, color);
    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + internalWidth, y + cornerSize, cornerSize, internalHeight, 248 / 256f, 248f / 256f, 1f, 8f / 256f, inventoryTexture, true, true, color);
    // Actual inventory slots
    int sumSlots2HL = 0;
    selectedSlot = null;
    for (int i = 0; i < getInventory().getWidth(); i++) {
        for (int j = 0; j < height; j++) {
            boolean mouseOver = mouse.getCursorX() > x + cornerSize + i * slotSize && mouse.getCursorX() <= x + cornerSize + i * slotSize + slotSize && mouse.getCursorY() > y + cornerSize + j * slotSize && mouse.getCursorY() <= y + cornerSize + j * slotSize + slotSize;
            // Just a dirt hack to always keep selected slot values where we want them
            if (mouseOver && selectedSlot == null) {
                selectedSlot = new int[] { i, j };
            }
            ItemPile selectedPile = null;
            if (selectedSlot != null)
                selectedPile = getInventory().getItemPileAt(selectedSlot[0], selectedSlot[1]);
            ItemPile thisPile = getInventory().getItemPileAt(i, j);
            if (summary) {
                ItemPile summaryBarSelected = getInventory().getItemPileAt(highlightSlot, 0);
                if (summaryBarSelected != null && i == summaryBarSelected.getX()) {
                    sumSlots2HL = summaryBarSelected.getItem().getDefinition().getSlotsWidth();
                }
                if (sumSlots2HL > 0 || (summaryBarSelected == null && highlightSlot == i)) {
                    sumSlots2HL--;
                    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 32f / 256f, 176 / 256f, 56 / 256f, 152 / 256f, inventoryTexture, true, true, color);
                } else
                    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 176 / 256f, 32f / 256f, 152 / 256f, inventoryTexture, true, true, color);
            } else {
                if (mouseOver || (selectedPile != null && thisPile != null && selectedPile.getX() == thisPile.getX() && selectedPile.getY() == thisPile.getY())) {
                    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 32f / 256f, 176 / 256f, 56 / 256f, 152 / 256f, inventoryTexture, true, true, color);
                } else
                    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 176 / 256f, 32f / 256f, 152 / 256f, inventoryTexture, true, true, color);
            }
        }
    }
    // Blank part ( usefull for special inventories, ie player )
    for (int j = getInventory().getHeight(); j < getInventory().getHeight() + blankLines; j++) {
        for (int i = 0; i < getInventory().getWidth(); i++) {
            if (j == getInventory().getHeight()) {
                if (i == getInventory().getWidth() - 1)
                    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 224f / 256f, 152 / 256f, 248 / 256f, 128 / 256f, inventoryTexture, true, true, color);
                else
                    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 152 / 256f, 32f / 256f, 128 / 256f, inventoryTexture, true, true, color);
            } else {
                if (i == getInventory().getWidth() - 1)
                    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 224f / 256f, 56 / 256f, 248 / 256f, 32 / 256f, inventoryTexture, true, true, color);
                else
                    renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 56 / 256f, 32f / 256f, 32 / 256f, inventoryTexture, true, true, color);
            }
        }
    }
    // Top part
    if (!summary) {
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 8f / 256f, 32f / 256f, 32f / 256f, 8f / 256f, inventoryTexture, true, true, color);
        for (int i = 1; i < getInventory().getWidth() - 2; i++) {
            renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 32f / 256f, 32f / 256f, 56f / 256f, 8f / 256f, inventoryTexture, true, true, color);
        }
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + (getInventory().getWidth() - 2) * slotSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 200f / 256f, 32f / 256f, 224 / 256f, 8f / 256f, inventoryTexture, true, true, color);
        closedButton = mouse.getCursorX() > x + cornerSize + (getInventory().getWidth() - 1) * slotSize && mouse.getCursorX() <= x + cornerSize + (getInventory().getWidth() - 1) * slotSize + slotSize && mouse.getCursorY() > y + cornerSize + internalHeight - slotSize && mouse.getCursorY() <= y + cornerSize + internalHeight;
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + (getInventory().getWidth() - 1) * slotSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 224f / 256f, 32f / 256f, 248f / 256f, 8f / 256f, inventoryTexture, true, true, color);
        renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().getFont("LiberationSans-Bold", 12), x + cornerSize + 6, y + cornerSize + internalHeight - slotSize + 2 * scale, getInventory().getInventoryName(), scale, scale, new Vector4f(1, 1, 1, 1));
    }
    // Get rid of any remaining GUI elements or else they will draw on top of the
    // items
    renderer.getGuiRenderer().drawBuffer();
    // Draw the actual items
    for (ItemPile pile : getInventory()) {
        int i = pile.getX();
        int j = pile.getY();
        if (pile != null && (!summary || j == 0)) {
            int center = summary ? slotSize * (pile.getItem().getDefinition().getSlotsHeight() - 1) / 2 : 0;
            pile.getItem().getDefinition().getRenderer().renderItemInInventory(renderer, pile, x + cornerSize + i * slotSize, y - center + cornerSize + j * slotSize, scale);
        }
    }
    // )
    for (ItemPile pile : getInventory()) {
        int i = pile.getX();
        int j = pile.getY();
        if (pile != null && (!summary || j == 0)) {
            int amountToDisplay = pile.getAmount();
            // If we selected this item
            if ((InventoryView.selectedItem != null && InventoryView.selectedItem.getInventory() != null && getInventory().equals(InventoryView.selectedItem.getInventory()) && InventoryView.selectedItem.getX() == i && InventoryView.selectedItem.getY() == j)) {
                amountToDisplay -= InventoryView.selectedItemAmount;
            }
            // Draw amount of items in the pile
            if (amountToDisplay > 1)
                renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), x + cornerSize + ((pile.getItem().getDefinition().getSlotsWidth() - 1.0f) + i) * slotSize, y + cornerSize + j * slotSize, amountToDisplay + "", scale, scale, new Vector4f(1, 1, 1, 1));
        }
    }
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Mouse(io.xol.chunkstories.api.input.Mouse) Vector4f(org.joml.Vector4f) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Example 20 with Vector4f

use of org.joml.Vector4f in project chunkstories by Hugobros3.

the class LevelCreation method render.

@Override
public void render(RenderingInterface renderer) {
    if (parentLayer != null)
        this.parentLayer.render(renderer);
    int scale = gameWindow.getGuiScale();
    renderer.getGuiRenderer().drawBox(-1.0f, -1.0f, 1.0f, 1.0f, 0, 0, 0, 0, null, true, false, new Vector4f(0.0f, 0.0f, 0.0f, 0.25f));
    // int frame_border_size = 64;
    // + frame_border_size;
    float positionStartX = xPosition;
    // + frame_border_size;
    float positionStartY = yPosition;
    // width -= frame_border_size * 2;
    // height -= frame_border_size * 2;
    float x = positionStartX + 20;
    // int y = 48;
    renderer.getGuiRenderer().drawCorneredBoxTiled(positionStartX, positionStartY, width, height, 8, renderer.textures().getTexture("./textures/gui/scalableButton.png"), 32, 2);
    renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().getFont("LiberationSans-Regular", 12), x, positionStartY + height - 64, "Create a new World", 3, 3, new Vector4f(1));
    renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().getFont("LiberationSans-Regular", 12), x, positionStartY + height - 64 - 32, "For use in singleplayer", 2, 2, width, new Vector4f(1));
    renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().getFont("LiberationSans-Regular", 12), x, positionStartY + height - 64 - 96 - 4, "Level name", 2, 2, width, new Vector4f(1));
    int lvlnm_l = renderer.getFontRenderer().getFont("LiberationSans-Regular", 12).getWidth("Level name") * 2;
    levelName.setPosition(x + lvlnm_l + 20, positionStartY + height - 64 - 96);
    levelName.setWidth((width - (x + lvlnm_l + 20) - 20) / 2);
    levelName.render(renderer);
    String wg_string = "World generator to use";
    renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().getFont("LiberationSans-Regular", 12), x, positionStartY + height - 64 - 148 - 4, wg_string, 2, 2, width, new Vector4f(1));
    int wg_sl = renderer.getFontRenderer().getFont("LiberationSans-Regular", 12).getWidth(wg_string) * 2;
    worldGenName.setPosition(x + wg_sl + 20, positionStartY + height - 64 - 148);
    worldGenName.setWidth((width - (x + wg_sl + 20) - 20) / 2);
    worldGenName.render(renderer);
    WorldGeneratorDefinition wg = Client.getInstance().getContent().generators().getWorldGeneratorUnsafe(worldGenName.getText());
    String wg_validity_string;
    if (wg == null) {
        wg_validity_string = "#FF0000'" + worldGenName.getText() + "' wasnt found in the list of loaded world generators.";
    } else {
        wg_validity_string = "#00FF00'" + worldGenName.getText() + "' is a valid world generator !";
    }
    String wg_list = "Available world generators: ";
    Iterator<WorldGeneratorDefinition> iwg = Client.getInstance().getContent().generators().all();
    while (iwg != null && iwg.hasNext()) {
        WorldGeneratorDefinition wgt = iwg.next();
        wg_list += wgt.getName();
        if (iwg.hasNext())
            wg_list += ", ";
    }
    renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().getFont("LiberationSans-Regular", 12), x, positionStartY + height - 64 - 196 - 4, wg_validity_string, 2, 2, width, new Vector4f(1));
    renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().getFont("LiberationSans-Regular", 12), x, positionStartY + height - 64 - 196 - 4 - 32, wg_list, 2, 2, width, new Vector4f(1));
    cancelOption.setPosition(positionStartX + 20 * scale, positionStartY + 20 * scale);
    cancelOption.render(renderer);
    createOption.setPosition(positionStartX + width - createOption.getWidth() - 20 * scale, positionStartY + 20 * scale);
    createOption.render(renderer);
}
Also used : WorldGeneratorDefinition(io.xol.chunkstories.api.content.Content.WorldGenerators.WorldGeneratorDefinition) Vector4f(org.joml.Vector4f)

Aggregations

Vector4f (org.joml.Vector4f)68 Vector3f (org.joml.Vector3f)13 Font (io.xol.chunkstories.api.rendering.text.FontRenderer.Font)12 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)6 Vector3d (org.joml.Vector3d)6 Shader (io.xol.chunkstories.api.rendering.shader.Shader)5 CellData (io.xol.chunkstories.api.world.cell.CellData)5 Vector2f (org.joml.Vector2f)5 Mouse (io.xol.chunkstories.api.input.Mouse)4 Texture2DGL (io.xol.chunkstories.renderer.opengl.texture.Texture2DGL)4 ByteBuffer (java.nio.ByteBuffer)4 Matrix4f (org.joml.Matrix4f)4 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)3 STBEasyFont.stb_easy_font_print (org.lwjgl.stb.STBEasyFont.stb_easy_font_print)3 Location (io.xol.chunkstories.api.Location)2 Entity (io.xol.chunkstories.api.entity.Entity)2 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)2 GuiRenderer (io.xol.chunkstories.api.gui.GuiRenderer)2 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)2 Voxel (io.xol.chunkstories.api.voxel.Voxel)2