Search in sources :

Example 1 with Matrix4f

use of com.mojang.math.Matrix4f in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method handleCameraTransforms.

public static BakedModel handleCameraTransforms(PoseStack matrixStack, BakedModel model, ItemTransforms.TransformType cameraTransformType, boolean leftHandHackery) {
    PoseStack stack = new PoseStack();
    model = model.handlePerspective(cameraTransformType, stack);
    // If the stack is not empty, the code has added a matrix for us to use.
    if (!stack.clear()) {
        // Apply the transformation to the real matrix stack, flipping for left hand
        Matrix4f tMat = stack.last().pose();
        Matrix3f nMat = stack.last().normal();
        if (leftHandHackery) {
            tMat.multiplyBackward(flipX);
            tMat.multiply(flipX);
            nMat.multiplyBackward(flipXNormal);
            nMat.mul(flipXNormal);
        }
        matrixStack.last().pose().multiply(tMat);
        matrixStack.last().normal().mul(nMat);
    }
    return model;
}
Also used : Matrix4f(com.mojang.math.Matrix4f) Matrix3f(com.mojang.math.Matrix3f)

Example 2 with Matrix4f

use of com.mojang.math.Matrix4f in project MinecraftForge by MinecraftForge.

the class GuiUtils method drawTexturedModalRect.

public static void drawTexturedModalRect(PoseStack matrixStack, int x, int y, int u, int v, int width, int height, float zLevel) {
    final float uScale = 1f / 0x100;
    final float vScale = 1f / 0x100;
    Tesselator tessellator = Tesselator.getInstance();
    BufferBuilder wr = tessellator.getBuilder();
    wr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
    Matrix4f matrix = matrixStack.last().pose();
    wr.vertex(matrix, x, y + height, zLevel).uv(u * uScale, ((v + height) * vScale)).endVertex();
    wr.vertex(matrix, x + width, y + height, zLevel).uv((u + width) * uScale, ((v + height) * vScale)).endVertex();
    wr.vertex(matrix, x + width, y, zLevel).uv((u + width) * uScale, (v * vScale)).endVertex();
    wr.vertex(matrix, x, y, zLevel).uv(u * uScale, (v * vScale)).endVertex();
    tessellator.end();
}
Also used : Matrix4f(com.mojang.math.Matrix4f) BufferBuilder(com.mojang.blaze3d.vertex.BufferBuilder) Tesselator(com.mojang.blaze3d.vertex.Tesselator)

Example 3 with Matrix4f

use of com.mojang.math.Matrix4f in project MinecraftForge by MinecraftForge.

the class IForgeVertexConsumer method putBulkData.

// Copy of putBulkData with alpha support
default void putBulkData(PoseStack.Pose matrixEntry, BakedQuad bakedQuad, float[] baseBrightness, float red, float green, float blue, float alpha, int[] lightmapCoords, int overlayCoords, boolean readExistingColor) {
    int[] aint = bakedQuad.getVertices();
    Vec3i faceNormal = bakedQuad.getDirection().getNormal();
    Vector3f normal = new Vector3f((float) faceNormal.getX(), (float) faceNormal.getY(), (float) faceNormal.getZ());
    Matrix4f matrix4f = matrixEntry.pose();
    normal.transform(matrixEntry.normal());
    int intSize = DefaultVertexFormat.BLOCK.getIntegerSize();
    int vertexCount = aint.length / intSize;
    try (MemoryStack memorystack = MemoryStack.stackPush()) {
        ByteBuffer bytebuffer = memorystack.malloc(DefaultVertexFormat.BLOCK.getVertexSize());
        IntBuffer intbuffer = bytebuffer.asIntBuffer();
        for (int v = 0; v < vertexCount; ++v) {
            ((Buffer) intbuffer).clear();
            intbuffer.put(aint, v * 8, 8);
            float f = bytebuffer.getFloat(0);
            float f1 = bytebuffer.getFloat(4);
            float f2 = bytebuffer.getFloat(8);
            float cr;
            float cg;
            float cb;
            float ca;
            if (readExistingColor) {
                float r = (float) (bytebuffer.get(12) & 255) / 255.0F;
                float g = (float) (bytebuffer.get(13) & 255) / 255.0F;
                float b = (float) (bytebuffer.get(14) & 255) / 255.0F;
                float a = (float) (bytebuffer.get(15) & 255) / 255.0F;
                cr = r * baseBrightness[v] * red;
                cg = g * baseBrightness[v] * green;
                cb = b * baseBrightness[v] * blue;
                ca = a * alpha;
            } else {
                cr = baseBrightness[v] * red;
                cg = baseBrightness[v] * green;
                cb = baseBrightness[v] * blue;
                ca = alpha;
            }
            int lightmapCoord = applyBakedLighting(lightmapCoords[v], bytebuffer);
            float f9 = bytebuffer.getFloat(16);
            float f10 = bytebuffer.getFloat(20);
            Vector4f pos = new Vector4f(f, f1, f2, 1.0F);
            pos.transform(matrix4f);
            applyBakedNormals(normal, bytebuffer, matrixEntry.normal());
            ((VertexConsumer) this).vertex(pos.x(), pos.y(), pos.z(), cr, cg, cb, ca, f9, f10, overlayCoords, lightmapCoord, normal.x(), normal.y(), normal.z());
        }
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) IntBuffer(java.nio.IntBuffer) Buffer(java.nio.Buffer) Vec3i(net.minecraft.core.Vec3i) Matrix4f(com.mojang.math.Matrix4f) Vector4f(com.mojang.math.Vector4f) MemoryStack(org.lwjgl.system.MemoryStack) Vector3f(com.mojang.math.Vector3f) IntBuffer(java.nio.IntBuffer) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Matrix4f (com.mojang.math.Matrix4f)3 BufferBuilder (com.mojang.blaze3d.vertex.BufferBuilder)1 Tesselator (com.mojang.blaze3d.vertex.Tesselator)1 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)1 Matrix3f (com.mojang.math.Matrix3f)1 Vector3f (com.mojang.math.Vector3f)1 Vector4f (com.mojang.math.Vector4f)1 Buffer (java.nio.Buffer)1 ByteBuffer (java.nio.ByteBuffer)1 IntBuffer (java.nio.IntBuffer)1 Vec3i (net.minecraft.core.Vec3i)1 MemoryStack (org.lwjgl.system.MemoryStack)1