Search in sources :

Example 6 with Vector3f

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

the class QuadTransformer method processVertices.

private void processVertices(int[] inData, int[] outData) {
    int stride = DefaultVertexFormat.BLOCK.getVertexSize();
    int count = (inData.length * 4) / stride;
    for (int i = 0; i < count; i++) {
        int offset = POSITION + i * stride;
        float x = Float.intBitsToFloat(getAtByteOffset(inData, offset));
        float y = Float.intBitsToFloat(getAtByteOffset(inData, offset + 4));
        float z = Float.intBitsToFloat(getAtByteOffset(inData, offset + 8));
        Vector4f pos = new Vector4f(x, y, z, 1);
        transform.transformPosition(pos);
        pos.perspectiveDivide();
        putAtByteOffset(outData, offset, Float.floatToRawIntBits(pos.x()));
        putAtByteOffset(outData, offset + 4, Float.floatToRawIntBits(pos.y()));
        putAtByteOffset(outData, offset + 8, Float.floatToRawIntBits(pos.z()));
    }
    for (int i = 0; i < count; i++) {
        int offset = NORMAL + i * stride;
        int normalIn = getAtByteOffset(inData, offset);
        if (normalIn != 0) {
            float x = ((byte) ((normalIn) >> 24)) / 127.0f;
            float y = ((byte) ((normalIn << 8) >> 24)) / 127.0f;
            float z = ((byte) ((normalIn << 16) >> 24)) / 127.0f;
            Vector3f pos = new Vector3f(x, y, z);
            transform.transformNormal(pos);
            pos.normalize();
            int normalOut = ((((byte) (x / 127.0f)) & 0xFF) << 24) | ((((byte) (y / 127.0f)) & 0xFF) << 16) | ((((byte) (z / 127.0f)) & 0xFF) << 8) | (normalIn & 0xFF);
            putAtByteOffset(outData, offset, normalOut);
        }
    }
}
Also used : Vector4f(com.mojang.math.Vector4f) Vector3f(com.mojang.math.Vector3f)

Example 7 with Vector3f

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

the class TransformationHelper method lerp.

public static Vector3f lerp(Vector3f from, Vector3f to, float progress) {
    Vector3f res = from.copy();
    res.lerp(to, progress);
    return res;
}
Also used : Vector3f(com.mojang.math.Vector3f)

Aggregations

Vector3f (com.mojang.math.Vector3f)7 Vector4f (com.mojang.math.Vector4f)5 DefaultVertexFormat (com.mojang.blaze3d.vertex.DefaultVertexFormat)1 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)1 VertexFormat (com.mojang.blaze3d.vertex.VertexFormat)1 VertexFormatElement (com.mojang.blaze3d.vertex.VertexFormatElement)1 Matrix4f (com.mojang.math.Matrix4f)1 Transformation (com.mojang.math.Transformation)1 Buffer (java.nio.Buffer)1 ByteBuffer (java.nio.ByteBuffer)1 IntBuffer (java.nio.IntBuffer)1 Direction (net.minecraft.core.Direction)1 Vec3i (net.minecraft.core.Vec3i)1 Vec2 (net.minecraft.world.phys.Vec2)1 BakedQuadBuilder (net.minecraftforge.client.model.pipeline.BakedQuadBuilder)1 MemoryStack (org.lwjgl.system.MemoryStack)1