Fast 4x4 matrix multiplication in Java with NIO floating point buffers

I know that there are many such questions, but I can’t find one that concerns my situation. I have 4x4 matrices implemented as NIO floating point buffers (these matrices are used for OpenGL). Now I want to implement a multiplication method that multiplies matrix A by matrix B and stores the result in matrix C. Thus, the code may look like this:

class Matrix4f
{
    private FloatBuffer buffer = FloatBuffer.allocate(16);

    public Matrix4f multiply(Matrix4f matrix2, Matrix4f result)
    {
        {{{result = this * matrix2}}} <-- I need this code

        return result;
    }
}

What is the fastest code for this multiplication? Some versions of OpenGL (like the OpenGL ES files in Android) contain native code for this, while others do not. Therefore, I want to provide a general multiplication method for these implementations.

+3
source share
2

, , , .

, , , , , . . -

result[0][0] = this[0][0] * matrix2[0][0] + this[0][1] * matrix2[1][0] 
             + this[0][2] * matrix2[2][0] + this[0][3] * matrix2[3][0];
result[0][1] = // ... and so forth

, , , , $.

+6

Source: https://habr.com/ru/post/1744670/


All Articles