Inverse Matrix3f

Hello everybody,

is it possible to add the inverse() Method in Matrix3f the same way it’s in TransformMatrix ?

It would be useful for me and i think for lot’s of people since inverting a matrix is often used in Matrix calculation.

(i can extend Matrix 3f and make it myself but i think it would be a good addition to the core of jme :wink: )



Sure, I need that for Mat4 myself… I’ll look into it.

Add this to Matrix3f:

    public Matrix3f inverseLocal()
        float d00 = m11 * m22 - m12 * m21;
        float d10 = m01 * m22 - m02 * m21;
        float d20 = m01 * m12 - m02 * m11;
        float d01 = m10 * m22 - m12 * m20;
        float d11 = m00 * m22 - m02 * m20;
        float d21 = m00 * m12 - m02 * m10;
        float d02 = m10 * m21 - m11 * m20;
        float d12 = m00 * m21 - m01 * m20;
        float d22 = m00 * m11 - m01 * m10;
        float det = m00 * d00 - m01 * d01 + m02 * d02;
        m00 = d00 / det;
        m01 = -d10 / det;
        m02 = d20 / det;
        m10 = -d01 / det;
        m11 = d11 / det;
        m12 = -d21 / det;
        m20 = d02 / det;
        m21 = -d12 / det;
        m22 = d22 / det;
        return this;

I've been trying to do dot3 bump mapping using register combiners, which seems to need inverse matrices.. Never did manage to get it to work properly :?

Thanks, but actually just got done revamping both Matrix3f and Matrix4f… Matrix4f was extensively redone to get away from arrays and fall in line with how matrix3f is done. (which includes adding several new methods to it.) I also added determinant, adjoint, and inverse methods to both. This is in cvs now.

Maybe I missed something… but after updating from cvs just a couple of minutes ago, jme wouldn’t complie anymore. The problem appears to be here, in TransformMatrix:

    public void mult(float scalar) {

The compiler complains about Matrix3f not having a multiply(float) method. Which, as i found looking there, is actually right.

Sorry, it was just not checked in. saw that and checked it in just now. ://

Thanks renanse for this quick update :slight_smile:

one remark : i believed that inverting a 3*3 matrix could be done by putting line as column and column as line (i mean the determinant method was not needed, see TransormMatrix.invertRotInPlace()). Am i wrong ?



As far as I remember that only works for rotation matrices. The full determinant-based approach works on any 3x3 matrix.