From cbaf59e086113621c47e1c069344f1f3723f44d4 Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Mon, 16 Jul 2012 01:47:50 +0100
Subject:  ** TEST **  put back corrected SetPrimParams for avatars, referenced
 to  sitpart and not m_host.

---
 .../Shared/Api/Implementation/LSL_Api.cs           | 74 ++++++++++++++--------
 1 file changed, 48 insertions(+), 26 deletions(-)

diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 5bade25..5cbcfec 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -8000,6 +8000,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
             //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
 
             int idx = 0;
+            SceneObjectPart sitpart = World.GetSceneObjectPart(av.ParentID); // betting this will be used
 
             bool positionChanged = false;
             Vector3 finalPos = Vector3.Zero;
@@ -8014,60 +8015,81 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
 
                     switch (code)
                     {
+                        // a avatar is a child 
                         case (int)ScriptBaseClass.PRIM_POSITION:
                         case (int)ScriptBaseClass.PRIM_POS_LOCAL:
                             {
                                 if (remain < 1)
                                     return;
-
                                 LSL_Vector v;
                                 v = rules.GetVector3Item(idx++);
 
-                                SceneObjectPart part = World.GetSceneObjectPart(av.ParentID);
-                                if (part == null)
+                                if (sitpart == null)
                                     break;
 
-                                LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION;
-                                LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR;
-                                if (llGetLinkNumber() > 1)
+                                Vector3 pos = new Vector3((float)v.x, (float)v.y, (float)v.z); // requested absolute position
+
+                                if (sitpart != sitpart.ParentGroup.RootPart)
                                 {
-                                    localRot = llGetLocalRot();
-                                    localPos = llGetLocalPos();
+                                    pos -= sitpart.OffsetPosition; // remove sit part offset
+                                    Quaternion rot = sitpart.RotationOffset;
+                                    pos *= Quaternion.Conjugate(rot); // removed sit part rotation
                                 }
+                                Vector3 sitOffset = (Zrot(av.Rotation)) * (av.Appearance.AvatarHeight * 0.02638f * 2.0f);
+                                pos += sitOffset;
 
-                                v -= localPos;
-                                v /= localRot;
+                                finalPos = pos;
+                                positionChanged = true;
+                            }
+                            break;
 
-                                LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
+                        case (int)ScriptBaseClass.PRIM_ROTATION:
+                            {
+                                if (remain < 1)
+                                    return;
 
-                                v = v + 2 * sitOffset;
+                                if (sitpart == null)
+                                    break;
 
-                                av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
-                                av.SendAvatarDataToAllAgents();
+                                LSL_Rotation r = rules.GetQuaternionItem(idx++);
+                                Quaternion rot = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s); // requested world rotation
+                                
+                                SceneObjectGroup sitgrp = sitpart.ParentGroup;
+                                if (sitgrp != null)
+                                {
+                                    // need to replicate SL bug
+                                    rot = sitgrp.RootPart.RotationOffset * rot;
+                                    if (sitgrp.RootPart != sitpart)
+                                    {
+                                        Quaternion srot = sitpart.RotationOffset;
+                                        rot = Quaternion.Conjugate(srot) * rot; // removed sit part offset rotation
+                                    }
 
+                                    av.Rotation = rot;
+                                    //                                av.SendAvatarDataToAllAgents();
+                                    av.SendTerseUpdateToAllClients();
+                                }
                             }
                             break;
 
                         case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
-                        case (int)ScriptBaseClass.PRIM_ROTATION:
                             {
                                 if (remain < 1)
                                     return;
 
-                                LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION;
-                                LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR;
+                                if (sitpart == null)
+                                    break;
 
-                                if (llGetLinkNumber() > 1)
+                                LSL_Rotation r = rules.GetQuaternionItem(idx++);
+                                Quaternion rot = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s); // requested offset rotation
+                                if (sitpart != sitpart.ParentGroup.RootPart)
                                 {
-                                    localRot = llGetLocalRot();
-                                    localPos = llGetLocalPos();
+                                    Quaternion srot = sitpart.RotationOffset;
+                                    rot = Quaternion.Conjugate(srot) * rot; // remove sit part offset rotation
                                 }
-
-                                LSL_Rotation r;
-                                r = rules.GetQuaternionItem(idx++);
-                                r = r * llGetRootRotation() / localRot;
-                                av.Rotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
-                                av.SendAvatarDataToAllAgents();
+                                av.Rotation = rot;
+//                                av.SendAvatarDataToAllAgents();
+                                av.SendTerseUpdateToAllClients();
                             }
                             break;
 
-- 
cgit v1.1