applyQuaternion method

Vector3 applyQuaternion(
  1. Array quat
)

Implementation

Vector3 applyQuaternion(Array quat) {
  assert(listEqual(quat.shape.toList(), [4, 1]));

  var quatValues = quat.getColumn(0);

  var qx = quatValues[0];
  var qy = quatValues[1];
  var qz = quatValues[2];
  var qw = quatValues[3];

  var ix = qw * x + qy * z - qz * y;
  var iy = qw * y + qz * x - qx * z;
  var iz = qw * z + qx * y - qy * x;
  var iw = -qx * x - qy * y - qz * z;

  return Vector3(
      ix * qw + iw * -qx + iy * -qz - iz * -qy,
      iy * qw + iw * -qy + iz * -qx - ix * -qz,
      iz * qw + iw * -qz + ix * -qy - iy * -qx);
}