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.cs971
1 files changed, 786 insertions, 185 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index d4b4e0a..1e749da 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 // OS Mantis #4063 467 else // OS Mantis #4063
449 { // OS Mantis #4063 468 { // OS Mantis #4063
@@ -489,7 +508,8 @@ namespace OpenSim.Region.Framework.Scenes
489 } 508 }
490 } 509 }
491 510
492 m_pos = value; 511 if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting!
512 m_pos = value;
493 m_parentPosition = Vector3.Zero; 513 m_parentPosition = Vector3.Zero;
494 } 514 }
495 } 515 }
@@ -533,10 +553,39 @@ namespace OpenSim.Region.Framework.Scenes
533 } 553 }
534 } 554 }
535 555
556 public Quaternion OffsetRotation
557 {
558 get { return m_offsetRotation; }
559 set { m_offsetRotation = value; }
560 }
561
536 public Quaternion Rotation 562 public Quaternion Rotation
537 { 563 {
538 get { return m_bodyRot; } 564 get {
539 set { m_bodyRot = value; } 565 if (m_parentID != 0)
566 {
567 if (m_offsetRotation != null)
568 {
569 return m_offsetRotation;
570 }
571 else
572 {
573 return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
574 }
575
576 }
577 else
578 {
579 return m_bodyRot;
580 }
581 }
582 set {
583 m_bodyRot = value;
584 if (m_parentID != 0)
585 {
586 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
587 }
588 }
540 } 589 }
541 590
542 public Quaternion PreviousRotation 591 public Quaternion PreviousRotation
@@ -561,11 +610,21 @@ namespace OpenSim.Region.Framework.Scenes
561 610
562 private uint m_parentID; 611 private uint m_parentID;
563 612
613
614 private UUID m_linkedPrim;
615
564 public uint ParentID 616 public uint ParentID
565 { 617 {
566 get { return m_parentID; } 618 get { return m_parentID; }
567 set { m_parentID = value; } 619 set { m_parentID = value; }
568 } 620 }
621
622 public UUID LinkedPrim
623 {
624 get { return m_linkedPrim; }
625 set { m_linkedPrim = value; }
626 }
627
569 public float Health 628 public float Health
570 { 629 {
571 get { return m_health; } 630 get { return m_health; }
@@ -687,7 +746,7 @@ namespace OpenSim.Region.Framework.Scenes
687 CreateSceneViewer(); 746 CreateSceneViewer();
688 m_animator = new ScenePresenceAnimator(this); 747 m_animator = new ScenePresenceAnimator(this);
689 } 748 }
690 749
691 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() 750 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this()
692 { 751 {
693 m_rootRegionHandle = reginfo.RegionHandle; 752 m_rootRegionHandle = reginfo.RegionHandle;
@@ -719,10 +778,7 @@ namespace OpenSim.Region.Framework.Scenes
719 m_reprioritization_timer.AutoReset = false; 778 m_reprioritization_timer.AutoReset = false;
720 779
721 AdjustKnownSeeds(); 780 AdjustKnownSeeds();
722
723 // TODO: I think, this won't send anything, as we are still a child here...
724 Animator.TrySetMovementAnimation("STAND"); 781 Animator.TrySetMovementAnimation("STAND");
725
726 // we created a new ScenePresence (a new child agent) in a fresh region. 782 // we created a new ScenePresence (a new child agent) in a fresh region.
727 // Request info about all the (root) agents in this region 783 // Request info about all the (root) agents in this region
728 // Note: This won't send data *to* other clients in that region (children don't send) 784 // Note: This won't send data *to* other clients in that region (children don't send)
@@ -773,25 +829,47 @@ namespace OpenSim.Region.Framework.Scenes
773 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 829 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
774 Dir_Vectors[4] = Vector3.UnitZ; //UP 830 Dir_Vectors[4] = Vector3.UnitZ; //UP
775 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 831 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
776 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 832 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
777 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 833 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
778 Dir_Vectors[7] = -Vector3.UnitX; //BACK 834 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
835 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
836 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
779 } 837 }
780 838
781 private Vector3[] GetWalkDirectionVectors() 839 private Vector3[] GetWalkDirectionVectors()
782 { 840 {
783 Vector3[] vector = new Vector3[9]; 841 Vector3[] vector = new Vector3[11];
784 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 842 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
785 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 843 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
786 vector[2] = Vector3.UnitY; //LEFT 844 vector[2] = Vector3.UnitY; //LEFT
787 vector[3] = -Vector3.UnitY; //RIGHT 845 vector[3] = -Vector3.UnitY; //RIGHT
788 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 846 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
789 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 847 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
790 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 848 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
791 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 849 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
792 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 850 vector[8] = Vector3.UnitY; //LEFT_NUDGE
851 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
852 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
793 return vector; 853 return vector;
794 } 854 }
855
856 private bool[] GetDirectionIsNudge()
857 {
858 bool[] isNudge = new bool[11];
859 isNudge[0] = false; //FORWARD
860 isNudge[1] = false; //BACK
861 isNudge[2] = false; //LEFT
862 isNudge[3] = false; //RIGHT
863 isNudge[4] = false; //UP
864 isNudge[5] = false; //DOWN
865 isNudge[6] = true; //FORWARD_NUDGE
866 isNudge[7] = true; //BACK_NUDGE
867 isNudge[8] = true; //LEFT_NUDGE
868 isNudge[9] = true; //RIGHT_NUDGE
869 isNudge[10] = true; //DOWN_Nudge
870 return isNudge;
871 }
872
795 873
796 #endregion 874 #endregion
797 875
@@ -853,6 +931,54 @@ namespace OpenSim.Region.Framework.Scenes
853 pos.Y = crossedBorder.BorderLine.Z - 1; 931 pos.Y = crossedBorder.BorderLine.Z - 1;
854 } 932 }
855 933
934 //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet.
935 //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent,
936 //they'll bypass the landing point. But I can't think of any decent way of fixing this.
937 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
938 if (land != null)
939 {
940 if (KnownChildRegionHandles.Count == 0)
941 {
942 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
943 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)
944 {
945 pos = land.LandData.UserLocation;
946 }
947 }
948
949 land.SendLandUpdateToClient(ControllingClient);
950 }
951
952 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0)
953 {
954 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128);
955
956 if (pos.X < 0)
957 {
958 emergencyPos.X = (int)Constants.RegionSize + pos.X;
959 if (!(pos.Y < 0))
960 emergencyPos.Y = pos.Y;
961 if (!(pos.Z < 0))
962 emergencyPos.Z = pos.Z;
963 }
964 if (pos.Y < 0)
965 {
966 emergencyPos.Y = (int)Constants.RegionSize + pos.Y;
967 if (!(pos.X < 0))
968 emergencyPos.X = pos.X;
969 if (!(pos.Z < 0))
970 emergencyPos.Z = pos.Z;
971 }
972 if (pos.Z < 0)
973 {
974 emergencyPos.Z = 128;
975 if (!(pos.Y < 0))
976 emergencyPos.Y = pos.Y;
977 if (!(pos.X < 0))
978 emergencyPos.X = pos.X;
979 }
980 }
981
856 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 982 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
857 { 983 {
858 m_log.WarnFormat( 984 m_log.WarnFormat(
@@ -981,12 +1107,17 @@ namespace OpenSim.Region.Framework.Scenes
981 { 1107 {
982 if (PhysicsActor != null) 1108 if (PhysicsActor != null)
983 { 1109 {
984 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1110 try
985 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall; 1111 {
986 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); 1112 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
987 m_physicsActor.UnSubscribeEvents(); 1113 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall;
988 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1114 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
989 PhysicsActor = null; 1115 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1116 m_physicsActor.UnSubscribeEvents();
1117 PhysicsActor = null;
1118 }
1119 catch
1120 { }
990 } 1121 }
991 } 1122 }
992 1123
@@ -997,9 +1128,10 @@ namespace OpenSim.Region.Framework.Scenes
997 public void Teleport(Vector3 pos) 1128 public void Teleport(Vector3 pos)
998 { 1129 {
999 bool isFlying = false; 1130 bool isFlying = false;
1131
1000 if (m_physicsActor != null) 1132 if (m_physicsActor != null)
1001 isFlying = m_physicsActor.Flying; 1133 isFlying = m_physicsActor.Flying;
1002 1134
1003 RemoveFromPhysicalScene(); 1135 RemoveFromPhysicalScene();
1004 Velocity = Vector3.Zero; 1136 Velocity = Vector3.Zero;
1005 AbsolutePosition = pos; 1137 AbsolutePosition = pos;
@@ -1011,6 +1143,7 @@ namespace OpenSim.Region.Framework.Scenes
1011 } 1143 }
1012 1144
1013 SendTerseUpdateToAllClients(); 1145 SendTerseUpdateToAllClients();
1146
1014 } 1147 }
1015 1148
1016 public void TeleportWithMomentum(Vector3 pos) 1149 public void TeleportWithMomentum(Vector3 pos)
@@ -1229,6 +1362,7 @@ namespace OpenSim.Region.Framework.Scenes
1229 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); 1362 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902");
1230 1363
1231 m_pos = m_LastFinitePos; 1364 m_pos = m_LastFinitePos;
1365
1232 if (!m_pos.IsFinite()) 1366 if (!m_pos.IsFinite())
1233 { 1367 {
1234 m_pos.X = 127f; 1368 m_pos.X = 127f;
@@ -1295,7 +1429,6 @@ namespace OpenSim.Region.Framework.Scenes
1295 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1429 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1296 } 1430 }
1297 } 1431 }
1298
1299 lock (scriptedcontrols) 1432 lock (scriptedcontrols)
1300 { 1433 {
1301 if (scriptedcontrols.Count > 0) 1434 if (scriptedcontrols.Count > 0)
@@ -1310,6 +1443,9 @@ namespace OpenSim.Region.Framework.Scenes
1310 1443
1311 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1444 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1312 { 1445 {
1446 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1447 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1448
1313 // TODO: This doesn't prevent the user from walking yet. 1449 // TODO: This doesn't prevent the user from walking yet.
1314 // Setting parent ID would fix this, if we knew what value 1450 // Setting parent ID would fix this, if we knew what value
1315 // to use. Or we could add a m_isSitting variable. 1451 // to use. Or we could add a m_isSitting variable.
@@ -1358,12 +1494,20 @@ namespace OpenSim.Region.Framework.Scenes
1358 if (actor.Flying != oldflying) 1494 if (actor.Flying != oldflying)
1359 update_movementflag = true; 1495 update_movementflag = true;
1360 1496
1497 if (m_animator.m_jumping) // add for jumping
1498 update_movementflag = true;
1499
1361 if (q != m_bodyRot) 1500 if (q != m_bodyRot)
1362 { 1501 {
1363 m_bodyRot = q; 1502 m_bodyRot = q;
1364 update_rotation = true; 1503 update_rotation = true;
1365 } 1504 }
1366 1505
1506 //guilty until proven innocent..
1507 bool Nudging = true;
1508 //Basically, if there is at least one non-nudge control then we don't need
1509 //to worry about stopping the avatar
1510
1367 if (m_parentID == 0) 1511 if (m_parentID == 0)
1368 { 1512 {
1369 bool bAllowUpdateMoveToPosition = false; 1513 bool bAllowUpdateMoveToPosition = false;
@@ -1378,9 +1522,12 @@ namespace OpenSim.Region.Framework.Scenes
1378 else 1522 else
1379 dirVectors = Dir_Vectors; 1523 dirVectors = Dir_Vectors;
1380 1524
1381 // The fact that m_movementflag is a byte needs to be fixed 1525 bool[] isNudge = GetDirectionIsNudge();
1382 // it really should be a uint 1526
1383 uint nudgehack = 250; 1527
1528
1529
1530
1384 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1531 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1385 { 1532 {
1386 if (((uint)flags & (uint)DCF) != 0) 1533 if (((uint)flags & (uint)DCF) != 0)
@@ -1390,40 +1537,28 @@ namespace OpenSim.Region.Framework.Scenes
1390 try 1537 try
1391 { 1538 {
1392 agent_control_v3 += dirVectors[i]; 1539 agent_control_v3 += dirVectors[i];
1393 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1540 if (isNudge[i] == false)
1541 {
1542 Nudging = false;
1543 }
1394 } 1544 }
1395 catch (IndexOutOfRangeException) 1545 catch (IndexOutOfRangeException)
1396 { 1546 {
1397 // Why did I get this? 1547 // Why did I get this?
1398 } 1548 }
1399 1549
1400 if ((m_movementflag & (byte)(uint)DCF) == 0) 1550 if ((m_movementflag & (uint)DCF) == 0)
1401 { 1551 {
1402 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1403 {
1404 m_movementflag |= (byte)nudgehack;
1405 }
1406 m_movementflag += (byte)(uint)DCF; 1552 m_movementflag += (byte)(uint)DCF;
1407 update_movementflag = true; 1553 update_movementflag = true;
1408 } 1554 }
1409 } 1555 }
1410 else 1556 else
1411 { 1557 {
1412 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1558 if ((m_movementflag & (uint)DCF) != 0)
1413 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1414 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1415 ) // This or is for Nudge forward
1416 { 1559 {
1417 m_movementflag -= ((byte)(uint)DCF); 1560 m_movementflag -= (byte)(uint)DCF;
1418
1419 update_movementflag = true; 1561 update_movementflag = true;
1420 /*
1421 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1422 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1423 {
1424 m_log.Debug("Removed Hack flag");
1425 }
1426 */
1427 } 1562 }
1428 else 1563 else
1429 { 1564 {
@@ -1432,7 +1567,6 @@ namespace OpenSim.Region.Framework.Scenes
1432 } 1567 }
1433 i++; 1568 i++;
1434 } 1569 }
1435
1436 //Paupaw:Do Proper PID for Autopilot here 1570 //Paupaw:Do Proper PID for Autopilot here
1437 if (bResetMoveToPosition) 1571 if (bResetMoveToPosition)
1438 { 1572 {
@@ -1467,6 +1601,9 @@ namespace OpenSim.Region.Framework.Scenes
1467 // Ignore z component of vector 1601 // Ignore z component of vector
1468 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1602 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1469 LocalVectorToTarget2D.Normalize(); 1603 LocalVectorToTarget2D.Normalize();
1604
1605 //We're not nudging
1606 Nudging = false;
1470 agent_control_v3 += LocalVectorToTarget2D; 1607 agent_control_v3 += LocalVectorToTarget2D;
1471 1608
1472 // update avatar movement flags. the avatar coordinate system is as follows: 1609 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1557,13 +1694,13 @@ namespace OpenSim.Region.Framework.Scenes
1557 // m_log.DebugFormat( 1694 // m_log.DebugFormat(
1558 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1695 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1559 1696
1560 AddNewMovement(agent_control_v3, q); 1697 AddNewMovement(agent_control_v3, q, Nudging);
1561 1698
1562 1699
1563 } 1700 }
1564 } 1701 }
1565 1702
1566 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1703 if (update_movementflag && !SitGround)
1567 Animator.UpdateMovementAnimations(); 1704 Animator.UpdateMovementAnimations();
1568 1705
1569 m_scene.EventManager.TriggerOnClientMovement(this); 1706 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1578,7 +1715,6 @@ namespace OpenSim.Region.Framework.Scenes
1578 m_sitAtAutoTarget = false; 1715 m_sitAtAutoTarget = false;
1579 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1716 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1580 //proxy.PCode = (byte)PCode.ParticleSystem; 1717 //proxy.PCode = (byte)PCode.ParticleSystem;
1581
1582 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1718 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1583 proxyObjectGroup.AttachToScene(m_scene); 1719 proxyObjectGroup.AttachToScene(m_scene);
1584 1720
@@ -1620,7 +1756,7 @@ namespace OpenSim.Region.Framework.Scenes
1620 } 1756 }
1621 m_moveToPositionInProgress = true; 1757 m_moveToPositionInProgress = true;
1622 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1758 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1623 } 1759 }
1624 catch (Exception ex) 1760 catch (Exception ex)
1625 { 1761 {
1626 //Why did I get this error? 1762 //Why did I get this error?
@@ -1642,7 +1778,7 @@ namespace OpenSim.Region.Framework.Scenes
1642 Velocity = Vector3.Zero; 1778 Velocity = Vector3.Zero;
1643 SendAvatarDataToAllAgents(); 1779 SendAvatarDataToAllAgents();
1644 1780
1645 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1781 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1646 } 1782 }
1647 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1783 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1648 m_requestedSitTargetUUID = UUID.Zero; 1784 m_requestedSitTargetUUID = UUID.Zero;
@@ -1679,42 +1815,77 @@ namespace OpenSim.Region.Framework.Scenes
1679 1815
1680 if (m_parentID != 0) 1816 if (m_parentID != 0)
1681 { 1817 {
1682 m_log.Debug("StandupCode Executed"); 1818 SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID);
1683 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1684 if (part != null) 1819 if (part != null)
1685 { 1820 {
1821 part.TaskInventory.LockItemsForRead(true);
1686 TaskInventoryDictionary taskIDict = part.TaskInventory; 1822 TaskInventoryDictionary taskIDict = part.TaskInventory;
1687 if (taskIDict != null) 1823 if (taskIDict != null)
1688 { 1824 {
1689 lock (taskIDict) 1825 foreach (UUID taskID in taskIDict.Keys)
1690 { 1826 {
1691 foreach (UUID taskID in taskIDict.Keys) 1827 UnRegisterControlEventsToScript(LocalId, taskID);
1692 { 1828 taskIDict[taskID].PermsMask &= ~(
1693 UnRegisterControlEventsToScript(LocalId, taskID); 1829 2048 | //PERMISSION_CONTROL_CAMERA
1694 taskIDict[taskID].PermsMask &= ~( 1830 4); // PERMISSION_TAKE_CONTROLS
1695 2048 | //PERMISSION_CONTROL_CAMERA
1696 4); // PERMISSION_TAKE_CONTROLS
1697 }
1698 } 1831 }
1699
1700 } 1832 }
1833 part.TaskInventory.LockItemsForRead(false);
1701 // Reset sit target. 1834 // Reset sit target.
1702 if (part.GetAvatarOnSitTarget() == UUID) 1835 if (part.GetAvatarOnSitTarget() == UUID)
1703 part.SetAvatarOnSitTarget(UUID.Zero); 1836 part.SetAvatarOnSitTarget(UUID.Zero);
1704
1705 m_parentPosition = part.GetWorldPosition(); 1837 m_parentPosition = part.GetWorldPosition();
1706 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1838 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1707 } 1839 }
1840 // part.GetWorldRotation() is the rotation of the object being sat on
1841 // Rotation is the sittiing Av's rotation
1842
1843 Quaternion partRot;
1844// if (part.LinkNum == 1)
1845// { // Root prim of linkset
1846// partRot = part.ParentGroup.RootPart.RotationOffset;
1847// }
1848// else
1849// { // single or child prim
1850
1851// }
1852 if (part == null) //CW: Part may be gone. llDie() for example.
1853 {
1854 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1855 }
1856 else
1857 {
1858 partRot = part.GetWorldRotation();
1859 }
1708 1860
1861 Quaternion partIRot = Quaternion.Inverse(partRot);
1862
1863 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1864 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1865
1866
1709 if (m_physicsActor == null) 1867 if (m_physicsActor == null)
1710 { 1868 {
1711 AddToPhysicalScene(false); 1869 AddToPhysicalScene(false);
1712 } 1870 }
1713 1871 //CW: If the part isn't null then we can set the current position
1714 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1872 if (part != null)
1715 m_parentPosition = Vector3.Zero; 1873 {
1716 1874 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + ((m_pos - part.OffsetPosition) * partRot); // + av sit offset!
1717 m_parentID = 0; 1875 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1876 part.IsOccupied = false;
1877 part.ParentGroup.DeleteAvatar(ControllingClient.AgentId);
1878 }
1879 else
1880 {
1881 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1882 AbsolutePosition = m_lastWorldPosition;
1883 }
1884
1885 m_parentPosition = Vector3.Zero;
1886 m_parentID = 0;
1887 m_linkedPrim = UUID.Zero;
1888 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1718 SendAvatarDataToAllAgents(); 1889 SendAvatarDataToAllAgents();
1719 m_requestedSitTargetID = 0; 1890 m_requestedSitTargetID = 0;
1720 if (m_physicsActor != null && m_appearance != null) 1891 if (m_physicsActor != null && m_appearance != null)
@@ -1723,7 +1894,6 @@ namespace OpenSim.Region.Framework.Scenes
1723 SetHeight(m_appearance.AvatarHeight); 1894 SetHeight(m_appearance.AvatarHeight);
1724 } 1895 }
1725 } 1896 }
1726
1727 Animator.TrySetMovementAnimation("STAND"); 1897 Animator.TrySetMovementAnimation("STAND");
1728 } 1898 }
1729 1899
@@ -1754,13 +1924,9 @@ namespace OpenSim.Region.Framework.Scenes
1754 Vector3 avSitOffSet = part.SitTargetPosition; 1924 Vector3 avSitOffSet = part.SitTargetPosition;
1755 Quaternion avSitOrientation = part.SitTargetOrientation; 1925 Quaternion avSitOrientation = part.SitTargetOrientation;
1756 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1926 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1757 1927 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1758 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1928 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1759 bool SitTargetisSet = 1929 if (SitTargetisSet && !SitTargetOccupied)
1760 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1761 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1762
1763 if (SitTargetisSet && SitTargetUnOccupied)
1764 { 1930 {
1765 //switch the target to this prim 1931 //switch the target to this prim
1766 return part; 1932 return part;
@@ -1774,84 +1940,164 @@ namespace OpenSim.Region.Framework.Scenes
1774 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1940 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1775 { 1941 {
1776 bool autopilot = true; 1942 bool autopilot = true;
1943 Vector3 autopilotTarget = new Vector3();
1944 Quaternion sitOrientation = Quaternion.Identity;
1777 Vector3 pos = new Vector3(); 1945 Vector3 pos = new Vector3();
1778 Quaternion sitOrientation = pSitOrientation;
1779 Vector3 cameraEyeOffset = Vector3.Zero; 1946 Vector3 cameraEyeOffset = Vector3.Zero;
1780 Vector3 cameraAtOffset = Vector3.Zero; 1947 Vector3 cameraAtOffset = Vector3.Zero;
1781 bool forceMouselook = false; 1948 bool forceMouselook = false;
1782 1949
1783 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1950 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1784 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1951 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1785 if (part != null) 1952 if (part == null) return;
1786 { 1953
1787 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1954 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1788 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1955 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1789 1956
1790 // Is a sit target available? 1957 // part is the prim to sit on
1791 Vector3 avSitOffSet = part.SitTargetPosition; 1958 // offset is the world-ref vector distance from that prim center to the click-spot
1792 Quaternion avSitOrientation = part.SitTargetOrientation; 1959 // UUID is the UUID of the Avatar doing the clicking
1793 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1960
1794 1961 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1795 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1962
1796 bool SitTargetisSet = 1963 // Is a sit target available?
1797 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1964 Vector3 avSitOffSet = part.SitTargetPosition;
1798 ( 1965 Quaternion avSitOrientation = part.SitTargetOrientation;
1799 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1966
1800 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1967 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1801 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1968 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1802 ) 1969 Quaternion partRot;
1803 )); 1970// if (part.LinkNum == 1)
1804 1971// { // Root prim of linkset
1805 if (SitTargetisSet && SitTargetUnOccupied) 1972// partRot = part.ParentGroup.RootPart.RotationOffset;
1806 { 1973// }
1807 part.SetAvatarOnSitTarget(UUID); 1974// else
1808 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1975// { // single or child prim
1809 sitOrientation = avSitOrientation; 1976 partRot = part.GetWorldRotation();
1810 autopilot = false; 1977// }
1811 } 1978 Quaternion partIRot = Quaternion.Inverse(partRot);
1812 1979//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1813 pos = part.AbsolutePosition + offset; 1980 // Sit analysis rewritten by KF 091125
1814 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1981 if (SitTargetisSet) // scipted sit
1815 //{ 1982 {
1816 // offset = pos; 1983 if (!part.IsOccupied)
1817 //autopilot = false; 1984 {
1818 //} 1985//Console.WriteLine("Scripted, unoccupied");
1819 if (m_physicsActor != null) 1986 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1820 { 1987 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1821 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1988
1822 // We can remove the physicsActor until they stand up. 1989 Quaternion nrot = avSitOrientation;
1823 m_sitAvatarHeight = m_physicsActor.Size.Z; 1990 if (!part.IsRoot)
1824
1825 if (autopilot)
1826 { 1991 {
1827 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1992 nrot = part.RotationOffset * avSitOrientation;
1828 {
1829 autopilot = false;
1830
1831 RemoveFromPhysicalScene();
1832 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
1833 }
1834 } 1993 }
1835 else 1994 sitOrientation = nrot; // Change rotatione to the scripted one
1995 OffsetRotation = nrot;
1996 autopilot = false; // Jump direct to scripted llSitPos()
1997 }
1998 else
1999 {
2000//Console.WriteLine("Scripted, occupied");
2001 return;
2002 }
2003 }
2004 else // Not Scripted
2005 {
2006 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
2007 {
2008 // large prim & offset, ignore if other Avs sitting
2009// offset.Z -= 0.05f;
2010 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
2011 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
2012
2013//Console.WriteLine(" offset ={0}", offset);
2014//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
2015//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
2016
2017 }
2018 else // small offset
2019 {
2020//Console.WriteLine("Small offset");
2021 if (!part.IsOccupied)
2022 {
2023 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
2024 autopilotTarget = part.AbsolutePosition;
2025//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget);
2026 }
2027 else return; // occupied small
2028 } // end large/small
2029 } // end Scripted/not
2030 cameraAtOffset = part.GetCameraAtOffset();
2031 cameraEyeOffset = part.GetCameraEyeOffset();
2032 forceMouselook = part.GetForceMouselook();
2033 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
2034 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
2035
2036 if (m_physicsActor != null)
2037 {
2038 // If we're not using the client autopilot, we're immediately warping the avatar to the location
2039 // We can remove the physicsActor until they stand up.
2040 m_sitAvatarHeight = m_physicsActor.Size.Z;
2041 if (autopilot)
2042 { // its not a scripted sit
2043// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
2044 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 256.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 256.0f) )
1836 { 2045 {
2046 autopilot = false; // close enough
2047 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2048 Not using the part's position because returning the AV to the last known standing
2049 position is likely to be more friendly, isn't it? */
1837 RemoveFromPhysicalScene(); 2050 RemoveFromPhysicalScene();
1838 } 2051 Velocity = Vector3.Zero;
2052 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
2053 } // else the autopilot will get us close
2054 }
2055 else
2056 { // its a scripted sit
2057 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2058 I *am* using the part's position this time because we have no real idea how far away
2059 the avatar is from the sit target. */
2060 RemoveFromPhysicalScene();
2061 Velocity = Vector3.Zero;
1839 } 2062 }
1840
1841 cameraAtOffset = part.GetCameraAtOffset();
1842 cameraEyeOffset = part.GetCameraEyeOffset();
1843 forceMouselook = part.GetForceMouselook();
1844 } 2063 }
1845 2064 else return; // physactor is null!
1846 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 2065
1847 m_requestedSitTargetUUID = targetID; 2066 Vector3 offsetr; // = offset * partIRot;
2067 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
2068 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
2069 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
2070 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
2071 //offsetr = offset * partIRot;
2072//
2073 // else
2074 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
2075 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
2076 // (offset * partRot);
2077 // }
2078
2079//Console.WriteLine(" ");
2080//Console.WriteLine("link number ={0}", part.LinkNum);
2081//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
2082//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
2083//Console.WriteLine("Click offst ={0}", offset);
2084//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
2085//Console.WriteLine("offsetr ={0}", offsetr);
2086//Console.WriteLine("Camera At ={0}", cameraAtOffset);
2087//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
2088
2089 //NOTE: SendSitResponse should be relative to the GROUP *NOT* THE PRIM if we're sitting on a child
2090 ControllingClient.SendSitResponse(part.ParentGroup.UUID, ((offset * part.RotationOffset) + part.OffsetPosition), sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
2091
2092 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1848 // This calls HandleAgentSit twice, once from here, and the client calls 2093 // This calls HandleAgentSit twice, once from here, and the client calls
1849 // HandleAgentSit itself after it gets to the location 2094 // HandleAgentSit itself after it gets to the location
1850 // It doesn't get to the location until we've moved them there though 2095 // It doesn't get to the location until we've moved them there though
1851 // which happens in HandleAgentSit :P 2096 // which happens in HandleAgentSit :P
1852 m_autopilotMoving = autopilot; 2097 m_autopilotMoving = autopilot;
1853 m_autoPilotTarget = pos; 2098 m_autoPilotTarget = autopilotTarget;
1854 m_sitAtAutoTarget = autopilot; 2099 m_sitAtAutoTarget = autopilot;
2100 m_initialSitTarget = autopilotTarget;
1855 if (!autopilot) 2101 if (!autopilot)
1856 HandleAgentSit(remoteClient, UUID); 2102 HandleAgentSit(remoteClient, UUID);
1857 } 2103 }
@@ -2146,47 +2392,130 @@ namespace OpenSim.Region.Framework.Scenes
2146 { 2392 {
2147 if (part != null) 2393 if (part != null)
2148 { 2394 {
2395//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2149 if (part.GetAvatarOnSitTarget() == UUID) 2396 if (part.GetAvatarOnSitTarget() == UUID)
2150 { 2397 {
2398//Console.WriteLine("Scripted Sit");
2399 // Scripted sit
2151 Vector3 sitTargetPos = part.SitTargetPosition; 2400 Vector3 sitTargetPos = part.SitTargetPosition;
2152 Quaternion sitTargetOrient = part.SitTargetOrientation; 2401 Quaternion sitTargetOrient = part.SitTargetOrientation;
2153
2154 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2155 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2156
2157 //Quaternion result = (sitTargetOrient * vq) * nq;
2158
2159 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2402 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2160 m_pos += SIT_TARGET_ADJUSTMENT; 2403 m_pos += SIT_TARGET_ADJUSTMENT;
2404 if (!part.IsRoot)
2405 {
2406 m_pos *= part.RotationOffset;
2407 }
2161 m_bodyRot = sitTargetOrient; 2408 m_bodyRot = sitTargetOrient;
2162 //Rotation = sitTargetOrient;
2163 m_parentPosition = part.AbsolutePosition; 2409 m_parentPosition = part.AbsolutePosition;
2164 2410 part.IsOccupied = true;
2165 //SendTerseUpdateToAllClients(); 2411 part.ParentGroup.AddAvatar(agentID);
2166 } 2412 }
2167 else 2413 else
2168 { 2414 {
2169 m_pos -= part.AbsolutePosition; 2415 // if m_avUnscriptedSitPos is zero then Av sits above center
2416 // Else Av sits at m_avUnscriptedSitPos
2417
2418 // Non-scripted sit by Kitto Flora 21Nov09
2419 // Calculate angle of line from prim to Av
2420 Quaternion partIRot;
2421// if (part.LinkNum == 1)
2422// { // Root prim of linkset
2423// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2424// }
2425// else
2426// { // single or child prim
2427 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2428// }
2429 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2430 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2431 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2432 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2433 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2434 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2435 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2436 // Av sits at world euler <0,0, z>, translated by part rotation
2437 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2438
2170 m_parentPosition = part.AbsolutePosition; 2439 m_parentPosition = part.AbsolutePosition;
2171 } 2440 part.IsOccupied = true;
2441 part.ParentGroup.AddAvatar(agentID);
2442 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2443 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2444 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2445 m_avUnscriptedSitPos; // adds click offset, if any
2446 //Set up raytrace to find top surface of prim
2447 Vector3 size = part.Scale;
2448 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2449 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2450 Vector3 down = new Vector3(0f, 0f, -1f);
2451//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2452 m_scene.PhysicsScene.RaycastWorld(
2453 start, // Vector3 position,
2454 down, // Vector3 direction,
2455 mag, // float length,
2456 SitAltitudeCallback); // retMethod
2457 } // end scripted/not
2172 } 2458 }
2173 else 2459 else // no Av
2174 { 2460 {
2175 return; 2461 return;
2176 } 2462 }
2177 } 2463 }
2178 m_parentID = m_requestedSitTargetID;
2179 2464
2465 //We want our offsets to reference the root prim, not the child we may have sat on
2466 if (!part.IsRoot)
2467 {
2468 m_parentID = part.ParentGroup.RootPart.LocalId;
2469 m_pos += part.OffsetPosition;
2470 }
2471 else
2472 {
2473 m_parentID = m_requestedSitTargetID;
2474 }
2475
2476 m_linkedPrim = part.UUID;
2477 if (part.GetAvatarOnSitTarget() != UUID)
2478 {
2479 m_offsetRotation = m_offsetRotation / part.RotationOffset;
2480 }
2180 Velocity = Vector3.Zero; 2481 Velocity = Vector3.Zero;
2181 RemoveFromPhysicalScene(); 2482 RemoveFromPhysicalScene();
2182
2183 Animator.TrySetMovementAnimation(sitAnimation); 2483 Animator.TrySetMovementAnimation(sitAnimation);
2184 SendAvatarDataToAllAgents(); 2484 SendAvatarDataToAllAgents();
2185 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2186 // So we're also sending a terse update (which has avatar rotation)
2187 // [Update] We do now.
2188 //SendTerseUpdateToAllClients(); 2485 //SendTerseUpdateToAllClients();
2189 } 2486 }
2487
2488 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2489 {
2490 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2491 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2492 if(hitYN)
2493 {
2494 // m_pos = Av offset from prim center to make look like on center
2495 // m_parentPosition = Actual center pos of prim
2496 // collisionPoint = spot on prim where we want to sit
2497 // collisionPoint.Z = global sit surface height
2498 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2499 Quaternion partIRot;
2500// if (part.LinkNum == 1)
2501/// { // Root prim of linkset
2502// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2503// }
2504// else
2505// { // single or child prim
2506 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2507// }
2508 if (m_initialSitTarget != null)
2509 {
2510 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2511 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2512 //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2513 m_pos += offset;
2514 // ControllingClient.SendClearFollowCamProperties(part.UUID);
2515 }
2516
2517 }
2518 } // End SitAltitudeCallback KF.
2190 2519
2191 /// <summary> 2520 /// <summary>
2192 /// Event handler for the 'Always run' setting on the client 2521 /// Event handler for the 'Always run' setting on the client
@@ -2216,7 +2545,7 @@ namespace OpenSim.Region.Framework.Scenes
2216 /// </summary> 2545 /// </summary>
2217 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2546 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2218 /// <param name="rotation">The direction in which this avatar should now face. 2547 /// <param name="rotation">The direction in which this avatar should now face.
2219 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2548 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2220 { 2549 {
2221 if (m_isChildAgent) 2550 if (m_isChildAgent)
2222 { 2551 {
@@ -2257,15 +2586,26 @@ namespace OpenSim.Region.Framework.Scenes
2257 Rotation = rotation; 2586 Rotation = rotation;
2258 Vector3 direc = vec * rotation; 2587 Vector3 direc = vec * rotation;
2259 direc.Normalize(); 2588 direc.Normalize();
2589 PhysicsActor actor = m_physicsActor;
2590
2591 if (actor.Flying != m_flyingOld) // add for fly velocity control
2592 {
2593 m_flyingOld = actor.Flying; // add for fly velocity control
2594 if (!actor.Flying) m_wasFlying = true; // add for fly velocity control
2595 }
2596
2597 if (m_physicsActor.IsColliding == true) m_wasFlying = false; // add for fly velocity control
2598
2599 if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up.
2260 2600
2261 direc *= 0.03f * 128f * m_speedModifier; 2601 direc *= 0.03f * 128f * m_speedModifier;
2262 2602
2263 PhysicsActor actor = m_physicsActor;
2264 if (actor != null) 2603 if (actor != null)
2265 { 2604 {
2266 if (actor.Flying) 2605 if (actor.Flying)
2267 { 2606 {
2268 direc *= 4.0f; 2607// rm speed mod direc *= 4.0f;
2608 direc *= 5.2f; // for speed mod
2269 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 2609 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
2270 //bool colliding = (m_physicsActor.IsColliding==true); 2610 //bool colliding = (m_physicsActor.IsColliding==true);
2271 //if (controlland) 2611 //if (controlland)
@@ -2278,22 +2618,34 @@ namespace OpenSim.Region.Framework.Scenes
2278 // m_log.Info("[AGENT]: Stop FLying"); 2618 // m_log.Info("[AGENT]: Stop FLying");
2279 //} 2619 //}
2280 } 2620 }
2621 if (Animator.m_falling && m_wasFlying) // if falling from flying, disable motion add
2622 {
2623 direc *= 0.0f;
2624 }
2625 /* This jumping section removed to SPA
2281 else if (!actor.Flying && actor.IsColliding) 2626 else if (!actor.Flying && actor.IsColliding)
2282 { 2627 {
2283 if (direc.Z > 2.0f) 2628 if (direc.Z > 2.0f)
2284 { 2629 {
2285 direc.Z *= 3.0f; 2630 if(m_animator.m_animTickJump == -1)
2286 2631 {
2287 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2632 direc.Z *= 3.0f; // jump
2288 Animator.TrySetMovementAnimation("PREJUMP"); 2633 }
2289 Animator.TrySetMovementAnimation("JUMP"); 2634 else
2635 {
2636 direc.Z *= 0.1f; // prejump
2637 }
2638 / * Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs
2639 Animator.TrySetMovementAnimation("PREJUMP");
2640 Animator.TrySetMovementAnimation("JUMP");
2641 * /
2290 } 2642 }
2291 } 2643 } */
2292 } 2644 }
2293 2645
2294 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2646 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2295 m_forceToApply = direc; 2647 m_forceToApply = direc;
2296 2648 m_isNudging = Nudging;
2297 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2649 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2298 } 2650 }
2299 2651
@@ -2308,7 +2660,7 @@ namespace OpenSim.Region.Framework.Scenes
2308 const float POSITION_TOLERANCE = 0.05f; 2660 const float POSITION_TOLERANCE = 0.05f;
2309 //const int TIME_MS_TOLERANCE = 3000; 2661 //const int TIME_MS_TOLERANCE = 3000;
2310 2662
2311 SendPrimUpdates(); 2663
2312 2664
2313 if (m_isChildAgent == false) 2665 if (m_isChildAgent == false)
2314 { 2666 {
@@ -2338,6 +2690,9 @@ namespace OpenSim.Region.Framework.Scenes
2338 CheckForBorderCrossing(); 2690 CheckForBorderCrossing();
2339 CheckForSignificantMovement(); // sends update to the modules. 2691 CheckForSignificantMovement(); // sends update to the modules.
2340 } 2692 }
2693
2694 //Sending prim updates AFTER the avatar terse updates are sent
2695 SendPrimUpdates();
2341 } 2696 }
2342 2697
2343 #endregion 2698 #endregion
@@ -3086,6 +3441,7 @@ namespace OpenSim.Region.Framework.Scenes
3086 m_callbackURI = cAgent.CallbackURI; 3441 m_callbackURI = cAgent.CallbackURI;
3087 3442
3088 m_pos = cAgent.Position; 3443 m_pos = cAgent.Position;
3444
3089 m_velocity = cAgent.Velocity; 3445 m_velocity = cAgent.Velocity;
3090 m_CameraCenter = cAgent.Center; 3446 m_CameraCenter = cAgent.Center;
3091 m_CameraAtAxis = cAgent.AtAxis; 3447 m_CameraAtAxis = cAgent.AtAxis;
@@ -3204,17 +3560,46 @@ namespace OpenSim.Region.Framework.Scenes
3204 /// </summary> 3560 /// </summary>
3205 public override void UpdateMovement() 3561 public override void UpdateMovement()
3206 { 3562 {
3207 if (m_forceToApply.HasValue) 3563 if (Animator!=null) // add for jumping
3208 { 3564 { // add for jumping
3209 Vector3 force = m_forceToApply.Value; 3565 // if (!m_animator.m_jumping) // add for jumping
3566 // { // add for jumping
3210 3567
3211 m_updateflag = true; 3568 if (m_forceToApply.HasValue) // this section realigned
3212// movementvector = force; 3569 {
3213 Velocity = force;
3214 3570
3215 m_forceToApply = null; 3571 Vector3 force = m_forceToApply.Value;
3216 } 3572 m_updateflag = true;
3217 } 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 }
3600 // } // end realign
3601 } // add for jumping
3602 } // add for jumping
3218 3603
3219 /// <summary> 3604 /// <summary>
3220 /// Adds a physical representation of the avatar to the Physics plugin 3605 /// Adds a physical representation of the avatar to the Physics plugin
@@ -3228,10 +3613,8 @@ namespace OpenSim.Region.Framework.Scenes
3228 3613
3229 Vector3 pVec = AbsolutePosition; 3614 Vector3 pVec = AbsolutePosition;
3230 3615
3231 // Old bug where the height was in centimeters instead of meters
3232 m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, 3616 m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec,
3233 new Vector3(0f, 0f, m_appearance.AvatarHeight), isFlying); 3617 new Vector3(0f, 0f, m_appearance.AvatarHeight), isFlying);
3234
3235 scene.AddPhysicsActorTaint(m_physicsActor); 3618 scene.AddPhysicsActorTaint(m_physicsActor);
3236 //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3619 //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3237 m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3620 m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
@@ -3255,18 +3638,29 @@ namespace OpenSim.Region.Framework.Scenes
3255 { 3638 {
3256 if (e == null) 3639 if (e == null)
3257 return; 3640 return;
3258 3641
3259 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3642 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3260 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3261 // as of this comment the interval is set in AddToPhysicalScene 3643 // as of this comment the interval is set in AddToPhysicalScene
3262 if (Animator!=null) 3644 if (Animator!=null)
3263 Animator.UpdateMovementAnimations(); 3645 {
3646 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3647 { // else its will lock out other animation changes, like ground sit.
3648 Animator.UpdateMovementAnimations();
3649 m_updateCount--;
3650 }
3651 }
3264 3652
3265 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3653 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3266 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3654 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3267 3655
3268 CollisionPlane = Vector4.UnitW; 3656 CollisionPlane = Vector4.UnitW;
3269 3657
3658 if (m_lastColCount != coldata.Count)
3659 {
3660 m_updateCount = UPDATE_COUNT;
3661 m_lastColCount = coldata.Count;
3662 }
3663
3270 if (coldata.Count != 0 && Animator != null) 3664 if (coldata.Count != 0 && Animator != null)
3271 { 3665 {
3272 switch (Animator.CurrentMovementAnimation) 3666 switch (Animator.CurrentMovementAnimation)
@@ -3296,6 +3690,148 @@ namespace OpenSim.Region.Framework.Scenes
3296 } 3690 }
3297 } 3691 }
3298 3692
3693 List<uint> thisHitColliders = new List<uint>();
3694 List<uint> endedColliders = new List<uint>();
3695 List<uint> startedColliders = new List<uint>();
3696
3697 foreach (uint localid in coldata.Keys)
3698 {
3699 thisHitColliders.Add(localid);
3700 if (!m_lastColliders.Contains(localid))
3701 {
3702 startedColliders.Add(localid);
3703 }
3704 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
3705 }
3706
3707 // calculate things that ended colliding
3708 foreach (uint localID in m_lastColliders)
3709 {
3710 if (!thisHitColliders.Contains(localID))
3711 {
3712 endedColliders.Add(localID);
3713 }
3714 }
3715 //add the items that started colliding this time to the last colliders list.
3716 foreach (uint localID in startedColliders)
3717 {
3718 m_lastColliders.Add(localID);
3719 }
3720 // remove things that ended colliding from the last colliders list
3721 foreach (uint localID in endedColliders)
3722 {
3723 m_lastColliders.Remove(localID);
3724 }
3725
3726 // do event notification
3727 if (startedColliders.Count > 0)
3728 {
3729 ColliderArgs StartCollidingMessage = new ColliderArgs();
3730 List<DetectedObject> colliding = new List<DetectedObject>();
3731 foreach (uint localId in startedColliders)
3732 {
3733 if (localId == 0)
3734 continue;
3735
3736 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3737 string data = "";
3738 if (obj != null)
3739 {
3740 DetectedObject detobj = new DetectedObject();
3741 detobj.keyUUID = obj.UUID;
3742 detobj.nameStr = obj.Name;
3743 detobj.ownerUUID = obj.OwnerID;
3744 detobj.posVector = obj.AbsolutePosition;
3745 detobj.rotQuat = obj.GetWorldRotation();
3746 detobj.velVector = obj.Velocity;
3747 detobj.colliderType = 0;
3748 detobj.groupUUID = obj.GroupID;
3749 colliding.Add(detobj);
3750 }
3751 }
3752
3753 if (colliding.Count > 0)
3754 {
3755 StartCollidingMessage.Colliders = colliding;
3756
3757 foreach (SceneObjectGroup att in Attachments)
3758 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
3759 }
3760 }
3761
3762 if (endedColliders.Count > 0)
3763 {
3764 ColliderArgs EndCollidingMessage = new ColliderArgs();
3765 List<DetectedObject> colliding = new List<DetectedObject>();
3766 foreach (uint localId in endedColliders)
3767 {
3768 if (localId == 0)
3769 continue;
3770
3771 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3772 string data = "";
3773 if (obj != null)
3774 {
3775 DetectedObject detobj = new DetectedObject();
3776 detobj.keyUUID = obj.UUID;
3777 detobj.nameStr = obj.Name;
3778 detobj.ownerUUID = obj.OwnerID;
3779 detobj.posVector = obj.AbsolutePosition;
3780 detobj.rotQuat = obj.GetWorldRotation();
3781 detobj.velVector = obj.Velocity;
3782 detobj.colliderType = 0;
3783 detobj.groupUUID = obj.GroupID;
3784 colliding.Add(detobj);
3785 }
3786 }
3787
3788 if (colliding.Count > 0)
3789 {
3790 EndCollidingMessage.Colliders = colliding;
3791
3792 foreach (SceneObjectGroup att in Attachments)
3793 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
3794 }
3795 }
3796
3797 if (thisHitColliders.Count > 0)
3798 {
3799 ColliderArgs CollidingMessage = new ColliderArgs();
3800 List<DetectedObject> colliding = new List<DetectedObject>();
3801 foreach (uint localId in thisHitColliders)
3802 {
3803 if (localId == 0)
3804 continue;
3805
3806 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3807 string data = "";
3808 if (obj != null)
3809 {
3810 DetectedObject detobj = new DetectedObject();
3811 detobj.keyUUID = obj.UUID;
3812 detobj.nameStr = obj.Name;
3813 detobj.ownerUUID = obj.OwnerID;
3814 detobj.posVector = obj.AbsolutePosition;
3815 detobj.rotQuat = obj.GetWorldRotation();
3816 detobj.velVector = obj.Velocity;
3817 detobj.colliderType = 0;
3818 detobj.groupUUID = obj.GroupID;
3819 colliding.Add(detobj);
3820 }
3821 }
3822
3823 if (colliding.Count > 0)
3824 {
3825 CollidingMessage.Colliders = colliding;
3826
3827 lock (m_attachments)
3828 {
3829 foreach (SceneObjectGroup att in m_attachments)
3830 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
3831 }
3832 }
3833 }
3834
3299 if (m_invulnerable) 3835 if (m_invulnerable)
3300 return; 3836 return;
3301 3837
@@ -3721,6 +4257,39 @@ namespace OpenSim.Region.Framework.Scenes
3721 return; 4257 return;
3722 } 4258 }
3723 4259
4260 XmlDocument doc = new XmlDocument();
4261 string stateData = String.Empty;
4262
4263 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
4264 if (attServ != null)
4265 {
4266 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
4267 stateData = attServ.Get(ControllingClient.AgentId.ToString());
4268 if (stateData != String.Empty)
4269 {
4270 try
4271 {
4272 doc.LoadXml(stateData);
4273 }
4274 catch { }
4275 }
4276 }
4277
4278 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
4279
4280 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
4281 if (nodes.Count > 0)
4282 {
4283 foreach (XmlNode n in nodes)
4284 {
4285 XmlElement elem = (XmlElement)n;
4286 string itemID = elem.GetAttribute("ItemID");
4287 string xml = elem.InnerXml;
4288
4289 itemData[new UUID(itemID)] = xml;
4290 }
4291 }
4292
3724 List<AvatarAttachment> attachments = m_appearance.GetAttachments(); 4293 List<AvatarAttachment> attachments = m_appearance.GetAttachments();
3725 foreach (AvatarAttachment attach in attachments) 4294 foreach (AvatarAttachment attach in attachments)
3726 { 4295 {
@@ -3741,7 +4310,30 @@ namespace OpenSim.Region.Framework.Scenes
3741 4310
3742 try 4311 try
3743 { 4312 {
3744 m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p); 4313 string xmlData;
4314 XmlDocument d = new XmlDocument();
4315 UUID asset;
4316 if (itemData.TryGetValue(itemID, out xmlData))
4317 {
4318 d.LoadXml(xmlData);
4319 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID);
4320
4321 // Rez from inventory
4322 asset
4323 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d);
4324
4325 }
4326 else
4327 {
4328 // Rez from inventory (with a null doc to let
4329 // CHANGED_OWNER happen)
4330 asset
4331 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, null);
4332 }
4333
4334 m_log.InfoFormat(
4335 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2}",
4336 p, itemID, asset);
3745 } 4337 }
3746 catch (Exception e) 4338 catch (Exception e)
3747 { 4339 {
@@ -3774,6 +4366,15 @@ namespace OpenSim.Region.Framework.Scenes
3774 m_reprioritization_called = false; 4366 m_reprioritization_called = false;
3775 } 4367 }
3776 } 4368 }
4369
4370 private Vector3 Quat2Euler(Quaternion rot){
4371 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4372 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4373 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4374 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4375 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4376 return(new Vector3(x,y,z));
4377 }
3777 4378
3778 public void SaveChangedAttachments() 4379 public void SaveChangedAttachments()
3779 { 4380 {