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.cs909
1 files changed, 735 insertions, 174 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 4c17615..b3fa2f4 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;
@@ -72,7 +73,7 @@ namespace OpenSim.Region.Framework.Scenes
72// { 73// {
73// m_log.Debug("[ScenePresence] Destructor called"); 74// m_log.Debug("[ScenePresence] Destructor called");
74// } 75// }
75 76
76 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
77 78
78 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
@@ -88,7 +89,9 @@ namespace OpenSim.Region.Framework.Scenes
88 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
89 /// issue #1716 90 /// issue #1716
90 /// </summary> 91 /// </summary>
91 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 92// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
93 // Value revised by KF 091121 by comparison with SL.
94 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f);
92 95
93 public UUID currentParcelUUID = UUID.Zero; 96 public UUID currentParcelUUID = UUID.Zero;
94 97
@@ -122,8 +125,11 @@ namespace OpenSim.Region.Framework.Scenes
122 public Vector3 lastKnownAllowedPosition; 125 public Vector3 lastKnownAllowedPosition;
123 public bool sentMessageAboutRestrictedParcelFlyingDown; 126 public bool sentMessageAboutRestrictedParcelFlyingDown;
124 public Vector4 CollisionPlane = Vector4.UnitW; 127 public Vector4 CollisionPlane = Vector4.UnitW;
125 128
129 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
130 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
126 private Vector3 m_lastPosition; 131 private Vector3 m_lastPosition;
132 private Vector3 m_lastWorldPosition;
127 private Quaternion m_lastRotation; 133 private Quaternion m_lastRotation;
128 private Vector3 m_lastVelocity; 134 private Vector3 m_lastVelocity;
129 //private int m_lastTerseSent; 135 //private int m_lastTerseSent;
@@ -156,7 +162,6 @@ namespace OpenSim.Region.Framework.Scenes
156 private int m_perfMonMS; 162 private int m_perfMonMS;
157 163
158 private bool m_setAlwaysRun; 164 private bool m_setAlwaysRun;
159
160 private bool m_forceFly; 165 private bool m_forceFly;
161 private bool m_flyDisabled; 166 private bool m_flyDisabled;
162 167
@@ -180,7 +185,8 @@ namespace OpenSim.Region.Framework.Scenes
180 protected RegionInfo m_regionInfo; 185 protected RegionInfo m_regionInfo;
181 protected ulong crossingFromRegion; 186 protected ulong crossingFromRegion;
182 187
183 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 188 private readonly Vector3[] Dir_Vectors = new Vector3[11];
189 private bool m_isNudging = false;
184 190
185 // Position of agent's camera in world (region cordinates) 191 // Position of agent's camera in world (region cordinates)
186 protected Vector3 m_CameraCenter; 192 protected Vector3 m_CameraCenter;
@@ -205,17 +211,23 @@ namespace OpenSim.Region.Framework.Scenes
205 private bool m_autopilotMoving; 211 private bool m_autopilotMoving;
206 private Vector3 m_autoPilotTarget; 212 private Vector3 m_autoPilotTarget;
207 private bool m_sitAtAutoTarget; 213 private bool m_sitAtAutoTarget;
214 private Vector3 m_initialSitTarget = Vector3.Zero; //KF: First estimate of where to sit
208 215
209 private string m_nextSitAnimation = String.Empty; 216 private string m_nextSitAnimation = String.Empty;
210 217
211 //PauPaw:Proper PID Controler for autopilot************ 218 //PauPaw:Proper PID Controler for autopilot************
212 private bool m_moveToPositionInProgress; 219 private bool m_moveToPositionInProgress;
213 private Vector3 m_moveToPositionTarget; 220 private Vector3 m_moveToPositionTarget;
221 private Quaternion m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
214 222
215 private bool m_followCamAuto; 223 private bool m_followCamAuto;
216 224
217 private int m_movementUpdateCount; 225 private int m_movementUpdateCount;
226 private int m_lastColCount = -1; //KF: Look for Collision chnages
227 private int m_updateCount = 0; //KF: Update Anims for a while
228 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
218 private const int NumMovementsBetweenRayCast = 5; 229 private const int NumMovementsBetweenRayCast = 5;
230 private List<uint> m_lastColliders = new List<uint>();
219 231
220 private bool CameraConstraintActive; 232 private bool CameraConstraintActive;
221 //private int m_moveToPositionStateStatus; 233 //private int m_moveToPositionStateStatus;
@@ -242,7 +254,9 @@ namespace OpenSim.Region.Framework.Scenes
242 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 254 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
243 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 255 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
244 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 256 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
245 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 257 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
258 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
259 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
246 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 260 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
247 } 261 }
248 262
@@ -449,9 +463,18 @@ namespace OpenSim.Region.Framework.Scenes
449 get 463 get
450 { 464 {
451 PhysicsActor actor = m_physicsActor; 465 PhysicsActor actor = m_physicsActor;
452 if (actor != null) 466// if (actor != null)
467 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting!
453 m_pos = actor.Position; 468 m_pos = actor.Position;
454 469
470 // If we're sitting, we need to update our position
471 if (m_parentID != 0)
472 {
473 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
474 if (part != null)
475 m_parentPosition = part.AbsolutePosition;
476 }
477
455 return m_parentPosition + m_pos; 478 return m_parentPosition + m_pos;
456 } 479 }
457 set 480 set
@@ -470,7 +493,8 @@ namespace OpenSim.Region.Framework.Scenes
470 } 493 }
471 } 494 }
472 495
473 m_pos = value; 496 if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting!
497 m_pos = value;
474 m_parentPosition = Vector3.Zero; 498 m_parentPosition = Vector3.Zero;
475 } 499 }
476 } 500 }
@@ -514,10 +538,39 @@ namespace OpenSim.Region.Framework.Scenes
514 } 538 }
515 } 539 }
516 540
541 public Quaternion OffsetRotation
542 {
543 get { return m_offsetRotation; }
544 set { m_offsetRotation = value; }
545 }
546
517 public Quaternion Rotation 547 public Quaternion Rotation
518 { 548 {
519 get { return m_bodyRot; } 549 get {
520 set { m_bodyRot = value; } 550 if (m_parentID != 0)
551 {
552 if (m_offsetRotation != null)
553 {
554 return m_offsetRotation;
555 }
556 else
557 {
558 return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
559 }
560
561 }
562 else
563 {
564 return m_bodyRot;
565 }
566 }
567 set {
568 m_bodyRot = value;
569 if (m_parentID != 0)
570 {
571 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
572 }
573 }
521 } 574 }
522 575
523 public Quaternion PreviousRotation 576 public Quaternion PreviousRotation
@@ -542,11 +595,21 @@ namespace OpenSim.Region.Framework.Scenes
542 595
543 private uint m_parentID; 596 private uint m_parentID;
544 597
598
599 private UUID m_linkedPrim;
600
545 public uint ParentID 601 public uint ParentID
546 { 602 {
547 get { return m_parentID; } 603 get { return m_parentID; }
548 set { m_parentID = value; } 604 set { m_parentID = value; }
549 } 605 }
606
607 public UUID LinkedPrim
608 {
609 get { return m_linkedPrim; }
610 set { m_linkedPrim = value; }
611 }
612
550 public float Health 613 public float Health
551 { 614 {
552 get { return m_health; } 615 get { return m_health; }
@@ -668,7 +731,7 @@ namespace OpenSim.Region.Framework.Scenes
668 CreateSceneViewer(); 731 CreateSceneViewer();
669 m_animator = new ScenePresenceAnimator(this); 732 m_animator = new ScenePresenceAnimator(this);
670 } 733 }
671 734
672 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() 735 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this()
673 { 736 {
674 m_rootRegionHandle = reginfo.RegionHandle; 737 m_rootRegionHandle = reginfo.RegionHandle;
@@ -700,16 +763,16 @@ namespace OpenSim.Region.Framework.Scenes
700 m_reprioritization_timer.AutoReset = false; 763 m_reprioritization_timer.AutoReset = false;
701 764
702 AdjustKnownSeeds(); 765 AdjustKnownSeeds();
703
704 // TODO: I think, this won't send anything, as we are still a child here...
705 Animator.TrySetMovementAnimation("STAND"); 766 Animator.TrySetMovementAnimation("STAND");
706
707 // we created a new ScenePresence (a new child agent) in a fresh region. 767 // we created a new ScenePresence (a new child agent) in a fresh region.
708 // Request info about all the (root) agents in this region 768 // Request info about all the (root) agents in this region
709 // Note: This won't send data *to* other clients in that region (children don't send) 769 // Note: This won't send data *to* other clients in that region (children don't send)
710 SendInitialFullUpdateToAllClients(); 770 SendInitialFullUpdateToAllClients();
711
712 RegisterToEvents(); 771 RegisterToEvents();
772 if (m_controllingClient != null)
773 {
774 m_controllingClient.ProcessPendingPackets();
775 }
713 SetDirectionVectors(); 776 SetDirectionVectors();
714 } 777 }
715 778
@@ -759,25 +822,47 @@ namespace OpenSim.Region.Framework.Scenes
759 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 822 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
760 Dir_Vectors[4] = Vector3.UnitZ; //UP 823 Dir_Vectors[4] = Vector3.UnitZ; //UP
761 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 824 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
762 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 825 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
763 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 826 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
764 Dir_Vectors[7] = -Vector3.UnitX; //BACK 827 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
828 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
829 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
765 } 830 }
766 831
767 private Vector3[] GetWalkDirectionVectors() 832 private Vector3[] GetWalkDirectionVectors()
768 { 833 {
769 Vector3[] vector = new Vector3[9]; 834 Vector3[] vector = new Vector3[11];
770 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 835 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
771 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 836 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
772 vector[2] = Vector3.UnitY; //LEFT 837 vector[2] = Vector3.UnitY; //LEFT
773 vector[3] = -Vector3.UnitY; //RIGHT 838 vector[3] = -Vector3.UnitY; //RIGHT
774 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 839 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
775 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 840 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
776 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 841 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
777 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 842 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
778 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 843 vector[8] = Vector3.UnitY; //LEFT_NUDGE
844 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
845 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
779 return vector; 846 return vector;
780 } 847 }
848
849 private bool[] GetDirectionIsNudge()
850 {
851 bool[] isNudge = new bool[11];
852 isNudge[0] = false; //FORWARD
853 isNudge[1] = false; //BACK
854 isNudge[2] = false; //LEFT
855 isNudge[3] = false; //RIGHT
856 isNudge[4] = false; //UP
857 isNudge[5] = false; //DOWN
858 isNudge[6] = true; //FORWARD_NUDGE
859 isNudge[7] = true; //BACK_NUDGE
860 isNudge[8] = true; //LEFT_NUDGE
861 isNudge[9] = true; //RIGHT_NUDGE
862 isNudge[10] = true; //DOWN_Nudge
863 return isNudge;
864 }
865
781 866
782 #endregion 867 #endregion
783 868
@@ -820,7 +905,6 @@ namespace OpenSim.Region.Framework.Scenes
820 m_grouptitle = gm.GetGroupTitle(m_uuid); 905 m_grouptitle = gm.GetGroupTitle(m_uuid);
821 906
822 m_rootRegionHandle = m_scene.RegionInfo.RegionHandle; 907 m_rootRegionHandle = m_scene.RegionInfo.RegionHandle;
823
824 m_scene.SetRootAgentScene(m_uuid); 908 m_scene.SetRootAgentScene(m_uuid);
825 909
826 // Moved this from SendInitialData to ensure that m_appearance is initialized 910 // Moved this from SendInitialData to ensure that m_appearance is initialized
@@ -839,6 +923,52 @@ namespace OpenSim.Region.Framework.Scenes
839 pos.Y = crossedBorder.BorderLine.Z - 1; 923 pos.Y = crossedBorder.BorderLine.Z - 1;
840 } 924 }
841 925
926 //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet.
927 //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent,
928 //they'll bypass the landing point. But I can't think of any decent way of fixing this.
929 if (KnownChildRegionHandles.Count == 0)
930 {
931 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
932 if (land != null)
933 {
934 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
935 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)
936 {
937 pos = land.LandData.UserLocation;
938 }
939 }
940 }
941
942 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0)
943 {
944 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128);
945
946 if (pos.X < 0)
947 {
948 emergencyPos.X = (int)Constants.RegionSize + pos.X;
949 if (!(pos.Y < 0))
950 emergencyPos.Y = pos.Y;
951 if (!(pos.Z < 0))
952 emergencyPos.Z = pos.Z;
953 }
954 if (pos.Y < 0)
955 {
956 emergencyPos.Y = (int)Constants.RegionSize + pos.Y;
957 if (!(pos.X < 0))
958 emergencyPos.X = pos.X;
959 if (!(pos.Z < 0))
960 emergencyPos.Z = pos.Z;
961 }
962 if (pos.Z < 0)
963 {
964 emergencyPos.Z = 128;
965 if (!(pos.Y < 0))
966 emergencyPos.Y = pos.Y;
967 if (!(pos.X < 0))
968 emergencyPos.X = pos.X;
969 }
970 }
971
842 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 972 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
843 { 973 {
844 m_log.WarnFormat( 974 m_log.WarnFormat(
@@ -976,9 +1106,10 @@ namespace OpenSim.Region.Framework.Scenes
976 public void Teleport(Vector3 pos) 1106 public void Teleport(Vector3 pos)
977 { 1107 {
978 bool isFlying = false; 1108 bool isFlying = false;
1109
979 if (m_physicsActor != null) 1110 if (m_physicsActor != null)
980 isFlying = m_physicsActor.Flying; 1111 isFlying = m_physicsActor.Flying;
981 1112
982 RemoveFromPhysicalScene(); 1113 RemoveFromPhysicalScene();
983 Velocity = Vector3.Zero; 1114 Velocity = Vector3.Zero;
984 AbsolutePosition = pos; 1115 AbsolutePosition = pos;
@@ -990,6 +1121,7 @@ namespace OpenSim.Region.Framework.Scenes
990 } 1121 }
991 1122
992 SendTerseUpdateToAllClients(); 1123 SendTerseUpdateToAllClients();
1124
993 } 1125 }
994 1126
995 public void TeleportWithMomentum(Vector3 pos) 1127 public void TeleportWithMomentum(Vector3 pos)
@@ -1103,7 +1235,6 @@ namespace OpenSim.Region.Framework.Scenes
1103 pos.Z = ground + 1.5f; 1235 pos.Z = ground + 1.5f;
1104 AbsolutePosition = pos; 1236 AbsolutePosition = pos;
1105 } 1237 }
1106
1107 m_isChildAgent = false; 1238 m_isChildAgent = false;
1108 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 1239 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1109 MakeRootAgent(AbsolutePosition, m_flying); 1240 MakeRootAgent(AbsolutePosition, m_flying);
@@ -1202,6 +1333,7 @@ namespace OpenSim.Region.Framework.Scenes
1202 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); 1333 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902");
1203 1334
1204 m_pos = m_LastFinitePos; 1335 m_pos = m_LastFinitePos;
1336
1205 if (!m_pos.IsFinite()) 1337 if (!m_pos.IsFinite())
1206 { 1338 {
1207 m_pos.X = 127f; 1339 m_pos.X = 127f;
@@ -1268,7 +1400,6 @@ namespace OpenSim.Region.Framework.Scenes
1268 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1400 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1269 } 1401 }
1270 } 1402 }
1271
1272 lock (scriptedcontrols) 1403 lock (scriptedcontrols)
1273 { 1404 {
1274 if (scriptedcontrols.Count > 0) 1405 if (scriptedcontrols.Count > 0)
@@ -1283,6 +1414,9 @@ namespace OpenSim.Region.Framework.Scenes
1283 1414
1284 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1415 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1285 { 1416 {
1417 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1418 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1419
1286 // TODO: This doesn't prevent the user from walking yet. 1420 // TODO: This doesn't prevent the user from walking yet.
1287 // Setting parent ID would fix this, if we knew what value 1421 // Setting parent ID would fix this, if we knew what value
1288 // to use. Or we could add a m_isSitting variable. 1422 // to use. Or we could add a m_isSitting variable.
@@ -1337,6 +1471,11 @@ namespace OpenSim.Region.Framework.Scenes
1337 update_rotation = true; 1471 update_rotation = true;
1338 } 1472 }
1339 1473
1474 //guilty until proven innocent..
1475 bool Nudging = true;
1476 //Basically, if there is at least one non-nudge control then we don't need
1477 //to worry about stopping the avatar
1478
1340 if (m_parentID == 0) 1479 if (m_parentID == 0)
1341 { 1480 {
1342 bool bAllowUpdateMoveToPosition = false; 1481 bool bAllowUpdateMoveToPosition = false;
@@ -1351,9 +1490,12 @@ namespace OpenSim.Region.Framework.Scenes
1351 else 1490 else
1352 dirVectors = Dir_Vectors; 1491 dirVectors = Dir_Vectors;
1353 1492
1354 // The fact that m_movementflag is a byte needs to be fixed 1493 bool[] isNudge = GetDirectionIsNudge();
1355 // it really should be a uint 1494
1356 uint nudgehack = 250; 1495
1496
1497
1498
1357 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1499 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1358 { 1500 {
1359 if (((uint)flags & (uint)DCF) != 0) 1501 if (((uint)flags & (uint)DCF) != 0)
@@ -1363,40 +1505,28 @@ namespace OpenSim.Region.Framework.Scenes
1363 try 1505 try
1364 { 1506 {
1365 agent_control_v3 += dirVectors[i]; 1507 agent_control_v3 += dirVectors[i];
1366 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1508 if (isNudge[i] == false)
1509 {
1510 Nudging = false;
1511 }
1367 } 1512 }
1368 catch (IndexOutOfRangeException) 1513 catch (IndexOutOfRangeException)
1369 { 1514 {
1370 // Why did I get this? 1515 // Why did I get this?
1371 } 1516 }
1372 1517
1373 if ((m_movementflag & (byte)(uint)DCF) == 0) 1518 if ((m_movementflag & (uint)DCF) == 0)
1374 { 1519 {
1375 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1376 {
1377 m_movementflag |= (byte)nudgehack;
1378 }
1379 m_movementflag += (byte)(uint)DCF; 1520 m_movementflag += (byte)(uint)DCF;
1380 update_movementflag = true; 1521 update_movementflag = true;
1381 } 1522 }
1382 } 1523 }
1383 else 1524 else
1384 { 1525 {
1385 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1526 if ((m_movementflag & (uint)DCF) != 0)
1386 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1387 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1388 ) // This or is for Nudge forward
1389 { 1527 {
1390 m_movementflag -= ((byte)(uint)DCF); 1528 m_movementflag -= (byte)(uint)DCF;
1391
1392 update_movementflag = true; 1529 update_movementflag = true;
1393 /*
1394 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1395 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1396 {
1397 m_log.Debug("Removed Hack flag");
1398 }
1399 */
1400 } 1530 }
1401 else 1531 else
1402 { 1532 {
@@ -1405,7 +1535,6 @@ namespace OpenSim.Region.Framework.Scenes
1405 } 1535 }
1406 i++; 1536 i++;
1407 } 1537 }
1408
1409 //Paupaw:Do Proper PID for Autopilot here 1538 //Paupaw:Do Proper PID for Autopilot here
1410 if (bResetMoveToPosition) 1539 if (bResetMoveToPosition)
1411 { 1540 {
@@ -1440,6 +1569,9 @@ namespace OpenSim.Region.Framework.Scenes
1440 // Ignore z component of vector 1569 // Ignore z component of vector
1441 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1570 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1442 LocalVectorToTarget2D.Normalize(); 1571 LocalVectorToTarget2D.Normalize();
1572
1573 //We're not nudging
1574 Nudging = false;
1443 agent_control_v3 += LocalVectorToTarget2D; 1575 agent_control_v3 += LocalVectorToTarget2D;
1444 1576
1445 // update avatar movement flags. the avatar coordinate system is as follows: 1577 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1528,13 +1660,13 @@ namespace OpenSim.Region.Framework.Scenes
1528 // m_log.DebugFormat( 1660 // m_log.DebugFormat(
1529 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1661 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1530 1662
1531 AddNewMovement(agent_control_v3, q); 1663 AddNewMovement(agent_control_v3, q, Nudging);
1532 1664
1533 1665
1534 } 1666 }
1535 } 1667 }
1536 1668
1537 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1669 if (update_movementflag && !SitGround)
1538 Animator.UpdateMovementAnimations(); 1670 Animator.UpdateMovementAnimations();
1539 1671
1540 m_scene.EventManager.TriggerOnClientMovement(this); 1672 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1549,7 +1681,6 @@ namespace OpenSim.Region.Framework.Scenes
1549 m_sitAtAutoTarget = false; 1681 m_sitAtAutoTarget = false;
1550 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1682 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1551 //proxy.PCode = (byte)PCode.ParticleSystem; 1683 //proxy.PCode = (byte)PCode.ParticleSystem;
1552
1553 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1684 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1554 proxyObjectGroup.AttachToScene(m_scene); 1685 proxyObjectGroup.AttachToScene(m_scene);
1555 1686
@@ -1591,7 +1722,7 @@ namespace OpenSim.Region.Framework.Scenes
1591 } 1722 }
1592 m_moveToPositionInProgress = true; 1723 m_moveToPositionInProgress = true;
1593 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1724 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1594 } 1725 }
1595 catch (Exception ex) 1726 catch (Exception ex)
1596 { 1727 {
1597 //Why did I get this error? 1728 //Why did I get this error?
@@ -1613,7 +1744,7 @@ namespace OpenSim.Region.Framework.Scenes
1613 Velocity = Vector3.Zero; 1744 Velocity = Vector3.Zero;
1614 SendFullUpdateToAllClients(); 1745 SendFullUpdateToAllClients();
1615 1746
1616 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1747 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1617 } 1748 }
1618 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1749 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1619 m_requestedSitTargetUUID = UUID.Zero; 1750 m_requestedSitTargetUUID = UUID.Zero;
@@ -1650,50 +1781,85 @@ namespace OpenSim.Region.Framework.Scenes
1650 1781
1651 if (m_parentID != 0) 1782 if (m_parentID != 0)
1652 { 1783 {
1653 m_log.Debug("StandupCode Executed"); 1784 SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID);
1654 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1655 if (part != null) 1785 if (part != null)
1656 { 1786 {
1787 part.TaskInventory.LockItemsForRead(true);
1657 TaskInventoryDictionary taskIDict = part.TaskInventory; 1788 TaskInventoryDictionary taskIDict = part.TaskInventory;
1658 if (taskIDict != null) 1789 if (taskIDict != null)
1659 { 1790 {
1660 lock (taskIDict) 1791 foreach (UUID taskID in taskIDict.Keys)
1661 { 1792 {
1662 foreach (UUID taskID in taskIDict.Keys) 1793 UnRegisterControlEventsToScript(LocalId, taskID);
1663 { 1794 taskIDict[taskID].PermsMask &= ~(
1664 UnRegisterControlEventsToScript(LocalId, taskID); 1795 2048 | //PERMISSION_CONTROL_CAMERA
1665 taskIDict[taskID].PermsMask &= ~( 1796 4); // PERMISSION_TAKE_CONTROLS
1666 2048 | //PERMISSION_CONTROL_CAMERA
1667 4); // PERMISSION_TAKE_CONTROLS
1668 }
1669 } 1797 }
1670
1671 } 1798 }
1799 part.TaskInventory.LockItemsForRead(false);
1672 // Reset sit target. 1800 // Reset sit target.
1673 if (part.GetAvatarOnSitTarget() == UUID) 1801 if (part.GetAvatarOnSitTarget() == UUID)
1674 part.SetAvatarOnSitTarget(UUID.Zero); 1802 part.SetAvatarOnSitTarget(UUID.Zero);
1675
1676 m_parentPosition = part.GetWorldPosition(); 1803 m_parentPosition = part.GetWorldPosition();
1677 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1804 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1678 } 1805 }
1806 // part.GetWorldRotation() is the rotation of the object being sat on
1807 // Rotation is the sittiing Av's rotation
1808
1809 Quaternion partRot;
1810// if (part.LinkNum == 1)
1811// { // Root prim of linkset
1812// partRot = part.ParentGroup.RootPart.RotationOffset;
1813// }
1814// else
1815// { // single or child prim
1816
1817// }
1818 if (part == null) //CW: Part may be gone. llDie() for example.
1819 {
1820 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1821 }
1822 else
1823 {
1824 partRot = part.GetWorldRotation();
1825 }
1826
1827 Quaternion partIRot = Quaternion.Inverse(partRot);
1828
1829 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1830 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1679 1831
1832
1680 if (m_physicsActor == null) 1833 if (m_physicsActor == null)
1681 { 1834 {
1682 AddToPhysicalScene(false); 1835 AddToPhysicalScene(false);
1683 } 1836 }
1684 1837 //CW: If the part isn't null then we can set the current position
1685 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1838 if (part != null)
1686 m_parentPosition = Vector3.Zero; 1839 {
1687 1840 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + ((m_pos - part.OffsetPosition) * partRot); // + av sit offset!
1688 m_parentID = 0; 1841 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1842 part.IsOccupied = false;
1843 part.ParentGroup.DeleteAvatar(ControllingClient.AgentId);
1844 }
1845 else
1846 {
1847 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1848 AbsolutePosition = m_lastWorldPosition;
1849 }
1850
1851 m_parentPosition = Vector3.Zero;
1852 m_parentID = 0;
1853 m_linkedPrim = UUID.Zero;
1854 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1689 SendFullUpdateToAllClients(); 1855 SendFullUpdateToAllClients();
1690 m_requestedSitTargetID = 0; 1856 m_requestedSitTargetID = 0;
1857
1691 if ((m_physicsActor != null) && (m_avHeight > 0)) 1858 if ((m_physicsActor != null) && (m_avHeight > 0))
1692 { 1859 {
1693 SetHeight(m_avHeight); 1860 SetHeight(m_avHeight);
1694 } 1861 }
1695 } 1862 }
1696
1697 Animator.TrySetMovementAnimation("STAND"); 1863 Animator.TrySetMovementAnimation("STAND");
1698 } 1864 }
1699 1865
@@ -1724,13 +1890,9 @@ namespace OpenSim.Region.Framework.Scenes
1724 Vector3 avSitOffSet = part.SitTargetPosition; 1890 Vector3 avSitOffSet = part.SitTargetPosition;
1725 Quaternion avSitOrientation = part.SitTargetOrientation; 1891 Quaternion avSitOrientation = part.SitTargetOrientation;
1726 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1892 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1727 1893 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1728 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1894 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1729 bool SitTargetisSet = 1895 if (SitTargetisSet && !SitTargetOccupied)
1730 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1731 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1732
1733 if (SitTargetisSet && SitTargetUnOccupied)
1734 { 1896 {
1735 //switch the target to this prim 1897 //switch the target to this prim
1736 return part; 1898 return part;
@@ -1744,84 +1906,162 @@ namespace OpenSim.Region.Framework.Scenes
1744 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1906 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1745 { 1907 {
1746 bool autopilot = true; 1908 bool autopilot = true;
1909 Vector3 autopilotTarget = new Vector3();
1910 Quaternion sitOrientation = Quaternion.Identity;
1747 Vector3 pos = new Vector3(); 1911 Vector3 pos = new Vector3();
1748 Quaternion sitOrientation = pSitOrientation;
1749 Vector3 cameraEyeOffset = Vector3.Zero; 1912 Vector3 cameraEyeOffset = Vector3.Zero;
1750 Vector3 cameraAtOffset = Vector3.Zero; 1913 Vector3 cameraAtOffset = Vector3.Zero;
1751 bool forceMouselook = false; 1914 bool forceMouselook = false;
1752 1915
1753 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1916 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1754 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1917 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1755 if (part != null) 1918 if (part == null) return;
1756 { 1919
1757 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1920 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1758 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1921 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1759 1922
1760 // Is a sit target available? 1923 // part is the prim to sit on
1761 Vector3 avSitOffSet = part.SitTargetPosition; 1924 // offset is the world-ref vector distance from that prim center to the click-spot
1762 Quaternion avSitOrientation = part.SitTargetOrientation; 1925 // UUID is the UUID of the Avatar doing the clicking
1763 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1926
1764 1927 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1765 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1928
1766 bool SitTargetisSet = 1929 // Is a sit target available?
1767 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1930 Vector3 avSitOffSet = part.SitTargetPosition;
1768 ( 1931 Quaternion avSitOrientation = part.SitTargetOrientation;
1769 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1932
1770 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1933 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1771 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1934 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1772 ) 1935 Quaternion partRot;
1773 )); 1936// if (part.LinkNum == 1)
1774 1937// { // Root prim of linkset
1775 if (SitTargetisSet && SitTargetUnOccupied) 1938// partRot = part.ParentGroup.RootPart.RotationOffset;
1776 { 1939// }
1777 part.SetAvatarOnSitTarget(UUID); 1940// else
1778 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1941// { // single or child prim
1779 sitOrientation = avSitOrientation; 1942 partRot = part.GetWorldRotation();
1780 autopilot = false; 1943// }
1781 } 1944 Quaternion partIRot = Quaternion.Inverse(partRot);
1782 1945//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1783 pos = part.AbsolutePosition + offset; 1946 // Sit analysis rewritten by KF 091125
1784 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1947 if (SitTargetisSet) // scipted sit
1785 //{ 1948 {
1786 // offset = pos; 1949 if (!part.IsOccupied)
1787 //autopilot = false; 1950 {
1788 //} 1951//Console.WriteLine("Scripted, unoccupied");
1789 if (m_physicsActor != null) 1952 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1790 { 1953 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1791 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1954
1792 // We can remove the physicsActor until they stand up. 1955 Quaternion nrot = avSitOrientation;
1793 m_sitAvatarHeight = m_physicsActor.Size.Z; 1956 if (!part.IsRoot)
1794
1795 if (autopilot)
1796 { 1957 {
1797 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1958 nrot = part.RotationOffset * avSitOrientation;
1798 {
1799 autopilot = false;
1800
1801 RemoveFromPhysicalScene();
1802 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
1803 }
1804 } 1959 }
1805 else 1960 sitOrientation = nrot; // Change rotatione to the scripted one
1961 OffsetRotation = nrot;
1962 autopilot = false; // Jump direct to scripted llSitPos()
1963 }
1964 else
1965 {
1966//Console.WriteLine("Scripted, occupied");
1967 return;
1968 }
1969 }
1970 else // Not Scripted
1971 {
1972 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
1973 {
1974 // large prim & offset, ignore if other Avs sitting
1975// offset.Z -= 0.05f;
1976 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
1977 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
1978
1979//Console.WriteLine(" offset ={0}", offset);
1980//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
1981//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
1982
1983 }
1984 else // small offset
1985 {
1986//Console.WriteLine("Small offset");
1987 if (!part.IsOccupied)
1988 {
1989 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
1990 autopilotTarget = part.AbsolutePosition;
1991//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget);
1992 }
1993 else return; // occupied small
1994 } // end large/small
1995 } // end Scripted/not
1996 cameraAtOffset = part.GetCameraAtOffset();
1997 cameraEyeOffset = part.GetCameraEyeOffset();
1998 forceMouselook = part.GetForceMouselook();
1999 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
2000 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
2001
2002 if (m_physicsActor != null)
2003 {
2004 // If we're not using the client autopilot, we're immediately warping the avatar to the location
2005 // We can remove the physicsActor until they stand up.
2006 m_sitAvatarHeight = m_physicsActor.Size.Z;
2007 if (autopilot)
2008 { // its not a scripted sit
2009// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
2010 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 2.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 2.0f) )
1806 { 2011 {
2012 autopilot = false; // close enough
2013 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2014 Not using the part's position because returning the AV to the last known standing
2015 position is likely to be more friendly, isn't it? */
1807 RemoveFromPhysicalScene(); 2016 RemoveFromPhysicalScene();
1808 } 2017 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
2018 } // else the autopilot will get us close
2019 }
2020 else
2021 { // its a scripted sit
2022 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2023 I *am* using the part's position this time because we have no real idea how far away
2024 the avatar is from the sit target. */
2025 RemoveFromPhysicalScene();
1809 } 2026 }
1810
1811 cameraAtOffset = part.GetCameraAtOffset();
1812 cameraEyeOffset = part.GetCameraEyeOffset();
1813 forceMouselook = part.GetForceMouselook();
1814 } 2027 }
1815 2028 else return; // physactor is null!
1816 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 2029
1817 m_requestedSitTargetUUID = targetID; 2030 Vector3 offsetr; // = offset * partIRot;
2031 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
2032 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
2033 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
2034 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
2035 //offsetr = offset * partIRot;
2036//
2037 // else
2038 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
2039 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
2040 // (offset * partRot);
2041 // }
2042
2043//Console.WriteLine(" ");
2044//Console.WriteLine("link number ={0}", part.LinkNum);
2045//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
2046//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
2047//Console.WriteLine("Click offst ={0}", offset);
2048//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
2049//Console.WriteLine("offsetr ={0}", offsetr);
2050//Console.WriteLine("Camera At ={0}", cameraAtOffset);
2051//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
2052
2053 //NOTE: SendSitResponse should be relative to the GROUP *NOT* THE PRIM if we're sitting on a child
2054 ControllingClient.SendSitResponse(part.ParentGroup.UUID, ((offset * part.RotationOffset) + part.OffsetPosition), sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
2055
2056 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1818 // This calls HandleAgentSit twice, once from here, and the client calls 2057 // This calls HandleAgentSit twice, once from here, and the client calls
1819 // HandleAgentSit itself after it gets to the location 2058 // HandleAgentSit itself after it gets to the location
1820 // It doesn't get to the location until we've moved them there though 2059 // It doesn't get to the location until we've moved them there though
1821 // which happens in HandleAgentSit :P 2060 // which happens in HandleAgentSit :P
1822 m_autopilotMoving = autopilot; 2061 m_autopilotMoving = autopilot;
1823 m_autoPilotTarget = pos; 2062 m_autoPilotTarget = autopilotTarget;
1824 m_sitAtAutoTarget = autopilot; 2063 m_sitAtAutoTarget = autopilot;
2064 m_initialSitTarget = autopilotTarget;
1825 if (!autopilot) 2065 if (!autopilot)
1826 HandleAgentSit(remoteClient, UUID); 2066 HandleAgentSit(remoteClient, UUID);
1827 } 2067 }
@@ -2116,47 +2356,128 @@ namespace OpenSim.Region.Framework.Scenes
2116 { 2356 {
2117 if (part != null) 2357 if (part != null)
2118 { 2358 {
2359//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2119 if (part.GetAvatarOnSitTarget() == UUID) 2360 if (part.GetAvatarOnSitTarget() == UUID)
2120 { 2361 {
2362//Console.WriteLine("Scripted Sit");
2363 // Scripted sit
2121 Vector3 sitTargetPos = part.SitTargetPosition; 2364 Vector3 sitTargetPos = part.SitTargetPosition;
2122 Quaternion sitTargetOrient = part.SitTargetOrientation; 2365 Quaternion sitTargetOrient = part.SitTargetOrientation;
2123
2124 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2125 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2126
2127 //Quaternion result = (sitTargetOrient * vq) * nq;
2128
2129 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2366 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2130 m_pos += SIT_TARGET_ADJUSTMENT; 2367 m_pos += SIT_TARGET_ADJUSTMENT;
2368 if (!part.IsRoot)
2369 {
2370 m_pos *= part.RotationOffset;
2371 }
2131 m_bodyRot = sitTargetOrient; 2372 m_bodyRot = sitTargetOrient;
2132 //Rotation = sitTargetOrient;
2133 m_parentPosition = part.AbsolutePosition; 2373 m_parentPosition = part.AbsolutePosition;
2134 2374 part.IsOccupied = true;
2135 //SendTerseUpdateToAllClients(); 2375 part.ParentGroup.AddAvatar(agentID);
2376Console.WriteLine("Scripted Sit ofset {0}", m_pos);
2136 } 2377 }
2137 else 2378 else
2138 { 2379 {
2139 m_pos -= part.AbsolutePosition; 2380 // if m_avUnscriptedSitPos is zero then Av sits above center
2381 // Else Av sits at m_avUnscriptedSitPos
2382
2383 // Non-scripted sit by Kitto Flora 21Nov09
2384 // Calculate angle of line from prim to Av
2385 Quaternion partIRot;
2386// if (part.LinkNum == 1)
2387// { // Root prim of linkset
2388// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2389// }
2390// else
2391// { // single or child prim
2392 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2393// }
2394 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2395 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2396 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2397 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2398 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2399 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2400 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2401 // Av sits at world euler <0,0, z>, translated by part rotation
2402 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2403
2140 m_parentPosition = part.AbsolutePosition; 2404 m_parentPosition = part.AbsolutePosition;
2141 } 2405 part.IsOccupied = true;
2406 part.ParentGroup.AddAvatar(agentID);
2407 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2408 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2409 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2410 m_avUnscriptedSitPos; // adds click offset, if any
2411 //Set up raytrace to find top surface of prim
2412 Vector3 size = part.Scale;
2413 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2414 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2415 Vector3 down = new Vector3(0f, 0f, -1f);
2416//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2417 m_scene.PhysicsScene.RaycastWorld(
2418 start, // Vector3 position,
2419 down, // Vector3 direction,
2420 mag, // float length,
2421 SitAltitudeCallback); // retMethod
2422 } // end scripted/not
2142 } 2423 }
2143 else 2424 else // no Av
2144 { 2425 {
2145 return; 2426 return;
2146 } 2427 }
2147 } 2428 }
2148 m_parentID = m_requestedSitTargetID; 2429
2430 //We want our offsets to reference the root prim, not the child we may have sat on
2431 if (!part.IsRoot)
2432 {
2433 m_parentID = part.ParentGroup.RootPart.LocalId;
2434 m_pos += part.OffsetPosition;
2435 }
2436 else
2437 {
2438 m_parentID = m_requestedSitTargetID;
2439 }
2440
2441 m_linkedPrim = part.UUID;
2149 2442
2150 Velocity = Vector3.Zero; 2443 Velocity = Vector3.Zero;
2151 RemoveFromPhysicalScene(); 2444 RemoveFromPhysicalScene();
2152 2445
2153 Animator.TrySetMovementAnimation(sitAnimation); 2446 Animator.TrySetMovementAnimation(sitAnimation);
2154 SendFullUpdateToAllClients(); 2447 SendFullUpdateToAllClients();
2155 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2156 // So we're also sending a terse update (which has avatar rotation)
2157 // [Update] We do now.
2158 //SendTerseUpdateToAllClients();
2159 } 2448 }
2449
2450 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2451 {
2452 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2453 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2454 if(hitYN)
2455 {
2456 // m_pos = Av offset from prim center to make look like on center
2457 // m_parentPosition = Actual center pos of prim
2458 // collisionPoint = spot on prim where we want to sit
2459 // collisionPoint.Z = global sit surface height
2460 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2461 Quaternion partIRot;
2462// if (part.LinkNum == 1)
2463/// { // Root prim of linkset
2464// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2465// }
2466// else
2467// { // single or child prim
2468 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2469// }
2470 if (m_initialSitTarget != null)
2471 {
2472 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2473 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2474 //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2475 m_pos += offset;
2476 // ControllingClient.SendClearFollowCamProperties(part.UUID);
2477 }
2478
2479 }
2480 } // End SitAltitudeCallback KF.
2160 2481
2161 /// <summary> 2482 /// <summary>
2162 /// Event handler for the 'Always run' setting on the client 2483 /// Event handler for the 'Always run' setting on the client
@@ -2186,7 +2507,7 @@ namespace OpenSim.Region.Framework.Scenes
2186 /// </summary> 2507 /// </summary>
2187 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2508 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2188 /// <param name="rotation">The direction in which this avatar should now face. 2509 /// <param name="rotation">The direction in which this avatar should now face.
2189 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2510 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2190 { 2511 {
2191 if (m_isChildAgent) 2512 if (m_isChildAgent)
2192 { 2513 {
@@ -2227,10 +2548,11 @@ namespace OpenSim.Region.Framework.Scenes
2227 Rotation = rotation; 2548 Rotation = rotation;
2228 Vector3 direc = vec * rotation; 2549 Vector3 direc = vec * rotation;
2229 direc.Normalize(); 2550 direc.Normalize();
2551 PhysicsActor actor = m_physicsActor;
2552 if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up.
2230 2553
2231 direc *= 0.03f * 128f * m_speedModifier; 2554 direc *= 0.03f * 128f * m_speedModifier;
2232 2555
2233 PhysicsActor actor = m_physicsActor;
2234 if (actor != null) 2556 if (actor != null)
2235 { 2557 {
2236 if (actor.Flying) 2558 if (actor.Flying)
@@ -2252,18 +2574,25 @@ namespace OpenSim.Region.Framework.Scenes
2252 { 2574 {
2253 if (direc.Z > 2.0f) 2575 if (direc.Z > 2.0f)
2254 { 2576 {
2255 direc.Z *= 3.0f; 2577 if(m_animator.m_animTickJump == -1)
2256 2578 {
2257 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2579 direc.Z *= 3.0f; // jump
2258 Animator.TrySetMovementAnimation("PREJUMP"); 2580 }
2259 Animator.TrySetMovementAnimation("JUMP"); 2581 else
2582 {
2583 direc.Z *= 0.1f; // prejump
2584 }
2585 /* Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs
2586 Animator.TrySetMovementAnimation("PREJUMP");
2587 Animator.TrySetMovementAnimation("JUMP");
2588 */
2260 } 2589 }
2261 } 2590 }
2262 } 2591 }
2263 2592
2264 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2593 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2265 m_forceToApply = direc; 2594 m_forceToApply = direc;
2266 2595 m_isNudging = Nudging;
2267 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2596 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2268 } 2597 }
2269 2598
@@ -2278,7 +2607,7 @@ namespace OpenSim.Region.Framework.Scenes
2278 const float POSITION_TOLERANCE = 0.05f; 2607 const float POSITION_TOLERANCE = 0.05f;
2279 //const int TIME_MS_TOLERANCE = 3000; 2608 //const int TIME_MS_TOLERANCE = 3000;
2280 2609
2281 SendPrimUpdates(); 2610
2282 2611
2283 if (m_isChildAgent == false) 2612 if (m_isChildAgent == false)
2284 { 2613 {
@@ -2308,6 +2637,9 @@ namespace OpenSim.Region.Framework.Scenes
2308 CheckForBorderCrossing(); 2637 CheckForBorderCrossing();
2309 CheckForSignificantMovement(); // sends update to the modules. 2638 CheckForSignificantMovement(); // sends update to the modules.
2310 } 2639 }
2640
2641 //Sending prim updates AFTER the avatar terse updates are sent
2642 SendPrimUpdates();
2311 } 2643 }
2312 2644
2313 #endregion 2645 #endregion
@@ -3092,6 +3424,7 @@ namespace OpenSim.Region.Framework.Scenes
3092 m_callbackURI = cAgent.CallbackURI; 3424 m_callbackURI = cAgent.CallbackURI;
3093 3425
3094 m_pos = cAgent.Position; 3426 m_pos = cAgent.Position;
3427
3095 m_velocity = cAgent.Velocity; 3428 m_velocity = cAgent.Velocity;
3096 m_CameraCenter = cAgent.Center; 3429 m_CameraCenter = cAgent.Center;
3097 //m_avHeight = cAgent.Size.Z; 3430 //m_avHeight = cAgent.Size.Z;
@@ -3202,14 +3535,25 @@ namespace OpenSim.Region.Framework.Scenes
3202 { 3535 {
3203 if (m_forceToApply.HasValue) 3536 if (m_forceToApply.HasValue)
3204 { 3537 {
3205 Vector3 force = m_forceToApply.Value;
3206 3538
3539 Vector3 force = m_forceToApply.Value;
3207 m_updateflag = true; 3540 m_updateflag = true;
3208// movementvector = force;
3209 Velocity = force; 3541 Velocity = force;
3210 3542
3211 m_forceToApply = null; 3543 m_forceToApply = null;
3212 } 3544 }
3545 else
3546 {
3547 if (m_isNudging)
3548 {
3549 Vector3 force = Vector3.Zero;
3550
3551 m_updateflag = true;
3552 Velocity = force;
3553 m_isNudging = false;
3554 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3555 }
3556 }
3213 } 3557 }
3214 3558
3215 public override void SetText(string text, Vector3 color, double alpha) 3559 public override void SetText(string text, Vector3 color, double alpha)
@@ -3260,18 +3604,29 @@ namespace OpenSim.Region.Framework.Scenes
3260 { 3604 {
3261 if (e == null) 3605 if (e == null)
3262 return; 3606 return;
3263 3607
3264 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3608 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3265 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3266 // as of this comment the interval is set in AddToPhysicalScene 3609 // as of this comment the interval is set in AddToPhysicalScene
3267 if (Animator!=null) 3610 if (Animator!=null)
3268 Animator.UpdateMovementAnimations(); 3611 {
3612 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3613 { // else its will lock out other animation changes, like ground sit.
3614 Animator.UpdateMovementAnimations();
3615 m_updateCount--;
3616 }
3617 }
3269 3618
3270 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3619 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3271 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3620 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3272 3621
3273 CollisionPlane = Vector4.UnitW; 3622 CollisionPlane = Vector4.UnitW;
3274 3623
3624 if (m_lastColCount != coldata.Count)
3625 {
3626 m_updateCount = UPDATE_COUNT;
3627 m_lastColCount = coldata.Count;
3628 }
3629
3275 if (coldata.Count != 0 && Animator != null) 3630 if (coldata.Count != 0 && Animator != null)
3276 { 3631 {
3277 switch (Animator.CurrentMovementAnimation) 3632 switch (Animator.CurrentMovementAnimation)
@@ -3301,6 +3656,148 @@ namespace OpenSim.Region.Framework.Scenes
3301 } 3656 }
3302 } 3657 }
3303 3658
3659 List<uint> thisHitColliders = new List<uint>();
3660 List<uint> endedColliders = new List<uint>();
3661 List<uint> startedColliders = new List<uint>();
3662
3663 foreach (uint localid in coldata.Keys)
3664 {
3665 thisHitColliders.Add(localid);
3666 if (!m_lastColliders.Contains(localid))
3667 {
3668 startedColliders.Add(localid);
3669 }
3670 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
3671 }
3672
3673 // calculate things that ended colliding
3674 foreach (uint localID in m_lastColliders)
3675 {
3676 if (!thisHitColliders.Contains(localID))
3677 {
3678 endedColliders.Add(localID);
3679 }
3680 }
3681 //add the items that started colliding this time to the last colliders list.
3682 foreach (uint localID in startedColliders)
3683 {
3684 m_lastColliders.Add(localID);
3685 }
3686 // remove things that ended colliding from the last colliders list
3687 foreach (uint localID in endedColliders)
3688 {
3689 m_lastColliders.Remove(localID);
3690 }
3691
3692 // do event notification
3693 if (startedColliders.Count > 0)
3694 {
3695 ColliderArgs StartCollidingMessage = new ColliderArgs();
3696 List<DetectedObject> colliding = new List<DetectedObject>();
3697 foreach (uint localId in startedColliders)
3698 {
3699 if (localId == 0)
3700 continue;
3701
3702 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3703 string data = "";
3704 if (obj != null)
3705 {
3706 DetectedObject detobj = new DetectedObject();
3707 detobj.keyUUID = obj.UUID;
3708 detobj.nameStr = obj.Name;
3709 detobj.ownerUUID = obj.OwnerID;
3710 detobj.posVector = obj.AbsolutePosition;
3711 detobj.rotQuat = obj.GetWorldRotation();
3712 detobj.velVector = obj.Velocity;
3713 detobj.colliderType = 0;
3714 detobj.groupUUID = obj.GroupID;
3715 colliding.Add(detobj);
3716 }
3717 }
3718
3719 if (colliding.Count > 0)
3720 {
3721 StartCollidingMessage.Colliders = colliding;
3722
3723 foreach (SceneObjectGroup att in Attachments)
3724 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
3725 }
3726 }
3727
3728 if (endedColliders.Count > 0)
3729 {
3730 ColliderArgs EndCollidingMessage = new ColliderArgs();
3731 List<DetectedObject> colliding = new List<DetectedObject>();
3732 foreach (uint localId in endedColliders)
3733 {
3734 if (localId == 0)
3735 continue;
3736
3737 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3738 string data = "";
3739 if (obj != null)
3740 {
3741 DetectedObject detobj = new DetectedObject();
3742 detobj.keyUUID = obj.UUID;
3743 detobj.nameStr = obj.Name;
3744 detobj.ownerUUID = obj.OwnerID;
3745 detobj.posVector = obj.AbsolutePosition;
3746 detobj.rotQuat = obj.GetWorldRotation();
3747 detobj.velVector = obj.Velocity;
3748 detobj.colliderType = 0;
3749 detobj.groupUUID = obj.GroupID;
3750 colliding.Add(detobj);
3751 }
3752 }
3753
3754 if (colliding.Count > 0)
3755 {
3756 EndCollidingMessage.Colliders = colliding;
3757
3758 foreach (SceneObjectGroup att in Attachments)
3759 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
3760 }
3761 }
3762
3763 if (thisHitColliders.Count > 0)
3764 {
3765 ColliderArgs CollidingMessage = new ColliderArgs();
3766 List<DetectedObject> colliding = new List<DetectedObject>();
3767 foreach (uint localId in thisHitColliders)
3768 {
3769 if (localId == 0)
3770 continue;
3771
3772 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3773 string data = "";
3774 if (obj != null)
3775 {
3776 DetectedObject detobj = new DetectedObject();
3777 detobj.keyUUID = obj.UUID;
3778 detobj.nameStr = obj.Name;
3779 detobj.ownerUUID = obj.OwnerID;
3780 detobj.posVector = obj.AbsolutePosition;
3781 detobj.rotQuat = obj.GetWorldRotation();
3782 detobj.velVector = obj.Velocity;
3783 detobj.colliderType = 0;
3784 detobj.groupUUID = obj.GroupID;
3785 colliding.Add(detobj);
3786 }
3787 }
3788
3789 if (colliding.Count > 0)
3790 {
3791 CollidingMessage.Colliders = colliding;
3792
3793 lock (m_attachments)
3794 {
3795 foreach (SceneObjectGroup att in m_attachments)
3796 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
3797 }
3798 }
3799 }
3800
3304 if (m_invulnerable) 3801 if (m_invulnerable)
3305 return; 3802 return;
3306 3803
@@ -3475,7 +3972,10 @@ namespace OpenSim.Region.Framework.Scenes
3475 m_scene = scene; 3972 m_scene = scene;
3476 3973
3477 RegisterToEvents(); 3974 RegisterToEvents();
3478 3975 if (m_controllingClient != null)
3976 {
3977 m_controllingClient.ProcessPendingPackets();
3978 }
3479 /* 3979 /*
3480 AbsolutePosition = client.StartPos; 3980 AbsolutePosition = client.StartPos;
3481 3981
@@ -3705,6 +4205,39 @@ namespace OpenSim.Region.Framework.Scenes
3705 return; 4205 return;
3706 } 4206 }
3707 4207
4208 XmlDocument doc = new XmlDocument();
4209 string stateData = String.Empty;
4210
4211 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
4212 if (attServ != null)
4213 {
4214 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
4215 stateData = attServ.Get(ControllingClient.AgentId.ToString());
4216 if (stateData != String.Empty)
4217 {
4218 try
4219 {
4220 doc.LoadXml(stateData);
4221 }
4222 catch { }
4223 }
4224 }
4225
4226 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
4227
4228 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
4229 if (nodes.Count > 0)
4230 {
4231 foreach (XmlNode n in nodes)
4232 {
4233 XmlElement elem = (XmlElement)n;
4234 string itemID = elem.GetAttribute("ItemID");
4235 string xml = elem.InnerXml;
4236
4237 itemData[new UUID(itemID)] = xml;
4238 }
4239 }
4240
3708 List<int> attPoints = m_appearance.GetAttachedPoints(); 4241 List<int> attPoints = m_appearance.GetAttachedPoints();
3709 foreach (int p in attPoints) 4242 foreach (int p in attPoints)
3710 { 4243 {
@@ -3724,9 +4257,26 @@ namespace OpenSim.Region.Framework.Scenes
3724 4257
3725 try 4258 try
3726 { 4259 {
3727 // Rez from inventory 4260 string xmlData;
3728 UUID asset 4261 XmlDocument d = new XmlDocument();
3729 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p); 4262 UUID asset;
4263 if (itemData.TryGetValue(itemID, out xmlData))
4264 {
4265 d.LoadXml(xmlData);
4266 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID);
4267
4268 // Rez from inventory
4269 asset
4270 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d);
4271
4272 }
4273 else
4274 {
4275 // Rez from inventory (with a null doc to let
4276 // CHANGED_OWNER happen)
4277 asset
4278 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, null);
4279 }
3730 4280
3731 m_log.InfoFormat( 4281 m_log.InfoFormat(
3732 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})", 4282 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})",
@@ -3763,5 +4313,16 @@ namespace OpenSim.Region.Framework.Scenes
3763 m_reprioritization_called = false; 4313 m_reprioritization_called = false;
3764 } 4314 }
3765 } 4315 }
4316
4317 private Vector3 Quat2Euler(Quaternion rot){
4318 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4319 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4320 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4321 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4322 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4323 return(new Vector3(x,y,z));
4324 }
4325
4326
3766 } 4327 }
3767} 4328}