public LSL_Vector llRot2Left(LSL_Rotation r)
{
if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID)) return new LSL_Vector();
double m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
// m is always greater than zero
// if m is not equal to 1 then Rotation needs to be normalized
if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
{
m = 1.0 / Math.Sqrt(m);
r.x *= m;
r.y *= m;
r.z *= m;
r.s *= m;
}
// Fast Algebric Calculations instead of Vectors & Quaternions Product
double x = 2 * (r.x * r.y - r.z * r.s);
double y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
double z = 2 * (r.x * r.s + r.y * r.z);
return (new LSL_Vector(x, y, z));
}