Java Array Multiply multiply(float[] mat, float[] mat2, float[] dest)

Here you can find the source of multiply(float[] mat, float[] mat2, float[] dest)

Description

multiply

License

Open Source License

Declaration

public static float[] multiply(float[] mat, float[] mat2, float[] dest) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static float[] multiply(float[] mat, float[] mat2, float[] dest) {
        if (dest == null) {
            dest = mat;/*  w  ww.ja v a 2  s.com*/
        }

        // Cache the matrix values (makes for huge speed increases!)
        float a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
        float a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
        float a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
        float a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];

        // Cache only the current line of the second matrix
        float b0 = mat2[0], b1 = mat2[1], b2 = mat2[2], b3 = mat2[3];
        dest[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
        dest[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
        dest[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
        dest[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;

        b0 = mat2[4];
        b1 = mat2[5];
        b2 = mat2[6];
        b3 = mat2[7];
        dest[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
        dest[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
        dest[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
        dest[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;

        b0 = mat2[8];
        b1 = mat2[9];
        b2 = mat2[10];
        b3 = mat2[11];
        dest[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
        dest[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
        dest[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
        dest[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;

        b0 = mat2[12];
        b1 = mat2[13];
        b2 = mat2[14];
        b3 = mat2[15];
        dest[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
        dest[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
        dest[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
        dest[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;

        return dest;
    }
}

Related

  1. multiply(final float[] complexA, final float[] complexB, final boolean overwriteA)
  2. multiply(final int[] numbers)
  3. multiply(float[] array, float factor)
  4. multiply(float[] array, int multiplier)
  5. multiply(float[] in, float f)
  6. multiply(float[] v, double factor)
  7. multiply(float[] v1, float[] v2)
  8. multiply(long[] x, long[] y, long[] z)
  9. multiply(long[] x, long[] y, long[] z)