setDirection method

dynamic setDirection(
  1. dynamic dir
)

Implementation

setDirection(dir) {
  // dir is assumed to be normalized

  if (dir.y > 0.99999) {
    quaternion.set(0, 0, 0, 1);
  } else if (dir.y < -0.99999) {
    quaternion.set(1, 0, 0, 0);
  } else {
    _axis.set(dir.z, 0, -dir.x).normalize();

    var radians = Math.acos(dir.y);

    quaternion.setFromAxisAngle(_axis, radians);
  }
}