aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/ScenePresence.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs878
1 files changed, 703 insertions, 175 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 6c119c2..654e9ce 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Xml;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.Reflection; 31using System.Reflection;
31using System.Timers; 32using System.Timers;
@@ -73,7 +74,7 @@ namespace OpenSim.Region.Framework.Scenes
73// { 74// {
74// m_log.Debug("[ScenePresence] Destructor called"); 75// m_log.Debug("[ScenePresence] Destructor called");
75// } 76// }
76 77
77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 78 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
78 79
79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 80 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
@@ -89,7 +90,9 @@ namespace OpenSim.Region.Framework.Scenes
89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 90 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
90 /// issue #1716 91 /// issue #1716
91 /// </summary> 92 /// </summary>
92 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 93// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
94 // Value revised by KF 091121 by comparison with SL.
95 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f);
93 96
94 public UUID currentParcelUUID = UUID.Zero; 97 public UUID currentParcelUUID = UUID.Zero;
95 98
@@ -123,8 +126,11 @@ namespace OpenSim.Region.Framework.Scenes
123 public Vector3 lastKnownAllowedPosition; 126 public Vector3 lastKnownAllowedPosition;
124 public bool sentMessageAboutRestrictedParcelFlyingDown; 127 public bool sentMessageAboutRestrictedParcelFlyingDown;
125 public Vector4 CollisionPlane = Vector4.UnitW; 128 public Vector4 CollisionPlane = Vector4.UnitW;
126 129
130 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
131 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
127 private Vector3 m_lastPosition; 132 private Vector3 m_lastPosition;
133 private Vector3 m_lastWorldPosition;
128 private Quaternion m_lastRotation; 134 private Quaternion m_lastRotation;
129 private Vector3 m_lastVelocity; 135 private Vector3 m_lastVelocity;
130 //private int m_lastTerseSent; 136 //private int m_lastTerseSent;
@@ -157,7 +163,6 @@ namespace OpenSim.Region.Framework.Scenes
157 private int m_perfMonMS; 163 private int m_perfMonMS;
158 164
159 private bool m_setAlwaysRun; 165 private bool m_setAlwaysRun;
160
161 private bool m_forceFly; 166 private bool m_forceFly;
162 private bool m_flyDisabled; 167 private bool m_flyDisabled;
163 168
@@ -181,7 +186,8 @@ namespace OpenSim.Region.Framework.Scenes
181 protected RegionInfo m_regionInfo; 186 protected RegionInfo m_regionInfo;
182 protected ulong crossingFromRegion; 187 protected ulong crossingFromRegion;
183 188
184 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 189 private readonly Vector3[] Dir_Vectors = new Vector3[11];
190 private bool m_isNudging = false;
185 191
186 // Position of agent's camera in world (region cordinates) 192 // Position of agent's camera in world (region cordinates)
187 protected Vector3 m_CameraCenter; 193 protected Vector3 m_CameraCenter;
@@ -206,17 +212,23 @@ namespace OpenSim.Region.Framework.Scenes
206 private bool m_autopilotMoving; 212 private bool m_autopilotMoving;
207 private Vector3 m_autoPilotTarget; 213 private Vector3 m_autoPilotTarget;
208 private bool m_sitAtAutoTarget; 214 private bool m_sitAtAutoTarget;
215 private Vector3 m_initialSitTarget = Vector3.Zero; //KF: First estimate of where to sit
209 216
210 private string m_nextSitAnimation = String.Empty; 217 private string m_nextSitAnimation = String.Empty;
211 218
212 //PauPaw:Proper PID Controler for autopilot************ 219 //PauPaw:Proper PID Controler for autopilot************
213 private bool m_moveToPositionInProgress; 220 private bool m_moveToPositionInProgress;
214 private Vector3 m_moveToPositionTarget; 221 private Vector3 m_moveToPositionTarget;
222 private Quaternion m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
215 223
216 private bool m_followCamAuto; 224 private bool m_followCamAuto;
217 225
218 private int m_movementUpdateCount; 226 private int m_movementUpdateCount;
227 private int m_lastColCount = -1; //KF: Look for Collision chnages
228 private int m_updateCount = 0; //KF: Update Anims for a while
229 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
219 private const int NumMovementsBetweenRayCast = 5; 230 private const int NumMovementsBetweenRayCast = 5;
231 private List<uint> m_lastColliders = new List<uint>();
220 232
221 private bool CameraConstraintActive; 233 private bool CameraConstraintActive;
222 //private int m_moveToPositionStateStatus; 234 //private int m_moveToPositionStateStatus;
@@ -243,7 +255,9 @@ namespace OpenSim.Region.Framework.Scenes
243 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 255 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
244 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 256 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
245 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 257 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
246 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 258 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
259 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
260 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
247 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 261 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
248 } 262 }
249 263
@@ -450,9 +464,18 @@ namespace OpenSim.Region.Framework.Scenes
450 get 464 get
451 { 465 {
452 PhysicsActor actor = m_physicsActor; 466 PhysicsActor actor = m_physicsActor;
453 if (actor != null) 467// if (actor != null)
468 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting!
454 m_pos = actor.Position; 469 m_pos = actor.Position;
455 470
471 // If we're sitting, we need to update our position
472 if (m_parentID != 0)
473 {
474 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
475 if (part != null)
476 m_parentPosition = part.AbsolutePosition;
477 }
478
456 return m_parentPosition + m_pos; 479 return m_parentPosition + m_pos;
457 } 480 }
458 set 481 set
@@ -471,7 +494,8 @@ namespace OpenSim.Region.Framework.Scenes
471 } 494 }
472 } 495 }
473 496
474 m_pos = value; 497 if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting!
498 m_pos = value;
475 m_parentPosition = Vector3.Zero; 499 m_parentPosition = Vector3.Zero;
476 } 500 }
477 } 501 }
@@ -515,10 +539,39 @@ namespace OpenSim.Region.Framework.Scenes
515 } 539 }
516 } 540 }
517 541
542 public Quaternion OffsetRotation
543 {
544 get { return m_offsetRotation; }
545 set { m_offsetRotation = value; }
546 }
547
518 public Quaternion Rotation 548 public Quaternion Rotation
519 { 549 {
520 get { return m_bodyRot; } 550 get {
521 set { m_bodyRot = value; } 551 if (m_parentID != 0)
552 {
553 if (m_offsetRotation != null)
554 {
555 return m_offsetRotation;
556 }
557 else
558 {
559 return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
560 }
561
562 }
563 else
564 {
565 return m_bodyRot;
566 }
567 }
568 set {
569 m_bodyRot = value;
570 if (m_parentID != 0)
571 {
572 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
573 }
574 }
522 } 575 }
523 576
524 public Quaternion PreviousRotation 577 public Quaternion PreviousRotation
@@ -669,7 +722,7 @@ namespace OpenSim.Region.Framework.Scenes
669 CreateSceneViewer(); 722 CreateSceneViewer();
670 m_animator = new ScenePresenceAnimator(this); 723 m_animator = new ScenePresenceAnimator(this);
671 } 724 }
672 725
673 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() 726 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this()
674 { 727 {
675 m_rootRegionHandle = reginfo.RegionHandle; 728 m_rootRegionHandle = reginfo.RegionHandle;
@@ -701,16 +754,16 @@ namespace OpenSim.Region.Framework.Scenes
701 m_reprioritization_timer.AutoReset = false; 754 m_reprioritization_timer.AutoReset = false;
702 755
703 AdjustKnownSeeds(); 756 AdjustKnownSeeds();
704
705 // TODO: I think, this won't send anything, as we are still a child here...
706 Animator.TrySetMovementAnimation("STAND"); 757 Animator.TrySetMovementAnimation("STAND");
707
708 // we created a new ScenePresence (a new child agent) in a fresh region. 758 // we created a new ScenePresence (a new child agent) in a fresh region.
709 // Request info about all the (root) agents in this region 759 // Request info about all the (root) agents in this region
710 // Note: This won't send data *to* other clients in that region (children don't send) 760 // Note: This won't send data *to* other clients in that region (children don't send)
711 SendInitialFullUpdateToAllClients(); 761 SendInitialFullUpdateToAllClients();
712
713 RegisterToEvents(); 762 RegisterToEvents();
763 if (m_controllingClient != null)
764 {
765 m_controllingClient.ProcessPendingPackets();
766 }
714 SetDirectionVectors(); 767 SetDirectionVectors();
715 } 768 }
716 769
@@ -760,25 +813,47 @@ namespace OpenSim.Region.Framework.Scenes
760 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 813 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
761 Dir_Vectors[4] = Vector3.UnitZ; //UP 814 Dir_Vectors[4] = Vector3.UnitZ; //UP
762 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 815 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
763 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 816 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
764 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 817 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
765 Dir_Vectors[7] = -Vector3.UnitX; //BACK 818 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
819 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
820 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
766 } 821 }
767 822
768 private Vector3[] GetWalkDirectionVectors() 823 private Vector3[] GetWalkDirectionVectors()
769 { 824 {
770 Vector3[] vector = new Vector3[9]; 825 Vector3[] vector = new Vector3[11];
771 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 826 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
772 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 827 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
773 vector[2] = Vector3.UnitY; //LEFT 828 vector[2] = Vector3.UnitY; //LEFT
774 vector[3] = -Vector3.UnitY; //RIGHT 829 vector[3] = -Vector3.UnitY; //RIGHT
775 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 830 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
776 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 831 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
777 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 832 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
778 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 833 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
779 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 834 vector[8] = Vector3.UnitY; //LEFT_NUDGE
835 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
836 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
780 return vector; 837 return vector;
781 } 838 }
839
840 private bool[] GetDirectionIsNudge()
841 {
842 bool[] isNudge = new bool[11];
843 isNudge[0] = false; //FORWARD
844 isNudge[1] = false; //BACK
845 isNudge[2] = false; //LEFT
846 isNudge[3] = false; //RIGHT
847 isNudge[4] = false; //UP
848 isNudge[5] = false; //DOWN
849 isNudge[6] = true; //FORWARD_NUDGE
850 isNudge[7] = true; //BACK_NUDGE
851 isNudge[8] = true; //LEFT_NUDGE
852 isNudge[9] = true; //RIGHT_NUDGE
853 isNudge[10] = true; //DOWN_Nudge
854 return isNudge;
855 }
856
782 857
783 #endregion 858 #endregion
784 859
@@ -821,7 +896,6 @@ namespace OpenSim.Region.Framework.Scenes
821 m_grouptitle = gm.GetGroupTitle(m_uuid); 896 m_grouptitle = gm.GetGroupTitle(m_uuid);
822 897
823 m_rootRegionHandle = m_scene.RegionInfo.RegionHandle; 898 m_rootRegionHandle = m_scene.RegionInfo.RegionHandle;
824
825 m_scene.SetRootAgentScene(m_uuid); 899 m_scene.SetRootAgentScene(m_uuid);
826 900
827 // Moved this from SendInitialData to ensure that m_appearance is initialized 901 // Moved this from SendInitialData to ensure that m_appearance is initialized
@@ -840,6 +914,52 @@ namespace OpenSim.Region.Framework.Scenes
840 pos.Y = crossedBorder.BorderLine.Z - 1; 914 pos.Y = crossedBorder.BorderLine.Z - 1;
841 } 915 }
842 916
917 //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet.
918 //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent,
919 //they'll bypass the landing point. But I can't think of any decent way of fixing this.
920 if (KnownChildRegionHandles.Count == 0)
921 {
922 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
923 if (land != null)
924 {
925 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
926 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero && UserLevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid) && land.LandData.OwnerID != m_uuid)
927 {
928 pos = land.LandData.UserLocation;
929 }
930 }
931 }
932
933 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0)
934 {
935 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128);
936
937 if (pos.X < 0)
938 {
939 emergencyPos.X = (int)Constants.RegionSize + pos.X;
940 if (!(pos.Y < 0))
941 emergencyPos.Y = pos.Y;
942 if (!(pos.Z < 0))
943 emergencyPos.Z = pos.Z;
944 }
945 if (pos.Y < 0)
946 {
947 emergencyPos.Y = (int)Constants.RegionSize + pos.Y;
948 if (!(pos.X < 0))
949 emergencyPos.X = pos.X;
950 if (!(pos.Z < 0))
951 emergencyPos.Z = pos.Z;
952 }
953 if (pos.Z < 0)
954 {
955 emergencyPos.Z = 128;
956 if (!(pos.Y < 0))
957 emergencyPos.Y = pos.Y;
958 if (!(pos.X < 0))
959 emergencyPos.X = pos.X;
960 }
961 }
962
843 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 963 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
844 { 964 {
845 m_log.WarnFormat( 965 m_log.WarnFormat(
@@ -972,9 +1092,10 @@ namespace OpenSim.Region.Framework.Scenes
972 public void Teleport(Vector3 pos) 1092 public void Teleport(Vector3 pos)
973 { 1093 {
974 bool isFlying = false; 1094 bool isFlying = false;
1095
975 if (m_physicsActor != null) 1096 if (m_physicsActor != null)
976 isFlying = m_physicsActor.Flying; 1097 isFlying = m_physicsActor.Flying;
977 1098
978 RemoveFromPhysicalScene(); 1099 RemoveFromPhysicalScene();
979 Velocity = Vector3.Zero; 1100 Velocity = Vector3.Zero;
980 AbsolutePosition = pos; 1101 AbsolutePosition = pos;
@@ -986,6 +1107,7 @@ namespace OpenSim.Region.Framework.Scenes
986 } 1107 }
987 1108
988 SendTerseUpdateToAllClients(); 1109 SendTerseUpdateToAllClients();
1110
989 } 1111 }
990 1112
991 public void TeleportWithMomentum(Vector3 pos) 1113 public void TeleportWithMomentum(Vector3 pos)
@@ -1099,7 +1221,6 @@ namespace OpenSim.Region.Framework.Scenes
1099 pos.Z = ground + 1.5f; 1221 pos.Z = ground + 1.5f;
1100 AbsolutePosition = pos; 1222 AbsolutePosition = pos;
1101 } 1223 }
1102
1103 m_isChildAgent = false; 1224 m_isChildAgent = false;
1104 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 1225 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1105 MakeRootAgent(AbsolutePosition, m_flying); 1226 MakeRootAgent(AbsolutePosition, m_flying);
@@ -1198,6 +1319,7 @@ namespace OpenSim.Region.Framework.Scenes
1198 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); 1319 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902");
1199 1320
1200 m_pos = m_LastFinitePos; 1321 m_pos = m_LastFinitePos;
1322
1201 if (!m_pos.IsFinite()) 1323 if (!m_pos.IsFinite())
1202 { 1324 {
1203 m_pos.X = 127f; 1325 m_pos.X = 127f;
@@ -1264,7 +1386,6 @@ namespace OpenSim.Region.Framework.Scenes
1264 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1386 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1265 } 1387 }
1266 } 1388 }
1267
1268 lock (scriptedcontrols) 1389 lock (scriptedcontrols)
1269 { 1390 {
1270 if (scriptedcontrols.Count > 0) 1391 if (scriptedcontrols.Count > 0)
@@ -1279,6 +1400,9 @@ namespace OpenSim.Region.Framework.Scenes
1279 1400
1280 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1401 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1281 { 1402 {
1403 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1404 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1405
1282 // TODO: This doesn't prevent the user from walking yet. 1406 // TODO: This doesn't prevent the user from walking yet.
1283 // Setting parent ID would fix this, if we knew what value 1407 // Setting parent ID would fix this, if we knew what value
1284 // to use. Or we could add a m_isSitting variable. 1408 // to use. Or we could add a m_isSitting variable.
@@ -1333,6 +1457,11 @@ namespace OpenSim.Region.Framework.Scenes
1333 update_rotation = true; 1457 update_rotation = true;
1334 } 1458 }
1335 1459
1460 //guilty until proven innocent..
1461 bool Nudging = true;
1462 //Basically, if there is at least one non-nudge control then we don't need
1463 //to worry about stopping the avatar
1464
1336 if (m_parentID == 0) 1465 if (m_parentID == 0)
1337 { 1466 {
1338 bool bAllowUpdateMoveToPosition = false; 1467 bool bAllowUpdateMoveToPosition = false;
@@ -1347,9 +1476,12 @@ namespace OpenSim.Region.Framework.Scenes
1347 else 1476 else
1348 dirVectors = Dir_Vectors; 1477 dirVectors = Dir_Vectors;
1349 1478
1350 // The fact that m_movementflag is a byte needs to be fixed 1479 bool[] isNudge = GetDirectionIsNudge();
1351 // it really should be a uint 1480
1352 uint nudgehack = 250; 1481
1482
1483
1484
1353 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1485 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1354 { 1486 {
1355 if (((uint)flags & (uint)DCF) != 0) 1487 if (((uint)flags & (uint)DCF) != 0)
@@ -1359,40 +1491,28 @@ namespace OpenSim.Region.Framework.Scenes
1359 try 1491 try
1360 { 1492 {
1361 agent_control_v3 += dirVectors[i]; 1493 agent_control_v3 += dirVectors[i];
1362 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1494 if (isNudge[i] == false)
1495 {
1496 Nudging = false;
1497 }
1363 } 1498 }
1364 catch (IndexOutOfRangeException) 1499 catch (IndexOutOfRangeException)
1365 { 1500 {
1366 // Why did I get this? 1501 // Why did I get this?
1367 } 1502 }
1368 1503
1369 if ((m_movementflag & (byte)(uint)DCF) == 0) 1504 if ((m_movementflag & (uint)DCF) == 0)
1370 { 1505 {
1371 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1372 {
1373 m_movementflag |= (byte)nudgehack;
1374 }
1375 m_movementflag += (byte)(uint)DCF; 1506 m_movementflag += (byte)(uint)DCF;
1376 update_movementflag = true; 1507 update_movementflag = true;
1377 } 1508 }
1378 } 1509 }
1379 else 1510 else
1380 { 1511 {
1381 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1512 if ((m_movementflag & (uint)DCF) != 0)
1382 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1383 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1384 ) // This or is for Nudge forward
1385 { 1513 {
1386 m_movementflag -= ((byte)(uint)DCF); 1514 m_movementflag -= (byte)(uint)DCF;
1387
1388 update_movementflag = true; 1515 update_movementflag = true;
1389 /*
1390 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1391 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1392 {
1393 m_log.Debug("Removed Hack flag");
1394 }
1395 */
1396 } 1516 }
1397 else 1517 else
1398 { 1518 {
@@ -1401,7 +1521,6 @@ namespace OpenSim.Region.Framework.Scenes
1401 } 1521 }
1402 i++; 1522 i++;
1403 } 1523 }
1404
1405 //Paupaw:Do Proper PID for Autopilot here 1524 //Paupaw:Do Proper PID for Autopilot here
1406 if (bResetMoveToPosition) 1525 if (bResetMoveToPosition)
1407 { 1526 {
@@ -1436,6 +1555,9 @@ namespace OpenSim.Region.Framework.Scenes
1436 // Ignore z component of vector 1555 // Ignore z component of vector
1437 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1556 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1438 LocalVectorToTarget2D.Normalize(); 1557 LocalVectorToTarget2D.Normalize();
1558
1559 //We're not nudging
1560 Nudging = false;
1439 agent_control_v3 += LocalVectorToTarget2D; 1561 agent_control_v3 += LocalVectorToTarget2D;
1440 1562
1441 // update avatar movement flags. the avatar coordinate system is as follows: 1563 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1524,13 +1646,13 @@ namespace OpenSim.Region.Framework.Scenes
1524 // m_log.DebugFormat( 1646 // m_log.DebugFormat(
1525 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1647 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1526 1648
1527 AddNewMovement(agent_control_v3, q); 1649 AddNewMovement(agent_control_v3, q, Nudging);
1528 1650
1529 1651
1530 } 1652 }
1531 } 1653 }
1532 1654
1533 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1655 if (update_movementflag && !SitGround)
1534 Animator.UpdateMovementAnimations(); 1656 Animator.UpdateMovementAnimations();
1535 1657
1536 m_scene.EventManager.TriggerOnClientMovement(this); 1658 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1545,7 +1667,6 @@ namespace OpenSim.Region.Framework.Scenes
1545 m_sitAtAutoTarget = false; 1667 m_sitAtAutoTarget = false;
1546 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1668 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1547 //proxy.PCode = (byte)PCode.ParticleSystem; 1669 //proxy.PCode = (byte)PCode.ParticleSystem;
1548
1549 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1670 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1550 proxyObjectGroup.AttachToScene(m_scene); 1671 proxyObjectGroup.AttachToScene(m_scene);
1551 1672
@@ -1587,7 +1708,7 @@ namespace OpenSim.Region.Framework.Scenes
1587 } 1708 }
1588 m_moveToPositionInProgress = true; 1709 m_moveToPositionInProgress = true;
1589 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1710 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1590 } 1711 }
1591 catch (Exception ex) 1712 catch (Exception ex)
1592 { 1713 {
1593 //Why did I get this error? 1714 //Why did I get this error?
@@ -1609,7 +1730,7 @@ namespace OpenSim.Region.Framework.Scenes
1609 Velocity = Vector3.Zero; 1730 Velocity = Vector3.Zero;
1610 SendFullUpdateToAllClients(); 1731 SendFullUpdateToAllClients();
1611 1732
1612 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1733 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1613 } 1734 }
1614 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1735 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1615 m_requestedSitTargetUUID = UUID.Zero; 1736 m_requestedSitTargetUUID = UUID.Zero;
@@ -1646,50 +1767,84 @@ namespace OpenSim.Region.Framework.Scenes
1646 1767
1647 if (m_parentID != 0) 1768 if (m_parentID != 0)
1648 { 1769 {
1649 m_log.Debug("StandupCode Executed"); 1770 SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID);
1650 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1651 if (part != null) 1771 if (part != null)
1652 { 1772 {
1773 part.TaskInventory.LockItemsForRead(true);
1653 TaskInventoryDictionary taskIDict = part.TaskInventory; 1774 TaskInventoryDictionary taskIDict = part.TaskInventory;
1654 if (taskIDict != null) 1775 if (taskIDict != null)
1655 { 1776 {
1656 lock (taskIDict) 1777 foreach (UUID taskID in taskIDict.Keys)
1657 { 1778 {
1658 foreach (UUID taskID in taskIDict.Keys) 1779 UnRegisterControlEventsToScript(LocalId, taskID);
1659 { 1780 taskIDict[taskID].PermsMask &= ~(
1660 UnRegisterControlEventsToScript(LocalId, taskID); 1781 2048 | //PERMISSION_CONTROL_CAMERA
1661 taskIDict[taskID].PermsMask &= ~( 1782 4); // PERMISSION_TAKE_CONTROLS
1662 2048 | //PERMISSION_CONTROL_CAMERA
1663 4); // PERMISSION_TAKE_CONTROLS
1664 }
1665 } 1783 }
1666
1667 } 1784 }
1785 part.TaskInventory.LockItemsForRead(false);
1668 // Reset sit target. 1786 // Reset sit target.
1669 if (part.GetAvatarOnSitTarget() == UUID) 1787 if (part.GetAvatarOnSitTarget() == UUID)
1670 part.SetAvatarOnSitTarget(UUID.Zero); 1788 part.SetAvatarOnSitTarget(UUID.Zero);
1671
1672 m_parentPosition = part.GetWorldPosition(); 1789 m_parentPosition = part.GetWorldPosition();
1673 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1790 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1674 } 1791 }
1792 // part.GetWorldRotation() is the rotation of the object being sat on
1793 // Rotation is the sittiing Av's rotation
1794
1795 Quaternion partRot;
1796// if (part.LinkNum == 1)
1797// { // Root prim of linkset
1798// partRot = part.ParentGroup.RootPart.RotationOffset;
1799// }
1800// else
1801// { // single or child prim
1802
1803// }
1804 if (part == null) //CW: Part may be gone. llDie() for example.
1805 {
1806 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1807 }
1808 else
1809 {
1810 partRot = part.GetWorldRotation();
1811 }
1812
1813 Quaternion partIRot = Quaternion.Inverse(partRot);
1814
1815 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1816 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1675 1817
1818
1676 if (m_physicsActor == null) 1819 if (m_physicsActor == null)
1677 { 1820 {
1678 AddToPhysicalScene(false); 1821 AddToPhysicalScene(false);
1679 } 1822 }
1680 1823 //CW: If the part isn't null then we can set the current position
1681 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1824 if (part != null)
1682 m_parentPosition = Vector3.Zero; 1825 {
1683 1826 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + ((m_pos - part.OffsetPosition) * partRot); // + av sit offset!
1684 m_parentID = 0; 1827 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1828 part.IsOccupied = false;
1829 part.ParentGroup.DeleteAvatar(ControllingClient.AgentId);
1830 }
1831 else
1832 {
1833 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1834 AbsolutePosition = m_lastWorldPosition;
1835 }
1836
1837 m_parentPosition = Vector3.Zero;
1838 m_parentID = 0;
1839 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1685 SendFullUpdateToAllClients(); 1840 SendFullUpdateToAllClients();
1686 m_requestedSitTargetID = 0; 1841 m_requestedSitTargetID = 0;
1842
1687 if ((m_physicsActor != null) && (m_avHeight > 0)) 1843 if ((m_physicsActor != null) && (m_avHeight > 0))
1688 { 1844 {
1689 SetHeight(m_avHeight); 1845 SetHeight(m_avHeight);
1690 } 1846 }
1691 } 1847 }
1692
1693 Animator.TrySetMovementAnimation("STAND"); 1848 Animator.TrySetMovementAnimation("STAND");
1694 } 1849 }
1695 1850
@@ -1720,13 +1875,9 @@ namespace OpenSim.Region.Framework.Scenes
1720 Vector3 avSitOffSet = part.SitTargetPosition; 1875 Vector3 avSitOffSet = part.SitTargetPosition;
1721 Quaternion avSitOrientation = part.SitTargetOrientation; 1876 Quaternion avSitOrientation = part.SitTargetOrientation;
1722 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1877 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1723 1878 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1724 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1879 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1725 bool SitTargetisSet = 1880 if (SitTargetisSet && !SitTargetOccupied)
1726 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1727 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1728
1729 if (SitTargetisSet && SitTargetUnOccupied)
1730 { 1881 {
1731 //switch the target to this prim 1882 //switch the target to this prim
1732 return part; 1883 return part;
@@ -1740,84 +1891,156 @@ namespace OpenSim.Region.Framework.Scenes
1740 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1891 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1741 { 1892 {
1742 bool autopilot = true; 1893 bool autopilot = true;
1894 Vector3 autopilotTarget = new Vector3();
1895 Quaternion sitOrientation = Quaternion.Identity;
1743 Vector3 pos = new Vector3(); 1896 Vector3 pos = new Vector3();
1744 Quaternion sitOrientation = pSitOrientation;
1745 Vector3 cameraEyeOffset = Vector3.Zero; 1897 Vector3 cameraEyeOffset = Vector3.Zero;
1746 Vector3 cameraAtOffset = Vector3.Zero; 1898 Vector3 cameraAtOffset = Vector3.Zero;
1747 bool forceMouselook = false; 1899 bool forceMouselook = false;
1748 1900
1749 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1901 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1750 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1902 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1751 if (part != null) 1903 if (part == null) return;
1752 { 1904
1753 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1905 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1754 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1906 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1755 1907
1756 // Is a sit target available? 1908 // part is the prim to sit on
1757 Vector3 avSitOffSet = part.SitTargetPosition; 1909 // offset is the world-ref vector distance from that prim center to the click-spot
1758 Quaternion avSitOrientation = part.SitTargetOrientation; 1910 // UUID is the UUID of the Avatar doing the clicking
1759 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1911
1760 1912 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1761 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1913
1762 bool SitTargetisSet = 1914 // Is a sit target available?
1763 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1915 Vector3 avSitOffSet = part.SitTargetPosition;
1764 ( 1916 Quaternion avSitOrientation = part.SitTargetOrientation;
1765 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1917
1766 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1918 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1767 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1919 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1768 ) 1920 Quaternion partRot;
1769 )); 1921// if (part.LinkNum == 1)
1770 1922// { // Root prim of linkset
1771 if (SitTargetisSet && SitTargetUnOccupied) 1923// partRot = part.ParentGroup.RootPart.RotationOffset;
1772 { 1924// }
1773 part.SetAvatarOnSitTarget(UUID); 1925// else
1774 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1926// { // single or child prim
1775 sitOrientation = avSitOrientation; 1927 partRot = part.GetWorldRotation();
1776 autopilot = false; 1928// }
1777 } 1929 Quaternion partIRot = Quaternion.Inverse(partRot);
1778 1930//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1779 pos = part.AbsolutePosition + offset; 1931 // Sit analysis rewritten by KF 091125
1780 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1932 if (SitTargetisSet) // scipted sit
1781 //{ 1933 {
1782 // offset = pos; 1934 if (!part.IsOccupied)
1783 //autopilot = false; 1935 {
1784 //} 1936//Console.WriteLine("Scripted, unoccupied");
1785 if (m_physicsActor != null) 1937 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1786 { 1938 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1787 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1939 sitOrientation = avSitOrientation; // Change rotatione to the scripted one
1788 // We can remove the physicsActor until they stand up. 1940 OffsetRotation = avSitOrientation;
1789 m_sitAvatarHeight = m_physicsActor.Size.Z; 1941 autopilot = false; // Jump direct to scripted llSitPos()
1790 1942 }
1791 if (autopilot) 1943 else
1792 { 1944 {
1793 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1945//Console.WriteLine("Scripted, occupied");
1794 { 1946 return;
1795 autopilot = false; 1947 }
1948 }
1949 else // Not Scripted
1950 {
1951 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
1952 {
1953 // large prim & offset, ignore if other Avs sitting
1954// offset.Z -= 0.05f;
1955 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
1956 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
1957
1958//Console.WriteLine(" offset ={0}", offset);
1959//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
1960//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
1961
1962 }
1963 else // small offset
1964 {
1965//Console.WriteLine("Small offset");
1966 if (!part.IsOccupied)
1967 {
1968 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
1969 autopilotTarget = part.AbsolutePosition;
1970//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget);
1971 }
1972 else return; // occupied small
1973 } // end large/small
1974 } // end Scripted/not
1975 cameraAtOffset = part.GetCameraAtOffset();
1976 cameraEyeOffset = part.GetCameraEyeOffset();
1977 forceMouselook = part.GetForceMouselook();
1978 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
1979 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
1796 1980
1797 RemoveFromPhysicalScene(); 1981 if (m_physicsActor != null)
1798 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 1982 {
1799 } 1983 // If we're not using the client autopilot, we're immediately warping the avatar to the location
1800 } 1984 // We can remove the physicsActor until they stand up.
1801 else 1985 m_sitAvatarHeight = m_physicsActor.Size.Z;
1986 if (autopilot)
1987 { // its not a scripted sit
1988// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
1989 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 2.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 2.0f) )
1802 { 1990 {
1991 autopilot = false; // close enough
1992 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1993 Not using the part's position because returning the AV to the last known standing
1994 position is likely to be more friendly, isn't it? */
1803 RemoveFromPhysicalScene(); 1995 RemoveFromPhysicalScene();
1804 } 1996 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
1997 } // else the autopilot will get us close
1998 }
1999 else
2000 { // its a scripted sit
2001 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2002 I *am* using the part's position this time because we have no real idea how far away
2003 the avatar is from the sit target. */
2004 RemoveFromPhysicalScene();
1805 } 2005 }
1806
1807 cameraAtOffset = part.GetCameraAtOffset();
1808 cameraEyeOffset = part.GetCameraEyeOffset();
1809 forceMouselook = part.GetForceMouselook();
1810 } 2006 }
1811 2007 else return; // physactor is null!
1812 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 2008
1813 m_requestedSitTargetUUID = targetID; 2009 Vector3 offsetr; // = offset * partIRot;
2010 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
2011 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
2012 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
2013 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
2014 offsetr = offset * partIRot;
2015//
2016 // else
2017 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
2018 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
2019 // (offset * partRot);
2020 // }
2021
2022//Console.WriteLine(" ");
2023//Console.WriteLine("link number ={0}", part.LinkNum);
2024//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
2025//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
2026//Console.WriteLine("Click offst ={0}", offset);
2027//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
2028//Console.WriteLine("offsetr ={0}", offsetr);
2029//Console.WriteLine("Camera At ={0}", cameraAtOffset);
2030//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
2031
2032 //NOTE: SendSitResponse should be relative to the GROUP *NOT* THE PRIM if we're sitting on a child
2033 ControllingClient.SendSitResponse(part.ParentGroup.UUID, offsetr + part.OffsetPosition, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
2034
2035 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1814 // This calls HandleAgentSit twice, once from here, and the client calls 2036 // This calls HandleAgentSit twice, once from here, and the client calls
1815 // HandleAgentSit itself after it gets to the location 2037 // HandleAgentSit itself after it gets to the location
1816 // It doesn't get to the location until we've moved them there though 2038 // It doesn't get to the location until we've moved them there though
1817 // which happens in HandleAgentSit :P 2039 // which happens in HandleAgentSit :P
1818 m_autopilotMoving = autopilot; 2040 m_autopilotMoving = autopilot;
1819 m_autoPilotTarget = pos; 2041 m_autoPilotTarget = autopilotTarget;
1820 m_sitAtAutoTarget = autopilot; 2042 m_sitAtAutoTarget = autopilot;
2043 m_initialSitTarget = autopilotTarget;
1821 if (!autopilot) 2044 if (!autopilot)
1822 HandleAgentSit(remoteClient, UUID); 2045 HandleAgentSit(remoteClient, UUID);
1823 } 2046 }
@@ -2112,47 +2335,122 @@ namespace OpenSim.Region.Framework.Scenes
2112 { 2335 {
2113 if (part != null) 2336 if (part != null)
2114 { 2337 {
2338//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2115 if (part.GetAvatarOnSitTarget() == UUID) 2339 if (part.GetAvatarOnSitTarget() == UUID)
2116 { 2340 {
2341//Console.WriteLine("Scripted Sit");
2342 // Scripted sit
2117 Vector3 sitTargetPos = part.SitTargetPosition; 2343 Vector3 sitTargetPos = part.SitTargetPosition;
2118 Quaternion sitTargetOrient = part.SitTargetOrientation; 2344 Quaternion sitTargetOrient = part.SitTargetOrientation;
2119
2120 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2121 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2122
2123 //Quaternion result = (sitTargetOrient * vq) * nq;
2124
2125 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2345 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2126 m_pos += SIT_TARGET_ADJUSTMENT; 2346 m_pos += SIT_TARGET_ADJUSTMENT;
2127 m_bodyRot = sitTargetOrient; 2347 m_bodyRot = sitTargetOrient;
2128 //Rotation = sitTargetOrient;
2129 m_parentPosition = part.AbsolutePosition; 2348 m_parentPosition = part.AbsolutePosition;
2130 2349 part.IsOccupied = true;
2131 //SendTerseUpdateToAllClients(); 2350 part.ParentGroup.AddAvatar(agentID);
2351Console.WriteLine("Scripted Sit ofset {0}", m_pos);
2132 } 2352 }
2133 else 2353 else
2134 { 2354 {
2135 m_pos -= part.AbsolutePosition; 2355 // if m_avUnscriptedSitPos is zero then Av sits above center
2356 // Else Av sits at m_avUnscriptedSitPos
2357
2358 // Non-scripted sit by Kitto Flora 21Nov09
2359 // Calculate angle of line from prim to Av
2360 Quaternion partIRot;
2361// if (part.LinkNum == 1)
2362// { // Root prim of linkset
2363// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2364// }
2365// else
2366// { // single or child prim
2367 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2368// }
2369 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2370 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2371 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2372 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2373 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2374 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2375 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2376 // Av sits at world euler <0,0, z>, translated by part rotation
2377 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2378
2136 m_parentPosition = part.AbsolutePosition; 2379 m_parentPosition = part.AbsolutePosition;
2137 } 2380 part.IsOccupied = true;
2381 part.ParentGroup.AddAvatar(agentID);
2382 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2383 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2384 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2385 m_avUnscriptedSitPos; // adds click offset, if any
2386 //Set up raytrace to find top surface of prim
2387 Vector3 size = part.Scale;
2388 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2389 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2390 Vector3 down = new Vector3(0f, 0f, -1f);
2391//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2392 m_scene.PhysicsScene.RaycastWorld(
2393 start, // Vector3 position,
2394 down, // Vector3 direction,
2395 mag, // float length,
2396 SitAltitudeCallback); // retMethod
2397 } // end scripted/not
2138 } 2398 }
2139 else 2399 else // no Av
2140 { 2400 {
2141 return; 2401 return;
2142 } 2402 }
2143 } 2403 }
2144 m_parentID = m_requestedSitTargetID; 2404
2405 //We want our offsets to reference the root prim, not the child we may have sat on
2406 if (!part.IsRoot)
2407 {
2408 m_parentID = part.ParentGroup.RootPart.LocalId;
2409 m_pos += part.OffsetPosition;
2410 }
2411 else
2412 {
2413 m_parentID = m_requestedSitTargetID;
2414 }
2145 2415
2146 Velocity = Vector3.Zero; 2416 Velocity = Vector3.Zero;
2147 RemoveFromPhysicalScene(); 2417 RemoveFromPhysicalScene();
2148 2418
2149 Animator.TrySetMovementAnimation(sitAnimation); 2419 Animator.TrySetMovementAnimation(sitAnimation);
2150 SendFullUpdateToAllClients(); 2420 SendFullUpdateToAllClients();
2151 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2152 // So we're also sending a terse update (which has avatar rotation)
2153 // [Update] We do now.
2154 //SendTerseUpdateToAllClients();
2155 } 2421 }
2422
2423 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2424 {
2425 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2426 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2427 if(hitYN)
2428 {
2429 // m_pos = Av offset from prim center to make look like on center
2430 // m_parentPosition = Actual center pos of prim
2431 // collisionPoint = spot on prim where we want to sit
2432 // collisionPoint.Z = global sit surface height
2433 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2434 Quaternion partIRot;
2435// if (part.LinkNum == 1)
2436/// { // Root prim of linkset
2437// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2438// }
2439// else
2440// { // single or child prim
2441 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2442// }
2443 if (m_initialSitTarget != null)
2444 {
2445 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2446 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2447 //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2448 m_pos += offset;
2449 // ControllingClient.SendClearFollowCamProperties(part.UUID);
2450 }
2451
2452 }
2453 } // End SitAltitudeCallback KF.
2156 2454
2157 /// <summary> 2455 /// <summary>
2158 /// Event handler for the 'Always run' setting on the client 2456 /// Event handler for the 'Always run' setting on the client
@@ -2182,7 +2480,7 @@ namespace OpenSim.Region.Framework.Scenes
2182 /// </summary> 2480 /// </summary>
2183 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2481 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2184 /// <param name="rotation">The direction in which this avatar should now face. 2482 /// <param name="rotation">The direction in which this avatar should now face.
2185 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2483 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2186 { 2484 {
2187 if (m_isChildAgent) 2485 if (m_isChildAgent)
2188 { 2486 {
@@ -2223,10 +2521,11 @@ namespace OpenSim.Region.Framework.Scenes
2223 Rotation = rotation; 2521 Rotation = rotation;
2224 Vector3 direc = vec * rotation; 2522 Vector3 direc = vec * rotation;
2225 direc.Normalize(); 2523 direc.Normalize();
2524 PhysicsActor actor = m_physicsActor;
2525 if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up.
2226 2526
2227 direc *= 0.03f * 128f * m_speedModifier; 2527 direc *= 0.03f * 128f * m_speedModifier;
2228 2528
2229 PhysicsActor actor = m_physicsActor;
2230 if (actor != null) 2529 if (actor != null)
2231 { 2530 {
2232 if (actor.Flying) 2531 if (actor.Flying)
@@ -2248,18 +2547,25 @@ namespace OpenSim.Region.Framework.Scenes
2248 { 2547 {
2249 if (direc.Z > 2.0f) 2548 if (direc.Z > 2.0f)
2250 { 2549 {
2251 direc.Z *= 3.0f; 2550 if(m_animator.m_animTickJump == -1)
2252 2551 {
2253 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2552 direc.Z *= 3.0f; // jump
2254 Animator.TrySetMovementAnimation("PREJUMP"); 2553 }
2255 Animator.TrySetMovementAnimation("JUMP"); 2554 else
2555 {
2556 direc.Z *= 0.1f; // prejump
2557 }
2558 /* Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs
2559 Animator.TrySetMovementAnimation("PREJUMP");
2560 Animator.TrySetMovementAnimation("JUMP");
2561 */
2256 } 2562 }
2257 } 2563 }
2258 } 2564 }
2259 2565
2260 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2566 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2261 m_forceToApply = direc; 2567 m_forceToApply = direc;
2262 2568 m_isNudging = Nudging;
2263 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2569 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2264 } 2570 }
2265 2571
@@ -2274,7 +2580,7 @@ namespace OpenSim.Region.Framework.Scenes
2274 const float POSITION_TOLERANCE = 0.05f; 2580 const float POSITION_TOLERANCE = 0.05f;
2275 //const int TIME_MS_TOLERANCE = 3000; 2581 //const int TIME_MS_TOLERANCE = 3000;
2276 2582
2277 SendPrimUpdates(); 2583
2278 2584
2279 if (m_isChildAgent == false) 2585 if (m_isChildAgent == false)
2280 { 2586 {
@@ -2304,6 +2610,9 @@ namespace OpenSim.Region.Framework.Scenes
2304 CheckForBorderCrossing(); 2610 CheckForBorderCrossing();
2305 CheckForSignificantMovement(); // sends update to the modules. 2611 CheckForSignificantMovement(); // sends update to the modules.
2306 } 2612 }
2613
2614 //Sending prim updates AFTER the avatar terse updates are sent
2615 SendPrimUpdates();
2307 } 2616 }
2308 2617
2309 #endregion 2618 #endregion
@@ -3076,6 +3385,7 @@ namespace OpenSim.Region.Framework.Scenes
3076 m_callbackURI = cAgent.CallbackURI; 3385 m_callbackURI = cAgent.CallbackURI;
3077 3386
3078 m_pos = cAgent.Position; 3387 m_pos = cAgent.Position;
3388
3079 m_velocity = cAgent.Velocity; 3389 m_velocity = cAgent.Velocity;
3080 m_CameraCenter = cAgent.Center; 3390 m_CameraCenter = cAgent.Center;
3081 //m_avHeight = cAgent.Size.Z; 3391 //m_avHeight = cAgent.Size.Z;
@@ -3165,14 +3475,25 @@ namespace OpenSim.Region.Framework.Scenes
3165 { 3475 {
3166 if (m_forceToApply.HasValue) 3476 if (m_forceToApply.HasValue)
3167 { 3477 {
3168 Vector3 force = m_forceToApply.Value;
3169 3478
3479 Vector3 force = m_forceToApply.Value;
3170 m_updateflag = true; 3480 m_updateflag = true;
3171// movementvector = force;
3172 Velocity = force; 3481 Velocity = force;
3173 3482
3174 m_forceToApply = null; 3483 m_forceToApply = null;
3175 } 3484 }
3485 else
3486 {
3487 if (m_isNudging)
3488 {
3489 Vector3 force = Vector3.Zero;
3490
3491 m_updateflag = true;
3492 Velocity = force;
3493 m_isNudging = false;
3494 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3495 }
3496 }
3176 } 3497 }
3177 3498
3178 public override void SetText(string text, Vector3 color, double alpha) 3499 public override void SetText(string text, Vector3 color, double alpha)
@@ -3223,18 +3544,29 @@ namespace OpenSim.Region.Framework.Scenes
3223 { 3544 {
3224 if (e == null) 3545 if (e == null)
3225 return; 3546 return;
3226 3547
3227 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3548 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3228 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3229 // as of this comment the interval is set in AddToPhysicalScene 3549 // as of this comment the interval is set in AddToPhysicalScene
3230 if (Animator!=null) 3550 if (Animator!=null)
3231 Animator.UpdateMovementAnimations(); 3551 {
3552 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3553 { // else its will lock out other animation changes, like ground sit.
3554 Animator.UpdateMovementAnimations();
3555 m_updateCount--;
3556 }
3557 }
3232 3558
3233 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3559 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3234 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3560 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3235 3561
3236 CollisionPlane = Vector4.UnitW; 3562 CollisionPlane = Vector4.UnitW;
3237 3563
3564 if (m_lastColCount != coldata.Count)
3565 {
3566 m_updateCount = UPDATE_COUNT;
3567 m_lastColCount = coldata.Count;
3568 }
3569
3238 if (coldata.Count != 0 && Animator != null) 3570 if (coldata.Count != 0 && Animator != null)
3239 { 3571 {
3240 switch (Animator.CurrentMovementAnimation) 3572 switch (Animator.CurrentMovementAnimation)
@@ -3264,6 +3596,145 @@ namespace OpenSim.Region.Framework.Scenes
3264 } 3596 }
3265 } 3597 }
3266 3598
3599 List<uint> thisHitColliders = new List<uint>();
3600 List<uint> endedColliders = new List<uint>();
3601 List<uint> startedColliders = new List<uint>();
3602
3603 foreach (uint localid in coldata.Keys)
3604 {
3605 thisHitColliders.Add(localid);
3606 if (!m_lastColliders.Contains(localid))
3607 {
3608 startedColliders.Add(localid);
3609 }
3610 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
3611 }
3612
3613 // calculate things that ended colliding
3614 foreach (uint localID in m_lastColliders)
3615 {
3616 if (!thisHitColliders.Contains(localID))
3617 {
3618 endedColliders.Add(localID);
3619 }
3620 }
3621 //add the items that started colliding this time to the last colliders list.
3622 foreach (uint localID in startedColliders)
3623 {
3624 m_lastColliders.Add(localID);
3625 }
3626 // remove things that ended colliding from the last colliders list
3627 foreach (uint localID in endedColliders)
3628 {
3629 m_lastColliders.Remove(localID);
3630 }
3631
3632 // do event notification
3633 if (startedColliders.Count > 0)
3634 {
3635 ColliderArgs StartCollidingMessage = new ColliderArgs();
3636 List<DetectedObject> colliding = new List<DetectedObject>();
3637 foreach (uint localId in startedColliders)
3638 {
3639 if (localId == 0)
3640 continue;
3641
3642 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3643 string data = "";
3644 if (obj != null)
3645 {
3646 DetectedObject detobj = new DetectedObject();
3647 detobj.keyUUID = obj.UUID;
3648 detobj.nameStr = obj.Name;
3649 detobj.ownerUUID = obj.OwnerID;
3650 detobj.posVector = obj.AbsolutePosition;
3651 detobj.rotQuat = obj.GetWorldRotation();
3652 detobj.velVector = obj.Velocity;
3653 detobj.colliderType = 0;
3654 detobj.groupUUID = obj.GroupID;
3655 colliding.Add(detobj);
3656 }
3657 }
3658
3659 if (colliding.Count > 0)
3660 {
3661 StartCollidingMessage.Colliders = colliding;
3662
3663 foreach (SceneObjectGroup att in Attachments)
3664 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
3665 }
3666 }
3667
3668 if (endedColliders.Count > 0)
3669 {
3670 ColliderArgs EndCollidingMessage = new ColliderArgs();
3671 List<DetectedObject> colliding = new List<DetectedObject>();
3672 foreach (uint localId in endedColliders)
3673 {
3674 if (localId == 0)
3675 continue;
3676
3677 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3678 string data = "";
3679 if (obj != null)
3680 {
3681 DetectedObject detobj = new DetectedObject();
3682 detobj.keyUUID = obj.UUID;
3683 detobj.nameStr = obj.Name;
3684 detobj.ownerUUID = obj.OwnerID;
3685 detobj.posVector = obj.AbsolutePosition;
3686 detobj.rotQuat = obj.GetWorldRotation();
3687 detobj.velVector = obj.Velocity;
3688 detobj.colliderType = 0;
3689 detobj.groupUUID = obj.GroupID;
3690 colliding.Add(detobj);
3691 }
3692 }
3693
3694 if (colliding.Count > 0)
3695 {
3696 EndCollidingMessage.Colliders = colliding;
3697
3698 foreach (SceneObjectGroup att in Attachments)
3699 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
3700 }
3701 }
3702
3703 if (thisHitColliders.Count > 0)
3704 {
3705 ColliderArgs CollidingMessage = new ColliderArgs();
3706 List<DetectedObject> colliding = new List<DetectedObject>();
3707 foreach (uint localId in thisHitColliders)
3708 {
3709 if (localId == 0)
3710 continue;
3711
3712 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3713 string data = "";
3714 if (obj != null)
3715 {
3716 DetectedObject detobj = new DetectedObject();
3717 detobj.keyUUID = obj.UUID;
3718 detobj.nameStr = obj.Name;
3719 detobj.ownerUUID = obj.OwnerID;
3720 detobj.posVector = obj.AbsolutePosition;
3721 detobj.rotQuat = obj.GetWorldRotation();
3722 detobj.velVector = obj.Velocity;
3723 detobj.colliderType = 0;
3724 detobj.groupUUID = obj.GroupID;
3725 colliding.Add(detobj);
3726 }
3727 }
3728
3729 if (colliding.Count > 0)
3730 {
3731 CollidingMessage.Colliders = colliding;
3732
3733 foreach (SceneObjectGroup att in Attachments)
3734 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
3735 }
3736 }
3737
3267 if (m_invulnerable) 3738 if (m_invulnerable)
3268 return; 3739 return;
3269 3740
@@ -3438,7 +3909,10 @@ namespace OpenSim.Region.Framework.Scenes
3438 m_scene = scene; 3909 m_scene = scene;
3439 3910
3440 RegisterToEvents(); 3911 RegisterToEvents();
3441 3912 if (m_controllingClient != null)
3913 {
3914 m_controllingClient.ProcessPendingPackets();
3915 }
3442 /* 3916 /*
3443 AbsolutePosition = client.StartPos; 3917 AbsolutePosition = client.StartPos;
3444 3918
@@ -3669,6 +4143,32 @@ namespace OpenSim.Region.Framework.Scenes
3669 return; 4143 return;
3670 } 4144 }
3671 4145
4146 XmlDocument doc = new XmlDocument();
4147 string stateData = String.Empty;
4148
4149 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
4150 if (attServ != null)
4151 {
4152 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
4153 stateData = attServ.Get(ControllingClient.AgentId.ToString());
4154 doc.LoadXml(stateData);
4155 }
4156
4157 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
4158
4159 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
4160 if (nodes.Count > 0)
4161 {
4162 foreach (XmlNode n in nodes)
4163 {
4164 XmlElement elem = (XmlElement)n;
4165 string itemID = elem.GetAttribute("ItemID");
4166 string xml = elem.InnerXml;
4167
4168 itemData[new UUID(itemID)] = xml;
4169 }
4170 }
4171
3672 List<int> attPoints = m_appearance.GetAttachedPoints(); 4172 List<int> attPoints = m_appearance.GetAttachedPoints();
3673 foreach (int p in attPoints) 4173 foreach (int p in attPoints)
3674 { 4174 {
@@ -3688,9 +4188,26 @@ namespace OpenSim.Region.Framework.Scenes
3688 4188
3689 try 4189 try
3690 { 4190 {
3691 // Rez from inventory 4191 string xmlData;
3692 UUID asset 4192 XmlDocument d = new XmlDocument();
3693 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p); 4193 UUID asset;
4194 if (itemData.TryGetValue(itemID, out xmlData))
4195 {
4196 d.LoadXml(xmlData);
4197 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID);
4198
4199 // Rez from inventory
4200 asset
4201 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d);
4202
4203 }
4204 else
4205 {
4206 // Rez from inventory (with a null doc to let
4207 // CHANGED_OWNER happen)
4208 asset
4209 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, null);
4210 }
3694 4211
3695 m_log.InfoFormat( 4212 m_log.InfoFormat(
3696 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})", 4213 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})",
@@ -3727,5 +4244,16 @@ namespace OpenSim.Region.Framework.Scenes
3727 m_reprioritization_called = false; 4244 m_reprioritization_called = false;
3728 } 4245 }
3729 } 4246 }
4247
4248 private Vector3 Quat2Euler(Quaternion rot){
4249 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4250 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4251 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4252 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4253 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4254 return(new Vector3(x,y,z));
4255 }
4256
4257
3730 } 4258 }
3731} 4259}