From bc24c0e5d7f40abd1d0f1c02bb88f35cdd6c9bcf Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Fri, 18 Jul 2008 01:20:06 +0000 Subject: Mantis#1768. Thank you kindly, Junta_Kohime for a patch that: llRot2Fwd function modified, using fast algebric calculations instead of vectors and quaternions products. The accuracy is the same. Normalization is now implemented. --- .../Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 16 +++++++++++++++- .../ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index b53f6c0..3ae1f3a 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -430,7 +430,21 @@ namespace OpenSim.Region.ScriptEngine.Common public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r) { m_host.AddScriptLPS(1); - return (new LSL_Types.Vector3(1,0,0) * r); + double x,y,z,m; + m = Math.Sqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.s*r.s); + // m is always greater than zero + if (m!=1) // if m is not equal to 1 then Rotation needs to be normalized + { + r.x/=m; + r.y/=m; + r.z/=m; + r.s/=m; + } + // Fast Algebric Calculations instead of Vectors & Quaternions Product + x = r.x*r.x-r.y*r.y-r.z*r.z+r.s*r.s; + y = 2*(r.x*r.y+r.z*r.s); + z = 2*(r.x*r.z-r.y*r.s); + return (new LSL_Types.Vector3(x,y,z)); } public LSL_Types.Vector3 llRot2Left(LSL_Types.Quaternion r) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 260457b..e7313e1 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -417,7 +417,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r) { m_host.AddScriptLPS(1); - return (new LSL_Types.Vector3(1,0,0) * r); + double x,y,z,m; + m = Math.Sqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.s*r.s); + // m is always greater than zero + if (m!=1) // if m is not equal to 1 then Rotation needs to be normalized + { + r.x/=m; + r.y/=m; + r.z/=m; + r.s/=m; + } + // Fast Algebric Calculations instead of Vectors & Quaternions Product + x = r.x*r.x-r.y*r.y-r.z*r.z+r.s*r.s; + y = 2*(r.x*r.y+r.z*r.s); + z = 2*(r.x*r.z-r.y*r.s); + return (new LSL_Types.Vector3(x,y,z)); } public LSL_Types.Vector3 llRot2Left(LSL_Types.Quaternion r) -- cgit v1.1