copyRotationInto method

Matrix3 copyRotationInto (Matrix3 rotationMatrix)

Set rotationMatrix to a rotation matrix containing the same rotation as this.

Implementation

Matrix3 copyRotationInto(Matrix3 rotationMatrix) {
  final double d = length2;
  assert(d != 0.0);
  final double s = 2.0 / d;

  final double _x = _qStorage[0];
  final double _y = _qStorage[1];
  final double _z = _qStorage[2];
  final double _w = _qStorage[3];

  final double xs = _x * s;
  final double ys = _y * s;
  final double zs = _z * s;

  final double wx = _w * xs;
  final double wy = _w * ys;
  final double wz = _w * zs;

  final double xx = _x * xs;
  final double xy = _x * ys;
  final double xz = _x * zs;

  final double yy = _y * ys;
  final double yz = _y * zs;
  final double zz = _z * zs;

  final Float64List rotationMatrixStorage = rotationMatrix.storage;
  rotationMatrixStorage[0] = 1.0 - (yy + zz); // column 0
  rotationMatrixStorage[1] = xy + wz;
  rotationMatrixStorage[2] = xz - wy;
  rotationMatrixStorage[3] = xy - wz; // column 1
  rotationMatrixStorage[4] = 1.0 - (xx + zz);
  rotationMatrixStorage[5] = yz + wx;
  rotationMatrixStorage[6] = xz + wy; // column 2
  rotationMatrixStorage[7] = yz - wx;
  rotationMatrixStorage[8] = 1.0 - (xx + yy);
  return rotationMatrix;
}