setRandom method
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 x0 = rn.nextDouble();
final r1 = math.sqrt(1.0 - x0);
final r2 = math.sqrt(x0);
final t1 = math.pi * 2.0 * rn.nextDouble();
final t2 = math.pi * 2.0 * rn.nextDouble();
final c1 = math.cos(t1);
final s1 = math.sin(t1);
final c2 = math.cos(t2);
final s2 = math.sin(t2);
_qStorage[0] = s1 * r1;
_qStorage[1] = c1 * r1;
_qStorage[2] = s2 * r2;
_qStorage[3] = c2 * r2;
}