copyInverse method

double copyInverse (
  1. Matrix4 arg
)

Set this matrix to be the inverse of arg

Implementation

double copyInverse(Matrix4 arg) {
  final Float32List argStorage = arg._m4storage;
  final double a00 = argStorage[0];
  final double a01 = argStorage[1];
  final double a02 = argStorage[2];
  final double a03 = argStorage[3];
  final double a10 = argStorage[4];
  final double a11 = argStorage[5];
  final double a12 = argStorage[6];
  final double a13 = argStorage[7];
  final double a20 = argStorage[8];
  final double a21 = argStorage[9];
  final double a22 = argStorage[10];
  final double a23 = argStorage[11];
  final double a30 = argStorage[12];
  final double a31 = argStorage[13];
  final double a32 = argStorage[14];
  final double a33 = argStorage[15];
  final double b00 = a00 * a11 - a01 * a10;
  final double b01 = a00 * a12 - a02 * a10;
  final double b02 = a00 * a13 - a03 * a10;
  final double b03 = a01 * a12 - a02 * a11;
  final double b04 = a01 * a13 - a03 * a11;
  final double b05 = a02 * a13 - a03 * a12;
  final double b06 = a20 * a31 - a21 * a30;
  final double b07 = a20 * a32 - a22 * a30;
  final double b08 = a20 * a33 - a23 * a30;
  final double b09 = a21 * a32 - a22 * a31;
  final double b10 = a21 * a33 - a23 * a31;
  final double b11 = a22 * a33 - a23 * a32;
  final double det =
      (b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06);
  if (det == 0.0) {
    setFrom(arg);
    return 0.0;
  }
  final double invDet = 1.0 / det;
  _m4storage[0] = (a11 * b11 - a12 * b10 + a13 * b09) * invDet;
  _m4storage[1] = (-a01 * b11 + a02 * b10 - a03 * b09) * invDet;
  _m4storage[2] = (a31 * b05 - a32 * b04 + a33 * b03) * invDet;
  _m4storage[3] = (-a21 * b05 + a22 * b04 - a23 * b03) * invDet;
  _m4storage[4] = (-a10 * b11 + a12 * b08 - a13 * b07) * invDet;
  _m4storage[5] = (a00 * b11 - a02 * b08 + a03 * b07) * invDet;
  _m4storage[6] = (-a30 * b05 + a32 * b02 - a33 * b01) * invDet;
  _m4storage[7] = (a20 * b05 - a22 * b02 + a23 * b01) * invDet;
  _m4storage[8] = (a10 * b10 - a11 * b08 + a13 * b06) * invDet;
  _m4storage[9] = (-a00 * b10 + a01 * b08 - a03 * b06) * invDet;
  _m4storage[10] = (a30 * b04 - a31 * b02 + a33 * b00) * invDet;
  _m4storage[11] = (-a20 * b04 + a21 * b02 - a23 * b00) * invDet;
  _m4storage[12] = (-a10 * b09 + a11 * b07 - a12 * b06) * invDet;
  _m4storage[13] = (a00 * b09 - a01 * b07 + a02 * b06) * invDet;
  _m4storage[14] = (-a30 * b03 + a31 * b01 - a32 * b00) * invDet;
  _m4storage[15] = (a20 * b03 - a21 * b01 + a22 * b00) * invDet;
  return det;
}