+
+ /** multiply by another matrix */
+ public Matrix times(Matrix z) {
+ float t00 = a;
+ float t01 = b;
+ float t02 = c;
+ float t03 = d;
+ float t10 = e;
+ float t11 = f;
+ float t12 = g;
+ float t13 = h;
+ float t20 = i;
+ float t21 = j;
+ float t22 = k;
+ float t23 = l;
+ float t30 = m;
+ float t31 = n;
+ float t32 = o;
+ float t33 = p;
+ float m00 = z.a;
+ float m01 = z.b;
+ float m02 = z.c;
+ float m03 = z.d;
+ float m10 = z.e;
+ float m11 = z.f;
+ float m12 = z.g;
+ float m13 = z.h;
+ float m20 = z.i;
+ float m21 = z.j;
+ float m22 = z.k;
+ float m23 = z.l;
+ float m30 = z.m;
+ float m31 = z.n;
+ float m32 = z.o;
+ float m33 = z.p;
+ return new Matrix(t00*m00 + t01*m10 + t02*m20 + t03*m30,
+ t00*m01 + t01*m11 + t02*m21 + t03*m31,
+ t00*m02 + t01*m12 + t02*m22 + t03*m32,
+ t00*m03 + t01*m13 + t02*m23 + t03*m33,
+ t10*m00 + t11*m10 + t12*m20 + t13*m30,
+ t10*m01 + t11*m11 + t12*m21 + t13*m31,
+ t10*m02 + t11*m12 + t12*m22 + t13*m32,
+ t10*m03 + t11*m13 + t12*m23 + t13*m33,
+ t20*m00 + t21*m10 + t22*m20 + t23*m30,
+ t20*m01 + t21*m11 + t22*m21 + t23*m31,
+ t20*m02 + t21*m12 + t22*m22 + t23*m32,
+ t20*m03 + t21*m13 + t22*m23 + t23*m33,
+ t30*m00 + t31*m10 + t32*m20 + t33*m30,
+ t30*m01 + t31*m11 + t32*m21 + t33*m31,
+ t30*m02 + t31*m12 + t32*m22 + t33*m32,
+ t30*m03 + t31*m13 + t32*m23 + t33*m33);
+ }
+
+ /** compute the determinant of the matrix */
+ public float determinant() {
+ float m00 = a;
+ float m01 = b;
+ float m02 = c;
+ float m03 = d;
+ float m10 = e;
+ float m11 = f;
+ float m12 = g;
+ float m13 = h;
+ float m20 = i;
+ float m21 = j;
+ float m22 = k;
+ float m23 = l;
+ float m30 = m;
+ float m31 = n;
+ float m32 = o;
+ float m33 = p;
+ return
+ m03 * m12 * m21 * m30-m02 * m13 * m21 * m30-m03 * m11 * m22 * m30+m01 * m13 * m22 * m30+
+ m02 * m11 * m23 * m30-m01 * m12 * m23 * m30-m03 * m12 * m20 * m31+m02 * m13 * m20 * m31+
+ m03 * m10 * m22 * m31-m00 * m13 * m22 * m31-m02 * m10 * m23 * m31+m00 * m12 * m23 * m31+
+ m03 * m11 * m20 * m32-m01 * m13 * m20 * m32-m03 * m10 * m21 * m32+m00 * m13 * m21 * m32+
+ m01 * m10 * m23 * m32-m00 * m11 * m23 * m32-m02 * m11 * m20 * m33+m01 * m12 * m20 * m33+
+ m02 * m10 * m21 * m33-m00 * m12 * m21 * m33-m01 * m10 * m22 * m33+m00 * m11 * m22 * m33;
+ }
+
+ /** compute the inverse of the matrix, returns null if not invertible */
+ public Matrix inverse() {
+ float determinant = determinant();
+ if (determinant==0) return null;
+ float m00 = a;
+ float m01 = b;
+ float m02 = c;
+ float m03 = d;
+ float m10 = e;
+ float m11 = f;
+ float m12 = g;
+ float m13 = h;
+ float m20 = i;
+ float m21 = j;
+ float m22 = k;
+ float m23 = l;
+ float m30 = m;
+ float m31 = n;
+ float m32 = o;
+ float m33 = p;
+ return
+ new Matrix(m12*m23*m31 - m13*m22*m31 + m13*m21*m32 - m11*m23*m32 - m12*m21*m33 + m11*m22*m33,
+ m03*m22*m31 - m02*m23*m31 - m03*m21*m32 + m01*m23*m32 + m02*m21*m33 - m01*m22*m33,
+ m02*m13*m31 - m03*m12*m31 + m03*m11*m32 - m01*m13*m32 - m02*m11*m33 + m01*m12*m33,
+ m03*m12*m21 - m02*m13*m21 - m03*m11*m22 + m01*m13*m22 + m02*m11*m23 - m01*m12*m23,
+ m13*m22*m30 - m12*m23*m30 - m13*m20*m32 + m10*m23*m32 + m12*m20*m33 - m10*m22*m33,
+ m02*m23*m30 - m03*m22*m30 + m03*m20*m32 - m00*m23*m32 - m02*m20*m33 + m00*m22*m33,
+ m03*m12*m30 - m02*m13*m30 - m03*m10*m32 + m00*m13*m32 + m02*m10*m33 - m00*m12*m33,
+ m02*m13*m20 - m03*m12*m20 + m03*m10*m22 - m00*m13*m22 - m02*m10*m23 + m00*m12*m23,
+ m11*m23*m30 - m13*m21*m30 + m13*m20*m31 - m10*m23*m31 - m11*m20*m33 + m10*m21*m33,
+ m03*m21*m30 - m01*m23*m30 - m03*m20*m31 + m00*m23*m31 + m01*m20*m33 - m00*m21*m33,
+ m01*m13*m30 - m03*m11*m30 + m03*m10*m31 - m00*m13*m31 - m01*m10*m33 + m00*m11*m33,
+ m03*m11*m20 - m01*m13*m20 - m03*m10*m21 + m00*m13*m21 + m01*m10*m23 - m00*m11*m23,
+ m12*m21*m30 - m11*m22*m30 - m12*m20*m31 + m10*m22*m31 + m11*m20*m32 - m10*m21*m32,
+ m01*m22*m30 - m02*m21*m30 + m02*m20*m31 - m00*m22*m31 - m01*m20*m32 + m00*m21*m32,
+ m02*m11*m30 - m01*m12*m30 - m02*m10*m31 + m00*m12*m31 + m01*m10*m32 - m00*m11*m32,
+ m01*m12*m20 - m02*m11*m20 + m02*m10*m21 - m00*m12*m21 - m01*m10*m22 + m00*m11*m22)
+ .times(1/determinant);
+ }
+