User:Pedro Oval/Uniform random rotation

From Second Life Wiki
< User:Pedro Oval
Revision as of 06:17, 11 January 2011 by Pedro Oval (talk | contribs) (Added Uniform random rotation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Based on a "graphics gem" by Ken Shoemake [1]

<lsl> rotation UniformRandRot() {

   // Method from Graphic Gems 3, "Uniform Random Rotations"
   // by Ken Shoemake, p.130
   float x0 = llFrand(1.0);
   float a1 = llFrand(TWO_PI);
   float a2 = llFrand(TWO_PI);
   float r1 = llSqrt(1.0 - x0);
   float r2 = llSqrt(x0);
   float s1 = llSin(a1);
   float c1 = llCos(a1);
   float s2 = llSin(a2);
   float c2 = llCos(a2);
   return <s1*r1, c1*r1, s2*r2, c2*r2>;

} </lsl>