setFromRotationMatrix method

Euler setFromRotationMatrix(
  1. dynamic m, [
  2. String? order,
  3. bool? update
])

Implementation

Euler setFromRotationMatrix(m, [String? order, bool? update]) {
  //var clamp = MathUtils.clamp;

  // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)

  final te = m.elements;
  double m11 = te[0], m12 = te[4], m13 = te[8];
  double m21 = te[1], m22 = te[5], m23 = te[9];
  double m31 = te[2], m32 = te[6], m33 = te[10];

  order = order ?? _order;

  switch (order) {
    case 'XYZ':
      _y = Math.asin(MathUtils.clamp(m13, -1, 1));

      if (Math.abs(m13) < 0.9999999) {
        _x = Math.atan2(-m23, m33);
        _z = Math.atan2(-m12, m11);
      } else {
        _x = Math.atan2(m32, m22);
        _z = 0;
      }

      break;

    case 'YXZ':
      _x = Math.asin(-MathUtils.clamp(m23, -1, 1));

      if (Math.abs(m23) < 0.9999999) {
        _y = Math.atan2(m13, m33);
        _z = Math.atan2(m21, m22);
      } else {
        _y = Math.atan2(-m31, m11);
        _z = 0;
      }

      break;

    case 'ZXY':
      _x = Math.asin(MathUtils.clamp(m32, -1, 1));

      if (Math.abs(m32) < 0.9999999) {
        _y = Math.atan2(-m31, m33);
        _z = Math.atan2(-m12, m22);
      } else {
        _y = 0;
        _z = Math.atan2(m21, m11);
      }

      break;

    case 'ZYX':
      _y = Math.asin(-MathUtils.clamp(m31, -1, 1));

      if (Math.abs(m31) < 0.9999999) {
        _x = Math.atan2(m32, m33);
        _z = Math.atan2(m21, m11);
      } else {
        _x = 0;
        _z = Math.atan2(-m12, m22);
      }

      break;

    case 'YZX':
      _z = Math.asin(MathUtils.clamp(m21, -1, 1));

      if (Math.abs(m21) < 0.9999999) {
        _x = Math.atan2(-m23, m22);
        _y = Math.atan2(-m31, m11);
      } else {
        _x = 0;
        _y = Math.atan2(m13, m33);
      }

      break;

    case 'XZY':
      _z = Math.asin(-MathUtils.clamp(m12, -1, 1));

      if (Math.abs(m12) < 0.9999999) {
        _x = Math.atan2(m32, m22);
        _y = Math.atan2(m13, m11);
      } else {
        _x = Math.atan2(-m23, m33);
        _y = 0;
      }

      break;

    default:
      print(
          'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' +
              order);
  }

  _order = order;

  if (update != false) onChangeCallback();

  return this;
}