copyRotationInto method

Matrix3 copyRotationInto(
  1. Matrix3 rotationMatrix
)

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

Implementation

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

  final x = _qStorage[0];
  final y = _qStorage[1];
  final z = _qStorage[2];
  final w = _qStorage[3];

  final xs = x * s;
  final ys = y * s;
  final zs = z * s;

  final wx = w * xs;
  final wy = w * ys;
  final wz = w * zs;

  final xx = x * xs;
  final xy = x * ys;
  final xz = x * zs;

  final yy = y * ys;
  final yz = y * zs;
  final zz = z * zs;

  final 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;
}