From fced731e701fc17e907a26f0f9ef1f0f9f291976 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 14 Apr 2018 23:34:16 +0100 Subject: save a few ns on lsl vector rotations --- OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 1c152be..0c17a90 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -270,13 +270,15 @@ namespace OpenSim.Region.ScriptEngine.Shared // Vector-Rotation Math public static Vector3 operator *(Vector3 v, Quaternion r) { - Quaternion vq = new Quaternion(v.x, v.y, v.z, 0); - Quaternion nq = new Quaternion(-r.x, -r.y, -r.z, r.s); + double rx = r.s * v.x + r.y * v.z - r.z * v.y; + double ry = r.s * v.y + r.z * v.x - r.x * v.z; + double rz = r.s * v.z + r.x * v.y - r.y * v.x; - // adapted for operator * computing "b * a" - Quaternion result = nq * (vq * r); + v.x += 2.0f * (rz * r.y - ry * r.z); + v.y += 2.0f * (rx * r.z - rz * r.x); + v.z += 2.0f * (ry * r.x - rx * r.y); - return new Vector3(result.x, result.y, result.z); + return v; } public static Vector3 operator /(Vector3 v, Quaternion r) -- cgit v1.1