setFromEuler method

Quaternion setFromEuler(
  1. Euler euler, [
  2. bool update = false
])

Implementation

Quaternion setFromEuler(Euler euler, [bool update = false]) {
  var x = euler.x;
  var y = euler.y;
  var z = euler.z;
  var order = euler.order;

  // http://www.mathworks.com/matlabcentral/fileexchange/
  // 	20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  //	content/SpinCalc.m

  var cos = Math.cos;
  var sin = Math.sin;

  var c1 = cos(x / 2);
  var c2 = cos(y / 2);
  var c3 = cos(z / 2);

  var s1 = sin(x / 2);
  var s2 = sin(y / 2);
  var s3 = sin(z / 2);

  switch (order) {
    case 'XYZ':
      _x = s1 * c2 * c3 + c1 * s2 * s3;
      _y = c1 * s2 * c3 - s1 * c2 * s3;
      _z = c1 * c2 * s3 + s1 * s2 * c3;
      _w = c1 * c2 * c3 - s1 * s2 * s3;

      break;

    case 'YXZ':
      _x = s1 * c2 * c3 + c1 * s2 * s3;
      _y = c1 * s2 * c3 - s1 * c2 * s3;
      _z = c1 * c2 * s3 - s1 * s2 * c3;
      _w = c1 * c2 * c3 + s1 * s2 * s3;
      break;

    case 'ZXY':
      _x = s1 * c2 * c3 - c1 * s2 * s3;
      _y = c1 * s2 * c3 + s1 * c2 * s3;
      _z = c1 * c2 * s3 + s1 * s2 * c3;
      _w = c1 * c2 * c3 - s1 * s2 * s3;
      break;

    case 'ZYX':
      _x = s1 * c2 * c3 - c1 * s2 * s3;
      _y = c1 * s2 * c3 + s1 * c2 * s3;
      _z = c1 * c2 * s3 - s1 * s2 * c3;
      _w = c1 * c2 * c3 + s1 * s2 * s3;
      break;

    case 'YZX':
      _x = s1 * c2 * c3 + c1 * s2 * s3;
      _y = c1 * s2 * c3 + s1 * c2 * s3;
      _z = c1 * c2 * s3 - s1 * s2 * c3;
      _w = c1 * c2 * c3 - s1 * s2 * s3;
      break;

    case 'XZY':
      _x = s1 * c2 * c3 - c1 * s2 * s3;
      _y = c1 * s2 * c3 - s1 * c2 * s3;
      _z = c1 * c2 * s3 + s1 * s2 * c3;
      _w = c1 * c2 * c3 + s1 * s2 * s3;
      break;

    default:
      print('three.Quaternion: .setFromEuler() encountered an unknown order: $order');
  }

  if (update) {
    onChangeCallback();
  }
  return this;
}