From a949556c4ea74c993fc15bcfdcbc672d9f971897 Mon Sep 17 00:00:00 2001 From: dahlia Date: Mon, 10 Jun 2013 16:42:49 -0700 Subject: add a Normalize() method for LSL_Rotation --- OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 9ca5ca9..f6d94a3 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -371,6 +371,31 @@ namespace OpenSim.Region.ScriptEngine.Shared #endregion + #region Methods + public Quaternion Normalize() + { + double length = Math.Sqrt(x * x + y * y + z * z + s * s); + if (length < float.Epsilon) + { + x = 1; + y = 0; + z = 0; + s = 0; + } + else + { + + double invLength = 1.0 / length; + x *= invLength; + y *= invLength; + z *= invLength; + s *= invLength; + } + + return this; + } + #endregion + #region Overriders public override int GetHashCode() -- cgit v1.1