rotateByQuaternion method

Matrix3 rotateByQuaternion(
  1. Quaternion r
)

Implementation

Matrix3 rotateByQuaternion(Quaternion r) {
  final double aa = r.x * r.x;
  final double bb = r.y * r.y;
  final double cc = r.z * r.z;
  final double dd = r.w * r.w;

  final double ab = r.x * r.y;
  final double ac = r.x * r.z;
  final double bc = r.y * r.z;

  final double ad = r.x * r.w;
  final double bd = r.y * r.w;
  final double cd = r.z * r.w;

  storage[0] = aa - bb - cc + dd;
  storage[1] = 2 * ab - 2 * cd;
  storage[2] = 2 * ac + 2 * bd;
  storage[3] = 2 * ab + 2 * cd;
  storage[4] = -aa + bb - cc + dd;
  storage[5] = 2 * bc - 2 * ad;
  storage[6] = 2 * ac - 2 * bd;
  storage[7] = 2 * bc + 2 * ad;
  storage[8] = -aa - bb + cc + dd;

  return this;
}