setRandom method

void setRandom (Random rn)

Set the quaternion to a random rotation. The random number generator rn is used to generate the random numbers for the rotation.

Implementation

void setRandom(math.Random rn) {
  // From: "Uniform Random Rotations", Ken Shoemake, Graphics Gems III,
  // pg. 124-132.
  final double x0 = rn.nextDouble();
  final double r1 = math.sqrt(1.0 - x0);
  final double r2 = math.sqrt(x0);
  final double t1 = math.pi * 2.0 * rn.nextDouble();
  final double t2 = math.pi * 2.0 * rn.nextDouble();
  final double c1 = math.cos(t1);
  final double s1 = math.sin(t1);
  final double c2 = math.cos(t2);
  final double s2 = math.sin(t2);
  _qStorage[0] = s1 * r1;
  _qStorage[1] = c1 * r1;
  _qStorage[2] = s2 * r2;
  _qStorage[3] = c2 * r2;
}