From 037e5d8031c715c2e765a7cfd67afcf442aeeaa0 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 19 Apr 2018 19:21:08 +0100 Subject: [PATCH] save a few ns --- OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 0c17a90c59..e9ee9371bc 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -392,8 +392,8 @@ namespace OpenSim.Region.ScriptEngine.Shared #region Methods public Quaternion Normalize() { - double length = Math.Sqrt(x * x + y * y + z * z + s * s); - if (length < float.Epsilon) + double lengthsq = x * x + y * y + z * z + s * s; + if (lengthsq < float.Epsilon) { x = 0; y = 0; @@ -403,7 +403,7 @@ namespace OpenSim.Region.ScriptEngine.Shared else { - double invLength = 1.0 / length; + double invLength = 1.0 / Math.Sqrt(lengthsq); x *= invLength; y *= invLength; z *= invLength; @@ -474,7 +474,8 @@ namespace OpenSim.Region.ScriptEngine.Shared { // LSL quaternions can normalize to 0, normal Quaternions can't. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0) - rot.z = 1; // ZERO_ROTATION = 0,0,0,1 + return OMV_Quaternion.Identity; // ZERO_ROTATION = 0,0,0,1 + OMV_Quaternion omvrot = new OMV_Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s); omvrot.Normalize(); return omvrot; @@ -510,6 +511,7 @@ namespace OpenSim.Region.ScriptEngine.Shared public static Quaternion operator /(Quaternion a, Quaternion b) { + // assuming normalized b.s = -b.s; return a * b; }