matrixEulerAngles property

Vector3 get matrixEulerAngles

Implementation

Vector3 get matrixEulerAngles {
  final q = Quaternion(0, 0, 0, 0);
  decompose(Vector3.zero(), q, Vector3.zero());

  final t = q.x;
  q.x = q.y;
  q.y = t;

  final angles = Vector3.zero();

  // roll (x-axis rotation)
  final sinrCosp = 2 * (q.w * q.x + q.y * q.z);
  final cosrCosp = 1 - 2 * (q.x * q.x + q.y * q.y);
  angles[0] = math.atan2(sinrCosp, cosrCosp);

  // pitch (y-axis rotation)
  final sinp = 2 * (q.w * q.y - q.z * q.x);
  if (sinp.abs() >= 1) {
    angles[1] =
        _copySign(math.pi / 2, sinp); // use 90 degrees if out of range
  } else {
    angles[1] = math.asin(sinp);
  }
  // yaw (z-axis rotation)
  final sinyCosp = 2 * (q.w * q.z + q.x * q.y);
  final cosyCosp = 1 - 2 * (q.y * q.y + q.z * q.z);
  angles[2] = math.atan2(sinyCosp, cosyCosp);

  return angles;
}
set matrixEulerAngles (Vector3 angles)

Implementation

set matrixEulerAngles(Vector3 angles) {
  final translation = Vector3.zero();
  final scale = Vector3.zero();
  decompose(translation, Quaternion(0, 0, 0, 0), scale);
  final r = Quaternion.euler(angles[0], angles[1], angles[2]);
  setFromTranslationRotationScale(translation, r, scale);
}