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.cs977
1 files changed, 789 insertions, 188 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 46234f9..557fc42 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[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes(); 79// private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes();
@@ -87,7 +88,9 @@ namespace OpenSim.Region.Framework.Scenes
87 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 88 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
88 /// issue #1716 89 /// issue #1716
89 /// </summary> 90 /// </summary>
90 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 91// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
92 // Value revised by KF 091121 by comparison with SL.
93 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f);
91 94
92 public UUID currentParcelUUID = UUID.Zero; 95 public UUID currentParcelUUID = UUID.Zero;
93 96
@@ -121,8 +124,11 @@ namespace OpenSim.Region.Framework.Scenes
121 public Vector3 lastKnownAllowedPosition; 124 public Vector3 lastKnownAllowedPosition;
122 public bool sentMessageAboutRestrictedParcelFlyingDown; 125 public bool sentMessageAboutRestrictedParcelFlyingDown;
123 public Vector4 CollisionPlane = Vector4.UnitW; 126 public Vector4 CollisionPlane = Vector4.UnitW;
124 127
128 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
129 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
125 private Vector3 m_lastPosition; 130 private Vector3 m_lastPosition;
131 private Vector3 m_lastWorldPosition;
126 private Quaternion m_lastRotation; 132 private Quaternion m_lastRotation;
127 private Vector3 m_lastVelocity; 133 private Vector3 m_lastVelocity;
128 //private int m_lastTerseSent; 134 //private int m_lastTerseSent;
@@ -153,9 +159,10 @@ namespace OpenSim.Region.Framework.Scenes
153 private int m_perfMonMS; 159 private int m_perfMonMS;
154 160
155 private bool m_setAlwaysRun; 161 private bool m_setAlwaysRun;
156
157 private bool m_forceFly; 162 private bool m_forceFly;
158 private bool m_flyDisabled; 163 private bool m_flyDisabled;
164 private bool m_flyingOld; // add for fly velocity control
165 public bool m_wasFlying; // add for fly velocity control
159 166
160 private float m_speedModifier = 1.0f; 167 private float m_speedModifier = 1.0f;
161 168
@@ -174,7 +181,8 @@ namespace OpenSim.Region.Framework.Scenes
174 protected RegionInfo m_regionInfo; 181 protected RegionInfo m_regionInfo;
175 protected ulong crossingFromRegion; 182 protected ulong crossingFromRegion;
176 183
177 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 184 private readonly Vector3[] Dir_Vectors = new Vector3[11];
185 private bool m_isNudging = false;
178 186
179 // Position of agent's camera in world (region cordinates) 187 // Position of agent's camera in world (region cordinates)
180 protected Vector3 m_CameraCenter; 188 protected Vector3 m_CameraCenter;
@@ -199,17 +207,25 @@ namespace OpenSim.Region.Framework.Scenes
199 private bool m_autopilotMoving; 207 private bool m_autopilotMoving;
200 private Vector3 m_autoPilotTarget; 208 private Vector3 m_autoPilotTarget;
201 private bool m_sitAtAutoTarget; 209 private bool m_sitAtAutoTarget;
210 private Vector3 m_initialSitTarget = Vector3.Zero; //KF: First estimate of where to sit
202 211
203 private string m_nextSitAnimation = String.Empty; 212 private string m_nextSitAnimation = String.Empty;
204 213
205 //PauPaw:Proper PID Controler for autopilot************ 214 //PauPaw:Proper PID Controler for autopilot************
206 private bool m_moveToPositionInProgress; 215 private bool m_moveToPositionInProgress;
207 private Vector3 m_moveToPositionTarget; 216 private Vector3 m_moveToPositionTarget;
217 private Quaternion m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
208 218
209 private bool m_followCamAuto; 219 private bool m_followCamAuto;
210 220
211 private int m_movementUpdateCount; 221 private int m_movementUpdateCount;
222 private int m_lastColCount = -1; //KF: Look for Collision chnages
223 private int m_updateCount = 0; //KF: Update Anims for a while
224 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
212 private const int NumMovementsBetweenRayCast = 5; 225 private const int NumMovementsBetweenRayCast = 5;
226 private List<uint> m_lastColliders = new List<uint>();
227
228 private object m_syncRoot = new Object();
213 229
214 private bool CameraConstraintActive; 230 private bool CameraConstraintActive;
215 //private int m_moveToPositionStateStatus; 231 //private int m_moveToPositionStateStatus;
@@ -236,7 +252,9 @@ namespace OpenSim.Region.Framework.Scenes
236 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 252 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
237 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 253 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
238 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 254 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
239 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 255 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
256 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
257 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
240 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 258 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
241 } 259 }
242 260
@@ -443,7 +461,8 @@ namespace OpenSim.Region.Framework.Scenes
443 get 461 get
444 { 462 {
445 PhysicsActor actor = m_physicsActor; 463 PhysicsActor actor = m_physicsActor;
446 if (actor != null) 464// if (actor != null)
465 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting!
447 m_pos = actor.Position; 466 m_pos = actor.Position;
448 else 467 else
449 { 468 {
@@ -492,7 +511,8 @@ namespace OpenSim.Region.Framework.Scenes
492 } 511 }
493 } 512 }
494 513
495 m_pos = value; 514 if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting!
515 m_pos = value;
496 m_parentPosition = Vector3.Zero; 516 m_parentPosition = Vector3.Zero;
497 } 517 }
498 } 518 }
@@ -536,10 +556,39 @@ namespace OpenSim.Region.Framework.Scenes
536 } 556 }
537 } 557 }
538 558
559 public Quaternion OffsetRotation
560 {
561 get { return m_offsetRotation; }
562 set { m_offsetRotation = value; }
563 }
564
539 public Quaternion Rotation 565 public Quaternion Rotation
540 { 566 {
541 get { return m_bodyRot; } 567 get {
542 set { m_bodyRot = value; } 568 if (m_parentID != 0)
569 {
570 if (m_offsetRotation != null)
571 {
572 return m_offsetRotation;
573 }
574 else
575 {
576 return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
577 }
578
579 }
580 else
581 {
582 return m_bodyRot;
583 }
584 }
585 set {
586 m_bodyRot = value;
587 if (m_parentID != 0)
588 {
589 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
590 }
591 }
543 } 592 }
544 593
545 public Quaternion PreviousRotation 594 public Quaternion PreviousRotation
@@ -564,11 +613,21 @@ namespace OpenSim.Region.Framework.Scenes
564 613
565 private uint m_parentID; 614 private uint m_parentID;
566 615
616
617 private UUID m_linkedPrim;
618
567 public uint ParentID 619 public uint ParentID
568 { 620 {
569 get { return m_parentID; } 621 get { return m_parentID; }
570 set { m_parentID = value; } 622 set { m_parentID = value; }
571 } 623 }
624
625 public UUID LinkedPrim
626 {
627 get { return m_linkedPrim; }
628 set { m_linkedPrim = value; }
629 }
630
572 public float Health 631 public float Health
573 { 632 {
574 get { return m_health; } 633 get { return m_health; }
@@ -690,7 +749,7 @@ namespace OpenSim.Region.Framework.Scenes
690 CreateSceneViewer(); 749 CreateSceneViewer();
691 m_animator = new ScenePresenceAnimator(this); 750 m_animator = new ScenePresenceAnimator(this);
692 } 751 }
693 752
694 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() 753 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this()
695 { 754 {
696 m_rootRegionHandle = reginfo.RegionHandle; 755 m_rootRegionHandle = reginfo.RegionHandle;
@@ -722,10 +781,7 @@ namespace OpenSim.Region.Framework.Scenes
722 m_reprioritization_timer.AutoReset = false; 781 m_reprioritization_timer.AutoReset = false;
723 782
724 AdjustKnownSeeds(); 783 AdjustKnownSeeds();
725
726 // TODO: I think, this won't send anything, as we are still a child here...
727 Animator.TrySetMovementAnimation("STAND"); 784 Animator.TrySetMovementAnimation("STAND");
728
729 // we created a new ScenePresence (a new child agent) in a fresh region. 785 // we created a new ScenePresence (a new child agent) in a fresh region.
730 // Request info about all the (root) agents in this region 786 // Request info about all the (root) agents in this region
731 // Note: This won't send data *to* other clients in that region (children don't send) 787 // Note: This won't send data *to* other clients in that region (children don't send)
@@ -776,25 +832,47 @@ namespace OpenSim.Region.Framework.Scenes
776 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 832 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
777 Dir_Vectors[4] = Vector3.UnitZ; //UP 833 Dir_Vectors[4] = Vector3.UnitZ; //UP
778 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 834 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
779 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 835 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
780 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 836 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
781 Dir_Vectors[7] = -Vector3.UnitX; //BACK 837 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
838 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
839 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
782 } 840 }
783 841
784 private Vector3[] GetWalkDirectionVectors() 842 private Vector3[] GetWalkDirectionVectors()
785 { 843 {
786 Vector3[] vector = new Vector3[9]; 844 Vector3[] vector = new Vector3[11];
787 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 845 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
788 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 846 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
789 vector[2] = Vector3.UnitY; //LEFT 847 vector[2] = Vector3.UnitY; //LEFT
790 vector[3] = -Vector3.UnitY; //RIGHT 848 vector[3] = -Vector3.UnitY; //RIGHT
791 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 849 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
792 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 850 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
793 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 851 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
794 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 852 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
795 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 853 vector[8] = Vector3.UnitY; //LEFT_NUDGE
854 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
855 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
796 return vector; 856 return vector;
797 } 857 }
858
859 private bool[] GetDirectionIsNudge()
860 {
861 bool[] isNudge = new bool[11];
862 isNudge[0] = false; //FORWARD
863 isNudge[1] = false; //BACK
864 isNudge[2] = false; //LEFT
865 isNudge[3] = false; //RIGHT
866 isNudge[4] = false; //UP
867 isNudge[5] = false; //DOWN
868 isNudge[6] = true; //FORWARD_NUDGE
869 isNudge[7] = true; //BACK_NUDGE
870 isNudge[8] = true; //LEFT_NUDGE
871 isNudge[9] = true; //RIGHT_NUDGE
872 isNudge[10] = true; //DOWN_Nudge
873 return isNudge;
874 }
875
798 876
799 #endregion 877 #endregion
800 878
@@ -856,6 +934,54 @@ namespace OpenSim.Region.Framework.Scenes
856 pos.Y = crossedBorder.BorderLine.Z - 1; 934 pos.Y = crossedBorder.BorderLine.Z - 1;
857 } 935 }
858 936
937 //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet.
938 //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent,
939 //they'll bypass the landing point. But I can't think of any decent way of fixing this.
940 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
941 if (land != null)
942 {
943 if (KnownChildRegionHandles.Count == 0)
944 {
945 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
946 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)
947 {
948 pos = land.LandData.UserLocation;
949 }
950 }
951
952 land.SendLandUpdateToClient(ControllingClient);
953 }
954
955 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0)
956 {
957 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128);
958
959 if (pos.X < 0)
960 {
961 emergencyPos.X = (int)Constants.RegionSize + pos.X;
962 if (!(pos.Y < 0))
963 emergencyPos.Y = pos.Y;
964 if (!(pos.Z < 0))
965 emergencyPos.Z = pos.Z;
966 }
967 if (pos.Y < 0)
968 {
969 emergencyPos.Y = (int)Constants.RegionSize + pos.Y;
970 if (!(pos.X < 0))
971 emergencyPos.X = pos.X;
972 if (!(pos.Z < 0))
973 emergencyPos.Z = pos.Z;
974 }
975 if (pos.Z < 0)
976 {
977 emergencyPos.Z = 128;
978 if (!(pos.Y < 0))
979 emergencyPos.Y = pos.Y;
980 if (!(pos.X < 0))
981 emergencyPos.X = pos.X;
982 }
983 }
984
859 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 985 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
860 { 986 {
861 m_log.WarnFormat( 987 m_log.WarnFormat(
@@ -984,12 +1110,17 @@ namespace OpenSim.Region.Framework.Scenes
984 { 1110 {
985 if (PhysicsActor != null) 1111 if (PhysicsActor != null)
986 { 1112 {
987 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1113 try
988 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall; 1114 {
989 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); 1115 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
990 m_physicsActor.UnSubscribeEvents(); 1116 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall;
991 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1117 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
992 PhysicsActor = null; 1118 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1119 m_physicsActor.UnSubscribeEvents();
1120 PhysicsActor = null;
1121 }
1122 catch
1123 { }
993 } 1124 }
994 } 1125 }
995 1126
@@ -1000,9 +1131,10 @@ namespace OpenSim.Region.Framework.Scenes
1000 public void Teleport(Vector3 pos) 1131 public void Teleport(Vector3 pos)
1001 { 1132 {
1002 bool isFlying = false; 1133 bool isFlying = false;
1134
1003 if (m_physicsActor != null) 1135 if (m_physicsActor != null)
1004 isFlying = m_physicsActor.Flying; 1136 isFlying = m_physicsActor.Flying;
1005 1137
1006 RemoveFromPhysicalScene(); 1138 RemoveFromPhysicalScene();
1007 Velocity = Vector3.Zero; 1139 Velocity = Vector3.Zero;
1008 AbsolutePosition = pos; 1140 AbsolutePosition = pos;
@@ -1014,6 +1146,7 @@ namespace OpenSim.Region.Framework.Scenes
1014 } 1146 }
1015 1147
1016 SendTerseUpdateToAllClients(); 1148 SendTerseUpdateToAllClients();
1149
1017 } 1150 }
1018 1151
1019 public void TeleportWithMomentum(Vector3 pos) 1152 public void TeleportWithMomentum(Vector3 pos)
@@ -1232,6 +1365,7 @@ namespace OpenSim.Region.Framework.Scenes
1232 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); 1365 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902");
1233 1366
1234 m_pos = m_LastFinitePos; 1367 m_pos = m_LastFinitePos;
1368
1235 if (!m_pos.IsFinite()) 1369 if (!m_pos.IsFinite())
1236 { 1370 {
1237 m_pos.X = 127f; 1371 m_pos.X = 127f;
@@ -1298,7 +1432,6 @@ namespace OpenSim.Region.Framework.Scenes
1298 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1432 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1299 } 1433 }
1300 } 1434 }
1301
1302 lock (scriptedcontrols) 1435 lock (scriptedcontrols)
1303 { 1436 {
1304 if (scriptedcontrols.Count > 0) 1437 if (scriptedcontrols.Count > 0)
@@ -1313,6 +1446,9 @@ namespace OpenSim.Region.Framework.Scenes
1313 1446
1314 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1447 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1315 { 1448 {
1449 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1450 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1451
1316 // TODO: This doesn't prevent the user from walking yet. 1452 // TODO: This doesn't prevent the user from walking yet.
1317 // Setting parent ID would fix this, if we knew what value 1453 // Setting parent ID would fix this, if we knew what value
1318 // to use. Or we could add a m_isSitting variable. 1454 // to use. Or we could add a m_isSitting variable.
@@ -1361,12 +1497,20 @@ namespace OpenSim.Region.Framework.Scenes
1361 if (actor.Flying != oldflying) 1497 if (actor.Flying != oldflying)
1362 update_movementflag = true; 1498 update_movementflag = true;
1363 1499
1500 if (m_animator.m_jumping) // add for jumping
1501 update_movementflag = true;
1502
1364 if (q != m_bodyRot) 1503 if (q != m_bodyRot)
1365 { 1504 {
1366 m_bodyRot = q; 1505 m_bodyRot = q;
1367 update_rotation = true; 1506 update_rotation = true;
1368 } 1507 }
1369 1508
1509 //guilty until proven innocent..
1510 bool Nudging = true;
1511 //Basically, if there is at least one non-nudge control then we don't need
1512 //to worry about stopping the avatar
1513
1370 if (m_parentID == 0) 1514 if (m_parentID == 0)
1371 { 1515 {
1372 bool bAllowUpdateMoveToPosition = false; 1516 bool bAllowUpdateMoveToPosition = false;
@@ -1381,9 +1525,12 @@ namespace OpenSim.Region.Framework.Scenes
1381 else 1525 else
1382 dirVectors = Dir_Vectors; 1526 dirVectors = Dir_Vectors;
1383 1527
1384 // The fact that m_movementflag is a byte needs to be fixed 1528 bool[] isNudge = GetDirectionIsNudge();
1385 // it really should be a uint 1529
1386 uint nudgehack = 250; 1530
1531
1532
1533
1387 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1534 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1388 { 1535 {
1389 if (((uint)flags & (uint)DCF) != 0) 1536 if (((uint)flags & (uint)DCF) != 0)
@@ -1393,40 +1540,28 @@ namespace OpenSim.Region.Framework.Scenes
1393 try 1540 try
1394 { 1541 {
1395 agent_control_v3 += dirVectors[i]; 1542 agent_control_v3 += dirVectors[i];
1396 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1543 if (isNudge[i] == false)
1544 {
1545 Nudging = false;
1546 }
1397 } 1547 }
1398 catch (IndexOutOfRangeException) 1548 catch (IndexOutOfRangeException)
1399 { 1549 {
1400 // Why did I get this? 1550 // Why did I get this?
1401 } 1551 }
1402 1552
1403 if ((m_movementflag & (byte)(uint)DCF) == 0) 1553 if ((m_movementflag & (uint)DCF) == 0)
1404 { 1554 {
1405 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1406 {
1407 m_movementflag |= (byte)nudgehack;
1408 }
1409 m_movementflag += (byte)(uint)DCF; 1555 m_movementflag += (byte)(uint)DCF;
1410 update_movementflag = true; 1556 update_movementflag = true;
1411 } 1557 }
1412 } 1558 }
1413 else 1559 else
1414 { 1560 {
1415 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1561 if ((m_movementflag & (uint)DCF) != 0)
1416 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1417 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1418 ) // This or is for Nudge forward
1419 { 1562 {
1420 m_movementflag -= ((byte)(uint)DCF); 1563 m_movementflag -= (byte)(uint)DCF;
1421
1422 update_movementflag = true; 1564 update_movementflag = true;
1423 /*
1424 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1425 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1426 {
1427 m_log.Debug("Removed Hack flag");
1428 }
1429 */
1430 } 1565 }
1431 else 1566 else
1432 { 1567 {
@@ -1435,7 +1570,6 @@ namespace OpenSim.Region.Framework.Scenes
1435 } 1570 }
1436 i++; 1571 i++;
1437 } 1572 }
1438
1439 //Paupaw:Do Proper PID for Autopilot here 1573 //Paupaw:Do Proper PID for Autopilot here
1440 if (bResetMoveToPosition) 1574 if (bResetMoveToPosition)
1441 { 1575 {
@@ -1470,6 +1604,9 @@ namespace OpenSim.Region.Framework.Scenes
1470 // Ignore z component of vector 1604 // Ignore z component of vector
1471 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1605 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1472 LocalVectorToTarget2D.Normalize(); 1606 LocalVectorToTarget2D.Normalize();
1607
1608 //We're not nudging
1609 Nudging = false;
1473 agent_control_v3 += LocalVectorToTarget2D; 1610 agent_control_v3 += LocalVectorToTarget2D;
1474 1611
1475 // update avatar movement flags. the avatar coordinate system is as follows: 1612 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1560,13 +1697,13 @@ namespace OpenSim.Region.Framework.Scenes
1560 // m_log.DebugFormat( 1697 // m_log.DebugFormat(
1561 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1698 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1562 1699
1563 AddNewMovement(agent_control_v3, q); 1700 AddNewMovement(agent_control_v3, q, Nudging);
1564 1701
1565 1702
1566 } 1703 }
1567 } 1704 }
1568 1705
1569 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1706 if (update_movementflag && !SitGround)
1570 Animator.UpdateMovementAnimations(); 1707 Animator.UpdateMovementAnimations();
1571 1708
1572 m_scene.EventManager.TriggerOnClientMovement(this); 1709 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1581,7 +1718,6 @@ namespace OpenSim.Region.Framework.Scenes
1581 m_sitAtAutoTarget = false; 1718 m_sitAtAutoTarget = false;
1582 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1719 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1583 //proxy.PCode = (byte)PCode.ParticleSystem; 1720 //proxy.PCode = (byte)PCode.ParticleSystem;
1584
1585 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1721 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1586 proxyObjectGroup.AttachToScene(m_scene); 1722 proxyObjectGroup.AttachToScene(m_scene);
1587 1723
@@ -1623,7 +1759,7 @@ namespace OpenSim.Region.Framework.Scenes
1623 } 1759 }
1624 m_moveToPositionInProgress = true; 1760 m_moveToPositionInProgress = true;
1625 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1761 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1626 } 1762 }
1627 catch (Exception ex) 1763 catch (Exception ex)
1628 { 1764 {
1629 //Why did I get this error? 1765 //Why did I get this error?
@@ -1645,7 +1781,7 @@ namespace OpenSim.Region.Framework.Scenes
1645 Velocity = Vector3.Zero; 1781 Velocity = Vector3.Zero;
1646 SendAvatarDataToAllAgents(); 1782 SendAvatarDataToAllAgents();
1647 1783
1648 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1784 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1649 } 1785 }
1650 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1786 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1651 m_requestedSitTargetUUID = UUID.Zero; 1787 m_requestedSitTargetUUID = UUID.Zero;
@@ -1682,25 +1818,22 @@ namespace OpenSim.Region.Framework.Scenes
1682 1818
1683 if (m_parentID != 0) 1819 if (m_parentID != 0)
1684 { 1820 {
1685 m_log.Debug("StandupCode Executed"); 1821 SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID);
1686 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1687 if (part != null) 1822 if (part != null)
1688 { 1823 {
1824 part.TaskInventory.LockItemsForRead(true);
1689 TaskInventoryDictionary taskIDict = part.TaskInventory; 1825 TaskInventoryDictionary taskIDict = part.TaskInventory;
1690 if (taskIDict != null) 1826 if (taskIDict != null)
1691 { 1827 {
1692 lock (taskIDict) 1828 foreach (UUID taskID in taskIDict.Keys)
1693 { 1829 {
1694 foreach (UUID taskID in taskIDict.Keys) 1830 UnRegisterControlEventsToScript(LocalId, taskID);
1695 { 1831 taskIDict[taskID].PermsMask &= ~(
1696 UnRegisterControlEventsToScript(LocalId, taskID); 1832 2048 | //PERMISSION_CONTROL_CAMERA
1697 taskIDict[taskID].PermsMask &= ~( 1833 4); // PERMISSION_TAKE_CONTROLS
1698 2048 | //PERMISSION_CONTROL_CAMERA
1699 4); // PERMISSION_TAKE_CONTROLS
1700 }
1701 } 1834 }
1702
1703 } 1835 }
1836 part.TaskInventory.LockItemsForRead(false);
1704 // Reset sit target. 1837 // Reset sit target.
1705 if (part.GetAvatarOnSitTarget() == UUID) 1838 if (part.GetAvatarOnSitTarget() == UUID)
1706 part.SitTargetAvatar = UUID.Zero; 1839 part.SitTargetAvatar = UUID.Zero;
@@ -1709,16 +1842,55 @@ namespace OpenSim.Region.Framework.Scenes
1709 m_parentPosition = part.GetWorldPosition(); 1842 m_parentPosition = part.GetWorldPosition();
1710 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1843 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1711 } 1844 }
1845 // part.GetWorldRotation() is the rotation of the object being sat on
1846 // Rotation is the sittiing Av's rotation
1847
1848 Quaternion partRot;
1849// if (part.LinkNum == 1)
1850// { // Root prim of linkset
1851// partRot = part.ParentGroup.RootPart.RotationOffset;
1852// }
1853// else
1854// { // single or child prim
1855
1856// }
1857 if (part == null) //CW: Part may be gone. llDie() for example.
1858 {
1859 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1860 }
1861 else
1862 {
1863 partRot = part.GetWorldRotation();
1864 }
1865
1866 Quaternion partIRot = Quaternion.Inverse(partRot);
1712 1867
1868 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1869 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1870
1871
1713 if (m_physicsActor == null) 1872 if (m_physicsActor == null)
1714 { 1873 {
1715 AddToPhysicalScene(false); 1874 AddToPhysicalScene(false);
1716 } 1875 }
1717 1876 //CW: If the part isn't null then we can set the current position
1718 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1877 if (part != null)
1719 m_parentPosition = Vector3.Zero; 1878 {
1720 1879 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + ((m_pos - part.OffsetPosition) * partRot); // + av sit offset!
1721 m_parentID = 0; 1880 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1881 part.IsOccupied = false;
1882 part.ParentGroup.DeleteAvatar(ControllingClient.AgentId);
1883 }
1884 else
1885 {
1886 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1887 AbsolutePosition = m_lastWorldPosition;
1888 }
1889
1890 m_parentPosition = Vector3.Zero;
1891 m_parentID = 0;
1892 m_linkedPrim = UUID.Zero;
1893 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1722 SendAvatarDataToAllAgents(); 1894 SendAvatarDataToAllAgents();
1723 m_requestedSitTargetID = 0; 1895 m_requestedSitTargetID = 0;
1724 if (m_physicsActor != null && m_appearance != null) 1896 if (m_physicsActor != null && m_appearance != null)
@@ -1727,7 +1899,6 @@ namespace OpenSim.Region.Framework.Scenes
1727 SetHeight(m_appearance.AvatarHeight); 1899 SetHeight(m_appearance.AvatarHeight);
1728 } 1900 }
1729 } 1901 }
1730
1731 Animator.TrySetMovementAnimation("STAND"); 1902 Animator.TrySetMovementAnimation("STAND");
1732 } 1903 }
1733 1904
@@ -1758,13 +1929,9 @@ namespace OpenSim.Region.Framework.Scenes
1758 Vector3 avSitOffSet = part.SitTargetPosition; 1929 Vector3 avSitOffSet = part.SitTargetPosition;
1759 Quaternion avSitOrientation = part.SitTargetOrientation; 1930 Quaternion avSitOrientation = part.SitTargetOrientation;
1760 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1931 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1761 1932 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1762 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1933 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1763 bool SitTargetisSet = 1934 if (SitTargetisSet && !SitTargetOccupied)
1764 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1765 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1766
1767 if (SitTargetisSet && SitTargetUnOccupied)
1768 { 1935 {
1769 //switch the target to this prim 1936 //switch the target to this prim
1770 return part; 1937 return part;
@@ -1778,85 +1945,167 @@ namespace OpenSim.Region.Framework.Scenes
1778 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1945 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1779 { 1946 {
1780 bool autopilot = true; 1947 bool autopilot = true;
1948 Vector3 autopilotTarget = new Vector3();
1949 Quaternion sitOrientation = Quaternion.Identity;
1781 Vector3 pos = new Vector3(); 1950 Vector3 pos = new Vector3();
1782 Quaternion sitOrientation = pSitOrientation;
1783 Vector3 cameraEyeOffset = Vector3.Zero; 1951 Vector3 cameraEyeOffset = Vector3.Zero;
1784 Vector3 cameraAtOffset = Vector3.Zero; 1952 Vector3 cameraAtOffset = Vector3.Zero;
1785 bool forceMouselook = false; 1953 bool forceMouselook = false;
1786 1954
1787 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1955 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1788 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1956 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1789 if (part != null) 1957 if (part == null) return;
1790 { 1958
1791 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1959 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1792 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1960 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1793 1961
1794 // Is a sit target available? 1962 // part is the prim to sit on
1795 Vector3 avSitOffSet = part.SitTargetPosition; 1963 // offset is the world-ref vector distance from that prim center to the click-spot
1796 Quaternion avSitOrientation = part.SitTargetOrientation; 1964 // UUID is the UUID of the Avatar doing the clicking
1797 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1965
1798 1966 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1799 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1967
1800 bool SitTargetisSet = 1968 // Is a sit target available?
1801 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1969 Vector3 avSitOffSet = part.SitTargetPosition;
1802 ( 1970 Quaternion avSitOrientation = part.SitTargetOrientation;
1803 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1971
1804 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1972 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1805 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1973 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1806 ) 1974 Quaternion partRot;
1807 )); 1975// if (part.LinkNum == 1)
1808 1976// { // Root prim of linkset
1809 if (SitTargetisSet && SitTargetUnOccupied) 1977// partRot = part.ParentGroup.RootPart.RotationOffset;
1810 { 1978// }
1811 part.SitTargetAvatar = UUID; 1979// else
1812 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1980// { // single or child prim
1813 sitOrientation = avSitOrientation; 1981 partRot = part.GetWorldRotation();
1814 autopilot = false; 1982// }
1815 } 1983 Quaternion partIRot = Quaternion.Inverse(partRot);
1816 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 1984//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1817 1985 // Sit analysis rewritten by KF 091125
1818 pos = part.AbsolutePosition + offset; 1986 if (SitTargetisSet) // scipted sit
1819 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1987 {
1820 //{ 1988 if (!part.IsOccupied)
1821 // offset = pos; 1989 {
1822 //autopilot = false; 1990//Console.WriteLine("Scripted, unoccupied");
1823 //} 1991 part.SitTargetAvatar = UUID; // set that Av will be on it
1824 if (m_physicsActor != null) 1992 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1825 { 1993
1826 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1994 Quaternion nrot = avSitOrientation;
1827 // We can remove the physicsActor until they stand up. 1995 if (!part.IsRoot)
1828 m_sitAvatarHeight = m_physicsActor.Size.Z;
1829
1830 if (autopilot)
1831 { 1996 {
1832 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1997 nrot = part.RotationOffset * avSitOrientation;
1833 {
1834 autopilot = false;
1835
1836 RemoveFromPhysicalScene();
1837 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
1838 }
1839 } 1998 }
1840 else 1999 sitOrientation = nrot; // Change rotatione to the scripted one
2000 OffsetRotation = nrot;
2001 autopilot = false; // Jump direct to scripted llSitPos()
2002 }
2003 else
2004 {
2005//Console.WriteLine("Scripted, occupied");
2006 return;
2007 }
2008 }
2009 else // Not Scripted
2010 {
2011 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
2012 {
2013 // large prim & offset, ignore if other Avs sitting
2014// offset.Z -= 0.05f;
2015 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
2016 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
2017
2018//Console.WriteLine(" offset ={0}", offset);
2019//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
2020//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
2021
2022 }
2023 else // small offset
2024 {
2025//Console.WriteLine("Small offset");
2026 if (!part.IsOccupied)
2027 {
2028 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
2029 autopilotTarget = part.AbsolutePosition;
2030//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget);
2031 }
2032 else return; // occupied small
2033 } // end large/small
2034 } // end Scripted/not
2035
2036 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2037
2038 cameraAtOffset = part.GetCameraAtOffset();
2039 cameraEyeOffset = part.GetCameraEyeOffset();
2040 forceMouselook = part.GetForceMouselook();
2041 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
2042 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
2043
2044 if (m_physicsActor != null)
2045 {
2046 // If we're not using the client autopilot, we're immediately warping the avatar to the location
2047 // We can remove the physicsActor until they stand up.
2048 m_sitAvatarHeight = m_physicsActor.Size.Z;
2049 if (autopilot)
2050 { // its not a scripted sit
2051// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
2052 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 256.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 256.0f) )
1841 { 2053 {
2054 autopilot = false; // close enough
2055 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2056 Not using the part's position because returning the AV to the last known standing
2057 position is likely to be more friendly, isn't it? */
1842 RemoveFromPhysicalScene(); 2058 RemoveFromPhysicalScene();
1843 } 2059 Velocity = Vector3.Zero;
2060 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
2061 } // else the autopilot will get us close
2062 }
2063 else
2064 { // its a scripted sit
2065 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2066 I *am* using the part's position this time because we have no real idea how far away
2067 the avatar is from the sit target. */
2068 RemoveFromPhysicalScene();
2069 Velocity = Vector3.Zero;
1844 } 2070 }
1845
1846 cameraAtOffset = part.GetCameraAtOffset();
1847 cameraEyeOffset = part.GetCameraEyeOffset();
1848 forceMouselook = part.GetForceMouselook();
1849 } 2071 }
1850 2072 else return; // physactor is null!
1851 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 2073
1852 m_requestedSitTargetUUID = targetID; 2074 Vector3 offsetr; // = offset * partIRot;
2075 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
2076 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
2077 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
2078 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
2079 //offsetr = offset * partIRot;
2080//
2081 // else
2082 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
2083 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
2084 // (offset * partRot);
2085 // }
2086
2087//Console.WriteLine(" ");
2088//Console.WriteLine("link number ={0}", part.LinkNum);
2089//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
2090//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
2091//Console.WriteLine("Click offst ={0}", offset);
2092//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
2093//Console.WriteLine("offsetr ={0}", offsetr);
2094//Console.WriteLine("Camera At ={0}", cameraAtOffset);
2095//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
2096
2097 //NOTE: SendSitResponse should be relative to the GROUP *NOT* THE PRIM if we're sitting on a child
2098 ControllingClient.SendSitResponse(part.ParentGroup.UUID, ((offset * part.RotationOffset) + part.OffsetPosition), sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
2099
2100 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1853 // This calls HandleAgentSit twice, once from here, and the client calls 2101 // This calls HandleAgentSit twice, once from here, and the client calls
1854 // HandleAgentSit itself after it gets to the location 2102 // HandleAgentSit itself after it gets to the location
1855 // It doesn't get to the location until we've moved them there though 2103 // It doesn't get to the location until we've moved them there though
1856 // which happens in HandleAgentSit :P 2104 // which happens in HandleAgentSit :P
1857 m_autopilotMoving = autopilot; 2105 m_autopilotMoving = autopilot;
1858 m_autoPilotTarget = pos; 2106 m_autoPilotTarget = autopilotTarget;
1859 m_sitAtAutoTarget = autopilot; 2107 m_sitAtAutoTarget = autopilot;
2108 m_initialSitTarget = autopilotTarget;
1860 if (!autopilot) 2109 if (!autopilot)
1861 HandleAgentSit(remoteClient, UUID); 2110 HandleAgentSit(remoteClient, UUID);
1862 } 2111 }
@@ -2151,47 +2400,130 @@ namespace OpenSim.Region.Framework.Scenes
2151 { 2400 {
2152 if (part != null) 2401 if (part != null)
2153 { 2402 {
2403//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2154 if (part.GetAvatarOnSitTarget() == UUID) 2404 if (part.GetAvatarOnSitTarget() == UUID)
2155 { 2405 {
2406//Console.WriteLine("Scripted Sit");
2407 // Scripted sit
2156 Vector3 sitTargetPos = part.SitTargetPosition; 2408 Vector3 sitTargetPos = part.SitTargetPosition;
2157 Quaternion sitTargetOrient = part.SitTargetOrientation; 2409 Quaternion sitTargetOrient = part.SitTargetOrientation;
2158
2159 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2160 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2161
2162 //Quaternion result = (sitTargetOrient * vq) * nq;
2163
2164 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2410 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2165 m_pos += SIT_TARGET_ADJUSTMENT; 2411 m_pos += SIT_TARGET_ADJUSTMENT;
2412 if (!part.IsRoot)
2413 {
2414 m_pos *= part.RotationOffset;
2415 }
2166 m_bodyRot = sitTargetOrient; 2416 m_bodyRot = sitTargetOrient;
2167 //Rotation = sitTargetOrient;
2168 m_parentPosition = part.AbsolutePosition; 2417 m_parentPosition = part.AbsolutePosition;
2169 2418 part.IsOccupied = true;
2170 //SendTerseUpdateToAllClients(); 2419 part.ParentGroup.AddAvatar(agentID);
2171 } 2420 }
2172 else 2421 else
2173 { 2422 {
2174 m_pos -= part.AbsolutePosition; 2423 // if m_avUnscriptedSitPos is zero then Av sits above center
2424 // Else Av sits at m_avUnscriptedSitPos
2425
2426 // Non-scripted sit by Kitto Flora 21Nov09
2427 // Calculate angle of line from prim to Av
2428 Quaternion partIRot;
2429// if (part.LinkNum == 1)
2430// { // Root prim of linkset
2431// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2432// }
2433// else
2434// { // single or child prim
2435 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2436// }
2437 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2438 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2439 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2440 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2441 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2442 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2443 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2444 // Av sits at world euler <0,0, z>, translated by part rotation
2445 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2446
2175 m_parentPosition = part.AbsolutePosition; 2447 m_parentPosition = part.AbsolutePosition;
2176 } 2448 part.IsOccupied = true;
2449 part.ParentGroup.AddAvatar(agentID);
2450 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2451 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2452 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2453 m_avUnscriptedSitPos; // adds click offset, if any
2454 //Set up raytrace to find top surface of prim
2455 Vector3 size = part.Scale;
2456 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2457 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2458 Vector3 down = new Vector3(0f, 0f, -1f);
2459//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2460 m_scene.PhysicsScene.RaycastWorld(
2461 start, // Vector3 position,
2462 down, // Vector3 direction,
2463 mag, // float length,
2464 SitAltitudeCallback); // retMethod
2465 } // end scripted/not
2177 } 2466 }
2178 else 2467 else // no Av
2179 { 2468 {
2180 return; 2469 return;
2181 } 2470 }
2182 } 2471 }
2183 m_parentID = m_requestedSitTargetID;
2184 2472
2473 //We want our offsets to reference the root prim, not the child we may have sat on
2474 if (!part.IsRoot)
2475 {
2476 m_parentID = part.ParentGroup.RootPart.LocalId;
2477 m_pos += part.OffsetPosition;
2478 }
2479 else
2480 {
2481 m_parentID = m_requestedSitTargetID;
2482 }
2483
2484 m_linkedPrim = part.UUID;
2485 if (part.GetAvatarOnSitTarget() != UUID)
2486 {
2487 m_offsetRotation = m_offsetRotation / part.RotationOffset;
2488 }
2185 Velocity = Vector3.Zero; 2489 Velocity = Vector3.Zero;
2186 RemoveFromPhysicalScene(); 2490 RemoveFromPhysicalScene();
2187
2188 Animator.TrySetMovementAnimation(sitAnimation); 2491 Animator.TrySetMovementAnimation(sitAnimation);
2189 SendAvatarDataToAllAgents(); 2492 SendAvatarDataToAllAgents();
2190 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2191 // So we're also sending a terse update (which has avatar rotation)
2192 // [Update] We do now.
2193 //SendTerseUpdateToAllClients(); 2493 //SendTerseUpdateToAllClients();
2194 } 2494 }
2495
2496 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2497 {
2498 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2499 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2500 if(hitYN)
2501 {
2502 // m_pos = Av offset from prim center to make look like on center
2503 // m_parentPosition = Actual center pos of prim
2504 // collisionPoint = spot on prim where we want to sit
2505 // collisionPoint.Z = global sit surface height
2506 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2507 Quaternion partIRot;
2508// if (part.LinkNum == 1)
2509/// { // Root prim of linkset
2510// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2511// }
2512// else
2513// { // single or child prim
2514 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2515// }
2516 if (m_initialSitTarget != null)
2517 {
2518 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2519 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2520 //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2521 m_pos += offset;
2522 // ControllingClient.SendClearFollowCamProperties(part.UUID);
2523 }
2524
2525 }
2526 } // End SitAltitudeCallback KF.
2195 2527
2196 /// <summary> 2528 /// <summary>
2197 /// Event handler for the 'Always run' setting on the client 2529 /// Event handler for the 'Always run' setting on the client
@@ -2221,12 +2553,13 @@ namespace OpenSim.Region.Framework.Scenes
2221 /// </summary> 2553 /// </summary>
2222 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2554 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2223 /// <param name="rotation">The direction in which this avatar should now face. 2555 /// <param name="rotation">The direction in which this avatar should now face.
2224 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2556 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2225 { 2557 {
2226 if (m_isChildAgent) 2558 if (m_isChildAgent)
2227 { 2559 {
2228 // WHAT??? 2560 // WHAT???
2229 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!"); 2561 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent");
2562
2230 return; 2563 return;
2231 } 2564 }
2232 2565
@@ -2235,15 +2568,26 @@ namespace OpenSim.Region.Framework.Scenes
2235 Rotation = rotation; 2568 Rotation = rotation;
2236 Vector3 direc = vec * rotation; 2569 Vector3 direc = vec * rotation;
2237 direc.Normalize(); 2570 direc.Normalize();
2571 PhysicsActor actor = m_physicsActor;
2572
2573 if (actor.Flying != m_flyingOld) // add for fly velocity control
2574 {
2575 m_flyingOld = actor.Flying; // add for fly velocity control
2576 if (!actor.Flying) m_wasFlying = true; // add for fly velocity control
2577 }
2578
2579 if (m_physicsActor.IsColliding == true) m_wasFlying = false; // add for fly velocity control
2580
2581 if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up.
2238 2582
2239 direc *= 0.03f * 128f * m_speedModifier; 2583 direc *= 0.03f * 128f * m_speedModifier;
2240 2584
2241 PhysicsActor actor = m_physicsActor;
2242 if (actor != null) 2585 if (actor != null)
2243 { 2586 {
2244 if (actor.Flying) 2587 if (actor.Flying)
2245 { 2588 {
2246 direc *= 4.0f; 2589// rm speed mod direc *= 4.0f;
2590 direc *= 5.2f; // for speed mod
2247 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 2591 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
2248 //bool colliding = (m_physicsActor.IsColliding==true); 2592 //bool colliding = (m_physicsActor.IsColliding==true);
2249 //if (controlland) 2593 //if (controlland)
@@ -2256,22 +2600,34 @@ namespace OpenSim.Region.Framework.Scenes
2256 // m_log.Info("[AGENT]: Stop FLying"); 2600 // m_log.Info("[AGENT]: Stop FLying");
2257 //} 2601 //}
2258 } 2602 }
2603 if (Animator.m_falling && m_wasFlying) // if falling from flying, disable motion add
2604 {
2605 direc *= 0.0f;
2606 }
2607 /* This jumping section removed to SPA
2259 else if (!actor.Flying && actor.IsColliding) 2608 else if (!actor.Flying && actor.IsColliding)
2260 { 2609 {
2261 if (direc.Z > 2.0f) 2610 if (direc.Z > 2.0f)
2262 { 2611 {
2263 direc.Z *= 3.0f; 2612 if(m_animator.m_animTickJump == -1)
2264 2613 {
2265 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2614 direc.Z *= 3.0f; // jump
2266 Animator.TrySetMovementAnimation("PREJUMP"); 2615 }
2267 Animator.TrySetMovementAnimation("JUMP"); 2616 else
2617 {
2618 direc.Z *= 0.1f; // prejump
2619 }
2620 / * Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs
2621 Animator.TrySetMovementAnimation("PREJUMP");
2622 Animator.TrySetMovementAnimation("JUMP");
2623 * /
2268 } 2624 }
2269 } 2625 } */
2270 } 2626 }
2271 2627
2272 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2628 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2273 m_forceToApply = direc; 2629 m_forceToApply = direc;
2274 2630 m_isNudging = Nudging;
2275 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2631 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2276 } 2632 }
2277 2633
@@ -2320,6 +2676,9 @@ namespace OpenSim.Region.Framework.Scenes
2320 2676
2321 CheckForSignificantMovement(); // sends update to the modules. 2677 CheckForSignificantMovement(); // sends update to the modules.
2322 } 2678 }
2679
2680 //Sending prim updates AFTER the avatar terse updates are sent
2681 SendPrimUpdates();
2323 } 2682 }
2324 2683
2325 #endregion 2684 #endregion
@@ -3082,6 +3441,7 @@ namespace OpenSim.Region.Framework.Scenes
3082 m_callbackURI = cAgent.CallbackURI; 3441 m_callbackURI = cAgent.CallbackURI;
3083 3442
3084 m_pos = cAgent.Position; 3443 m_pos = cAgent.Position;
3444
3085 m_velocity = cAgent.Velocity; 3445 m_velocity = cAgent.Velocity;
3086 m_CameraCenter = cAgent.Center; 3446 m_CameraCenter = cAgent.Center;
3087 m_CameraAtAxis = cAgent.AtAxis; 3447 m_CameraAtAxis = cAgent.AtAxis;
@@ -3200,20 +3560,45 @@ namespace OpenSim.Region.Framework.Scenes
3200 /// </summary> 3560 /// </summary>
3201 public override void UpdateMovement() 3561 public override void UpdateMovement()
3202 { 3562 {
3203 if (m_forceToApply.HasValue) 3563 if (Animator!=null) // add for jumping
3204 { 3564 { // add for jumping
3205 Vector3 force = m_forceToApply.Value; 3565 // if (!m_animator.m_jumping) // add for jumping
3566 // { // add for jumping
3206 3567
3207 m_updateflag = true; 3568 if (m_forceToApply.HasValue) // this section realigned
3208 3569 {
3209 // The magic constant 0.95f seems to make walking feel less jerky,
3210 // probably because it hackishly accounts for the overall latency of
3211 // these Velocity updates -- Diva
3212 Velocity = force * .95F;
3213 3570
3214 m_forceToApply = null; 3571 Vector3 force = m_forceToApply.Value;
3215 } 3572 m_updateflag = true;
3216 } 3573if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3574 Velocity = force;
3575//Console.WriteLine("UM1 {0}", Velocity);
3576 m_forceToApply = null;
3577 }
3578 else
3579 {
3580 if (m_isNudging)
3581 {
3582 Vector3 force = Vector3.Zero;
3583
3584 m_updateflag = true;
3585if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3586 Velocity = force;
3587//Console.WriteLine("UM2 {0}", Velocity);
3588 m_isNudging = false;
3589 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3590 }
3591 else // add for jumping
3592 { // add for jumping
3593 Vector3 force = Vector3.Zero; // add for jumping
3594if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3595//Console.WriteLine("UM3 {0}", Velocity);
3596 Velocity = force; // add for jumping
3597 }
3598 }
3599 // } // end realign
3600 } // add for jumping
3601 } // add for jumping
3217 3602
3218 /// <summary> 3603 /// <summary>
3219 /// Adds a physical representation of the avatar to the Physics plugin 3604 /// Adds a physical representation of the avatar to the Physics plugin
@@ -3227,10 +3612,8 @@ namespace OpenSim.Region.Framework.Scenes
3227 3612
3228 Vector3 pVec = AbsolutePosition; 3613 Vector3 pVec = AbsolutePosition;
3229 3614
3230 // Old bug where the height was in centimeters instead of meters
3231 m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, 3615 m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec,
3232 new Vector3(0f, 0f, m_appearance.AvatarHeight), isFlying); 3616 new Vector3(0f, 0f, m_appearance.AvatarHeight), isFlying);
3233
3234 scene.AddPhysicsActorTaint(m_physicsActor); 3617 scene.AddPhysicsActorTaint(m_physicsActor);
3235 //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3618 //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3236 m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3619 m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
@@ -3254,18 +3637,29 @@ namespace OpenSim.Region.Framework.Scenes
3254 { 3637 {
3255 if (e == null) 3638 if (e == null)
3256 return; 3639 return;
3257 3640
3258 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3641 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3259 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3260 // as of this comment the interval is set in AddToPhysicalScene 3642 // as of this comment the interval is set in AddToPhysicalScene
3261 if (Animator!=null) 3643 if (Animator!=null)
3262 Animator.UpdateMovementAnimations(); 3644 {
3645 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3646 { // else its will lock out other animation changes, like ground sit.
3647 Animator.UpdateMovementAnimations();
3648 m_updateCount--;
3649 }
3650 }
3263 3651
3264 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3652 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3265 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3653 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3266 3654
3267 CollisionPlane = Vector4.UnitW; 3655 CollisionPlane = Vector4.UnitW;
3268 3656
3657 if (m_lastColCount != coldata.Count)
3658 {
3659 m_updateCount = UPDATE_COUNT;
3660 m_lastColCount = coldata.Count;
3661 }
3662
3269 if (coldata.Count != 0 && Animator != null) 3663 if (coldata.Count != 0 && Animator != null)
3270 { 3664 {
3271 switch (Animator.CurrentMovementAnimation) 3665 switch (Animator.CurrentMovementAnimation)
@@ -3295,6 +3689,148 @@ namespace OpenSim.Region.Framework.Scenes
3295 } 3689 }
3296 } 3690 }
3297 3691
3692 List<uint> thisHitColliders = new List<uint>();
3693 List<uint> endedColliders = new List<uint>();
3694 List<uint> startedColliders = new List<uint>();
3695
3696 foreach (uint localid in coldata.Keys)
3697 {
3698 thisHitColliders.Add(localid);
3699 if (!m_lastColliders.Contains(localid))
3700 {
3701 startedColliders.Add(localid);
3702 }
3703 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
3704 }
3705
3706 // calculate things that ended colliding
3707 foreach (uint localID in m_lastColliders)
3708 {
3709 if (!thisHitColliders.Contains(localID))
3710 {
3711 endedColliders.Add(localID);
3712 }
3713 }
3714 //add the items that started colliding this time to the last colliders list.
3715 foreach (uint localID in startedColliders)
3716 {
3717 m_lastColliders.Add(localID);
3718 }
3719 // remove things that ended colliding from the last colliders list
3720 foreach (uint localID in endedColliders)
3721 {
3722 m_lastColliders.Remove(localID);
3723 }
3724
3725 // do event notification
3726 if (startedColliders.Count > 0)
3727 {
3728 ColliderArgs StartCollidingMessage = new ColliderArgs();
3729 List<DetectedObject> colliding = new List<DetectedObject>();
3730 foreach (uint localId in startedColliders)
3731 {
3732 if (localId == 0)
3733 continue;
3734
3735 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3736 string data = "";
3737 if (obj != null)
3738 {
3739 DetectedObject detobj = new DetectedObject();
3740 detobj.keyUUID = obj.UUID;
3741 detobj.nameStr = obj.Name;
3742 detobj.ownerUUID = obj.OwnerID;
3743 detobj.posVector = obj.AbsolutePosition;
3744 detobj.rotQuat = obj.GetWorldRotation();
3745 detobj.velVector = obj.Velocity;
3746 detobj.colliderType = 0;
3747 detobj.groupUUID = obj.GroupID;
3748 colliding.Add(detobj);
3749 }
3750 }
3751
3752 if (colliding.Count > 0)
3753 {
3754 StartCollidingMessage.Colliders = colliding;
3755
3756 foreach (SceneObjectGroup att in Attachments)
3757 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
3758 }
3759 }
3760
3761 if (endedColliders.Count > 0)
3762 {
3763 ColliderArgs EndCollidingMessage = new ColliderArgs();
3764 List<DetectedObject> colliding = new List<DetectedObject>();
3765 foreach (uint localId in endedColliders)
3766 {
3767 if (localId == 0)
3768 continue;
3769
3770 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3771 string data = "";
3772 if (obj != null)
3773 {
3774 DetectedObject detobj = new DetectedObject();
3775 detobj.keyUUID = obj.UUID;
3776 detobj.nameStr = obj.Name;
3777 detobj.ownerUUID = obj.OwnerID;
3778 detobj.posVector = obj.AbsolutePosition;
3779 detobj.rotQuat = obj.GetWorldRotation();
3780 detobj.velVector = obj.Velocity;
3781 detobj.colliderType = 0;
3782 detobj.groupUUID = obj.GroupID;
3783 colliding.Add(detobj);
3784 }
3785 }
3786
3787 if (colliding.Count > 0)
3788 {
3789 EndCollidingMessage.Colliders = colliding;
3790
3791 foreach (SceneObjectGroup att in Attachments)
3792 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
3793 }
3794 }
3795
3796 if (thisHitColliders.Count > 0)
3797 {
3798 ColliderArgs CollidingMessage = new ColliderArgs();
3799 List<DetectedObject> colliding = new List<DetectedObject>();
3800 foreach (uint localId in thisHitColliders)
3801 {
3802 if (localId == 0)
3803 continue;
3804
3805 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3806 string data = "";
3807 if (obj != null)
3808 {
3809 DetectedObject detobj = new DetectedObject();
3810 detobj.keyUUID = obj.UUID;
3811 detobj.nameStr = obj.Name;
3812 detobj.ownerUUID = obj.OwnerID;
3813 detobj.posVector = obj.AbsolutePosition;
3814 detobj.rotQuat = obj.GetWorldRotation();
3815 detobj.velVector = obj.Velocity;
3816 detobj.colliderType = 0;
3817 detobj.groupUUID = obj.GroupID;
3818 colliding.Add(detobj);
3819 }
3820 }
3821
3822 if (colliding.Count > 0)
3823 {
3824 CollidingMessage.Colliders = colliding;
3825
3826 lock (m_attachments)
3827 {
3828 foreach (SceneObjectGroup att in m_attachments)
3829 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
3830 }
3831 }
3832 }
3833
3298 if (m_invulnerable) 3834 if (m_invulnerable)
3299 return; 3835 return;
3300 3836
@@ -3720,6 +4256,39 @@ namespace OpenSim.Region.Framework.Scenes
3720 return; 4256 return;
3721 } 4257 }
3722 4258
4259 XmlDocument doc = new XmlDocument();
4260 string stateData = String.Empty;
4261
4262 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
4263 if (attServ != null)
4264 {
4265 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
4266 stateData = attServ.Get(ControllingClient.AgentId.ToString());
4267 if (stateData != String.Empty)
4268 {
4269 try
4270 {
4271 doc.LoadXml(stateData);
4272 }
4273 catch { }
4274 }
4275 }
4276
4277 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
4278
4279 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
4280 if (nodes.Count > 0)
4281 {
4282 foreach (XmlNode n in nodes)
4283 {
4284 XmlElement elem = (XmlElement)n;
4285 string itemID = elem.GetAttribute("ItemID");
4286 string xml = elem.InnerXml;
4287
4288 itemData[new UUID(itemID)] = xml;
4289 }
4290 }
4291
3723 List<AvatarAttachment> attachments = m_appearance.GetAttachments(); 4292 List<AvatarAttachment> attachments = m_appearance.GetAttachments();
3724 foreach (AvatarAttachment attach in attachments) 4293 foreach (AvatarAttachment attach in attachments)
3725 { 4294 {
@@ -3740,7 +4309,30 @@ namespace OpenSim.Region.Framework.Scenes
3740 4309
3741 try 4310 try
3742 { 4311 {
3743 m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p); 4312 string xmlData;
4313 XmlDocument d = new XmlDocument();
4314 UUID asset;
4315 if (itemData.TryGetValue(itemID, out xmlData))
4316 {
4317 d.LoadXml(xmlData);
4318 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID);
4319
4320 // Rez from inventory
4321 asset
4322 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d);
4323
4324 }
4325 else
4326 {
4327 // Rez from inventory (with a null doc to let
4328 // CHANGED_OWNER happen)
4329 asset
4330 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, null);
4331 }
4332
4333 m_log.InfoFormat(
4334 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2}",
4335 p, itemID, asset);
3744 } 4336 }
3745 catch (Exception e) 4337 catch (Exception e)
3746 { 4338 {
@@ -3773,6 +4365,15 @@ namespace OpenSim.Region.Framework.Scenes
3773 m_reprioritization_called = false; 4365 m_reprioritization_called = false;
3774 } 4366 }
3775 } 4367 }
4368
4369 private Vector3 Quat2Euler(Quaternion rot){
4370 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4371 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4372 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4373 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4374 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4375 return(new Vector3(x,y,z));
4376 }
3776 4377
3777 public void SaveChangedAttachments() 4378 public void SaveChangedAttachments()
3778 { 4379 {