From b242ead6df06f013f507a4a15495a2720ec5d089 Mon Sep 17 00:00:00 2001 From: dahlia Date: Mon, 10 Jun 2013 17:10:04 -0700 Subject: llRot2Axis now checks absolute value of s rotation component before normalizing. Also removed some excessive division and cleaned up a bit --- .../Shared/Api/Implementation/LSL_Api.cs | 28 +++++----------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 9427061..c48285a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -4665,37 +4665,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Vector llRot2Axis(LSL_Rotation rot) { m_host.AddScriptLPS(1); - double x,y,z; + double x, y, z; - if (rot.s > 1) // normalization needed - { - double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y + - rot.z * rot.z + rot.s * rot.s); - - rot.x /= length; - rot.y /= length; - rot.z /= length; - rot.s /= length; - - } + if (Math.Abs(rot.s) > 1) // normalization needed + rot.Normalize(); - // double angle = 2 * Math.Acos(rot.s); double s = Math.Sqrt(1 - rot.s * rot.s); if (s < 0.001) { - x = 1; - y = z = 0; + return new LSL_Vector(1, 0, 0); } else { - x = rot.x / s; // normalise axis - y = rot.y / s; - z = rot.z / s; + double invS = 1.0 / s; + return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS); } - if ((double.IsNaN(x)) || double.IsInfinity(x)) x = 0; - if ((double.IsNaN(y)) || double.IsInfinity(y)) y = 0; - if ((double.IsNaN(z)) || double.IsInfinity(z)) z = 0; - return new LSL_Vector(x,y,z); } -- cgit v1.1