Is my 4x4 matrix multiplication on a 1D float array correct? I'm trying to develop my own math library to use on a Voxel engine, but I'm worried about Matrices multiplication. Everywhere I saw people using 4x4 Matrices on a 2D Float Array but I'm using a 1D Float Array because of performance needs.

    public float[] multiplicate(float[] factor){
        float[] result = new float[factor.length];
        for (int i = 0, a = 0, b = 0; i &lt; factor.length; i++){
            a = (i/4)*4;
            b = (i%4);
            result[i] = (mat4f[a] * factor[b]) + (mat4f[a+1] * factor[b+4]) + (mat4f[a+2] * factor[b+8]) + (mat4f[a+3] * factor[b+12]);
        }
        return result;
    }


EDIT: I'm using a 1D array to store the 4x4 Vector. If I use 16 float variables instead, should I gain in performance or memory usage? The code should be like that:

    r00 = a00*b00+a01*b10+a02*b20+a03*b30;
    r01 = a00*b01+a01*b11+a02*b21+a03*b31;
    r02 = a00*b02+a01*b12+a02*b22+a03*b32;
    r03 = a00*b03+a01*b13+a02*b23+a03*b33;


    r10 = a10*b00+a11*b10+a12*b20+a13*b30;
    r11 = a10*b01+a11*b11+a12*b21+a13*b31;
    r12 = a10*b02+a11*b12+a12*b22+a13*b32;
    r13 = a10*b03+a11*b13+a12*b23+a13*b33;

    r20 = a20*b00+a21*b10+a22*b20+a23*b30;
    r21 = a20*b01+a21*b11+a22*b21+a23*b31;
    r22 = a20*b02+a21*b12+a22*b22+a23*b32;
    r23 = a20*b03+a21*b13+a22*b23+a23*b33;


    r30 = a30*b00+a31*b10+a32*b20+a33*b30;
    r31 = a30*b01+a31*b11+a32*b21+a33*b31;
    r32 = a30*b02+a31*b12+a32*b22+a33*b32;
    r33 = a30*b03+a31*b13+a32*b23+a33*b33;


Where r00~r33 are 16 float variables where I store the result and later set to my 16 float main fields...The variables a00~a33 and b00~b33 are the factors variables.

So if I use fixed fields instead of a float array, should I gain in performance or memory usage?
My final code is:

public float[] multiplicate(float[] factor){
    int a = 0;
    int b = 0;
    float[] result = new float[factor.length];
    for (int i = 0; i &lt; factor.length; i++){
        a = (i/4)*4;
        b = (i%4);
        result[i] = (mat4f[a] * factor[b]) + (mat4f[a+1] * factor[b+4]) + (mat4f[a+2] * factor[b+8]) + (mat4f[a+3] * factor[b+12]);
    }
    return result;
}


I'll keeping using 1D float array because I'll need to use a FloatBuffer to send it to OpenGL (using LWJGL). So i'll get less overhead by calling one FloatBuffer.put(myArrFloatVar) then FloatBuffer.put(new float[]{r00, r01...r33} or event calling FloatBuffer.put(r00) 16 times.