JOML-CI / JOML

A Java math library for OpenGL rendering calculations
MIT License
728 stars 104 forks source link

MemUtilUnsafe.put3x3(Matrix3x2f m, long destAddr) places 0.0f in the bottom right of the matrix. Should be 1.0f ? #280

Closed nickthecoder closed 3 years ago

nickthecoder commented 3 years ago

In MemUtilUnsafe :

public void put3x3(Matrix3x2f m, long destAddr) {
            UNSAFE.putLong( null, destAddr,    UNSAFE.getLong(m, Matrix3x2f_m00));
            UNSAFE.putInt(  null, destAddr+8,  0);
            UNSAFE.putLong( null, destAddr+12, UNSAFE.getLong(m, Matrix3x2f_m00+8));
            UNSAFE.putInt(  null, destAddr+20, 0);
            UNSAFE.putLong( null, destAddr+24, UNSAFE.getLong(m, Matrix3x2f_m00+16));
            UNSAFE.putFloat(null, destAddr+32, 0.0f); // Wrong??? Should be 1.0f ???
        }

However, I believe that the bottom right corner of the matrix should be 1.0f, not 0.0f. See my comment in the code above. This has the effect of ignoring translations when two matrices are multiplied together.

FYI, the MemUtilNIO implementation does put 1.0f in the bottom right :

public void put3x3(Matrix3x2f m, int offset, FloatBuffer dest) {
            dest.put(offset,   m.m00());
            dest.put(offset+1, m.m01());
            dest.put(offset+2, 0.0f);
            dest.put(offset+3, m.m10());
            dest.put(offset+4, m.m11());
            dest.put(offset+5, 0.0f);
            dest.put(offset+6, m.m20());
            dest.put(offset+7, m.m21());
            dest.put(offset+8, 1.0f); // Correct ;-)
        }
httpdigest commented 3 years ago

Thanks a lot for spotting and reporting!