Fast 4x4 matrix multiplication in Java with NIO float buffers
- by kayahr
I know there are LOT of questions like that but I can't find one specific to my situation. I have 4x4 matrices implemented as NIO float buffers (These matrices are used for OpenGL). Now I want to implement a multiply method which multiplies Matrix A with Matrix B and stores the result in Matrix C. So 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 possible code to do this multiplication? Some OpenGL implementations (Like the OpenGL ES stuff in Android) provide native code for this but others doesn't. So I want to provide a generic multiplication method for these implementations.