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.cs979
1 files changed, 791 insertions, 188 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 9402f8b..dafc1af 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,7 +159,6 @@ 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;
159 164
@@ -177,7 +182,8 @@ namespace OpenSim.Region.Framework.Scenes
177 protected RegionInfo m_regionInfo; 182 protected RegionInfo m_regionInfo;
178 protected ulong crossingFromRegion; 183 protected ulong crossingFromRegion;
179 184
180 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 185 private readonly Vector3[] Dir_Vectors = new Vector3[11];
186 private bool m_isNudging = false;
181 187
182 // Position of agent's camera in world (region cordinates) 188 // Position of agent's camera in world (region cordinates)
183 protected Vector3 m_CameraCenter; 189 protected Vector3 m_CameraCenter;
@@ -202,17 +208,25 @@ namespace OpenSim.Region.Framework.Scenes
202 private bool m_autopilotMoving; 208 private bool m_autopilotMoving;
203 private Vector3 m_autoPilotTarget; 209 private Vector3 m_autoPilotTarget;
204 private bool m_sitAtAutoTarget; 210 private bool m_sitAtAutoTarget;
211 private Vector3 m_initialSitTarget = Vector3.Zero; //KF: First estimate of where to sit
205 212
206 private string m_nextSitAnimation = String.Empty; 213 private string m_nextSitAnimation = String.Empty;
207 214
208 //PauPaw:Proper PID Controler for autopilot************ 215 //PauPaw:Proper PID Controler for autopilot************
209 private bool m_moveToPositionInProgress; 216 private bool m_moveToPositionInProgress;
210 private Vector3 m_moveToPositionTarget; 217 private Vector3 m_moveToPositionTarget;
218 private Quaternion m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
211 219
212 private bool m_followCamAuto; 220 private bool m_followCamAuto;
213 221
214 private int m_movementUpdateCount; 222 private int m_movementUpdateCount;
223 private int m_lastColCount = -1; //KF: Look for Collision chnages
224 private int m_updateCount = 0; //KF: Update Anims for a while
225 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
215 private const int NumMovementsBetweenRayCast = 5; 226 private const int NumMovementsBetweenRayCast = 5;
227 private List<uint> m_lastColliders = new List<uint>();
228
229 private object m_syncRoot = new Object();
216 230
217 private bool CameraConstraintActive; 231 private bool CameraConstraintActive;
218 //private int m_moveToPositionStateStatus; 232 //private int m_moveToPositionStateStatus;
@@ -239,7 +253,9 @@ namespace OpenSim.Region.Framework.Scenes
239 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 253 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
240 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 254 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
241 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 255 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
242 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 256 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
257 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
258 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
243 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 259 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
244 } 260 }
245 261
@@ -446,9 +462,18 @@ namespace OpenSim.Region.Framework.Scenes
446 get 462 get
447 { 463 {
448 PhysicsActor actor = m_physicsActor; 464 PhysicsActor actor = m_physicsActor;
449 if (actor != null) 465// if (actor != null)
466 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting!
450 m_pos = actor.Position; 467 m_pos = actor.Position;
451 468
469 // If we're sitting, we need to update our position
470 if (m_parentID != 0)
471 {
472 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
473 if (part != null)
474 m_parentPosition = part.AbsolutePosition;
475 }
476
452 return m_parentPosition + m_pos; 477 return m_parentPosition + m_pos;
453 } 478 }
454 set 479 set
@@ -467,7 +492,8 @@ namespace OpenSim.Region.Framework.Scenes
467 } 492 }
468 } 493 }
469 494
470 m_pos = value; 495 if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting!
496 m_pos = value;
471 m_parentPosition = Vector3.Zero; 497 m_parentPosition = Vector3.Zero;
472 } 498 }
473 } 499 }
@@ -511,10 +537,39 @@ namespace OpenSim.Region.Framework.Scenes
511 } 537 }
512 } 538 }
513 539
540 public Quaternion OffsetRotation
541 {
542 get { return m_offsetRotation; }
543 set { m_offsetRotation = value; }
544 }
545
514 public Quaternion Rotation 546 public Quaternion Rotation
515 { 547 {
516 get { return m_bodyRot; } 548 get {
517 set { m_bodyRot = value; } 549 if (m_parentID != 0)
550 {
551 if (m_offsetRotation != null)
552 {
553 return m_offsetRotation;
554 }
555 else
556 {
557 return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
558 }
559
560 }
561 else
562 {
563 return m_bodyRot;
564 }
565 }
566 set {
567 m_bodyRot = value;
568 if (m_parentID != 0)
569 {
570 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
571 }
572 }
518 } 573 }
519 574
520 public Quaternion PreviousRotation 575 public Quaternion PreviousRotation
@@ -539,11 +594,21 @@ namespace OpenSim.Region.Framework.Scenes
539 594
540 private uint m_parentID; 595 private uint m_parentID;
541 596
597
598 private UUID m_linkedPrim;
599
542 public uint ParentID 600 public uint ParentID
543 { 601 {
544 get { return m_parentID; } 602 get { return m_parentID; }
545 set { m_parentID = value; } 603 set { m_parentID = value; }
546 } 604 }
605
606 public UUID LinkedPrim
607 {
608 get { return m_linkedPrim; }
609 set { m_linkedPrim = value; }
610 }
611
547 public float Health 612 public float Health
548 { 613 {
549 get { return m_health; } 614 get { return m_health; }
@@ -665,7 +730,7 @@ namespace OpenSim.Region.Framework.Scenes
665 CreateSceneViewer(); 730 CreateSceneViewer();
666 m_animator = new ScenePresenceAnimator(this); 731 m_animator = new ScenePresenceAnimator(this);
667 } 732 }
668 733
669 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() 734 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this()
670 { 735 {
671 m_rootRegionHandle = reginfo.RegionHandle; 736 m_rootRegionHandle = reginfo.RegionHandle;
@@ -697,18 +762,18 @@ namespace OpenSim.Region.Framework.Scenes
697 m_reprioritization_timer.AutoReset = false; 762 m_reprioritization_timer.AutoReset = false;
698 763
699 AdjustKnownSeeds(); 764 AdjustKnownSeeds();
700
701 // TODO: I think, this won't send anything, as we are still a child here...
702 Animator.TrySetMovementAnimation("STAND"); 765 Animator.TrySetMovementAnimation("STAND");
703
704 // we created a new ScenePresence (a new child agent) in a fresh region. 766 // we created a new ScenePresence (a new child agent) in a fresh region.
705 // Request info about all the (root) agents in this region 767 // Request info about all the (root) agents in this region
706 // Note: This won't send data *to* other clients in that region (children don't send) 768 // Note: This won't send data *to* other clients in that region (children don't send)
707 769
708// MIC: This gets called again in CompleteMovement 770// MIC: This gets called again in CompleteMovement
709 SendInitialFullUpdateToAllClients(); 771 SendInitialFullUpdateToAllClients();
710
711 RegisterToEvents(); 772 RegisterToEvents();
773 if (m_controllingClient != null)
774 {
775 m_controllingClient.ProcessPendingPackets();
776 }
712 SetDirectionVectors(); 777 SetDirectionVectors();
713 } 778 }
714 779
@@ -749,25 +814,47 @@ namespace OpenSim.Region.Framework.Scenes
749 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 814 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
750 Dir_Vectors[4] = Vector3.UnitZ; //UP 815 Dir_Vectors[4] = Vector3.UnitZ; //UP
751 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 816 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
752 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 817 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
753 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 818 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
754 Dir_Vectors[7] = -Vector3.UnitX; //BACK 819 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
820 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
821 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
755 } 822 }
756 823
757 private Vector3[] GetWalkDirectionVectors() 824 private Vector3[] GetWalkDirectionVectors()
758 { 825 {
759 Vector3[] vector = new Vector3[9]; 826 Vector3[] vector = new Vector3[11];
760 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 827 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
761 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 828 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
762 vector[2] = Vector3.UnitY; //LEFT 829 vector[2] = Vector3.UnitY; //LEFT
763 vector[3] = -Vector3.UnitY; //RIGHT 830 vector[3] = -Vector3.UnitY; //RIGHT
764 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 831 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
765 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 832 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
766 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 833 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
767 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 834 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
768 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 835 vector[8] = Vector3.UnitY; //LEFT_NUDGE
836 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
837 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
769 return vector; 838 return vector;
770 } 839 }
840
841 private bool[] GetDirectionIsNudge()
842 {
843 bool[] isNudge = new bool[11];
844 isNudge[0] = false; //FORWARD
845 isNudge[1] = false; //BACK
846 isNudge[2] = false; //LEFT
847 isNudge[3] = false; //RIGHT
848 isNudge[4] = false; //UP
849 isNudge[5] = false; //DOWN
850 isNudge[6] = true; //FORWARD_NUDGE
851 isNudge[7] = true; //BACK_NUDGE
852 isNudge[8] = true; //LEFT_NUDGE
853 isNudge[9] = true; //RIGHT_NUDGE
854 isNudge[10] = true; //DOWN_Nudge
855 return isNudge;
856 }
857
771 858
772 #endregion 859 #endregion
773 860
@@ -829,6 +916,52 @@ namespace OpenSim.Region.Framework.Scenes
829 pos.Y = crossedBorder.BorderLine.Z - 1; 916 pos.Y = crossedBorder.BorderLine.Z - 1;
830 } 917 }
831 918
919 //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet.
920 //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent,
921 //they'll bypass the landing point. But I can't think of any decent way of fixing this.
922 if (KnownChildRegionHandles.Count == 0)
923 {
924 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
925 if (land != null)
926 {
927 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
928 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)
929 {
930 pos = land.LandData.UserLocation;
931 }
932 }
933 }
934
935 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0)
936 {
937 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128);
938
939 if (pos.X < 0)
940 {
941 emergencyPos.X = (int)Constants.RegionSize + pos.X;
942 if (!(pos.Y < 0))
943 emergencyPos.Y = pos.Y;
944 if (!(pos.Z < 0))
945 emergencyPos.Z = pos.Z;
946 }
947 if (pos.Y < 0)
948 {
949 emergencyPos.Y = (int)Constants.RegionSize + pos.Y;
950 if (!(pos.X < 0))
951 emergencyPos.X = pos.X;
952 if (!(pos.Z < 0))
953 emergencyPos.Z = pos.Z;
954 }
955 if (pos.Z < 0)
956 {
957 emergencyPos.Z = 128;
958 if (!(pos.Y < 0))
959 emergencyPos.Y = pos.Y;
960 if (!(pos.X < 0))
961 emergencyPos.X = pos.X;
962 }
963 }
964
832 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 965 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
833 { 966 {
834 m_log.WarnFormat( 967 m_log.WarnFormat(
@@ -950,12 +1083,17 @@ namespace OpenSim.Region.Framework.Scenes
950 { 1083 {
951 if (PhysicsActor != null) 1084 if (PhysicsActor != null)
952 { 1085 {
953 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1086 try
954 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall; 1087 {
955 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); 1088 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
956 m_physicsActor.UnSubscribeEvents(); 1089 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall;
957 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1090 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
958 PhysicsActor = null; 1091 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1092 m_physicsActor.UnSubscribeEvents();
1093 PhysicsActor = null;
1094 }
1095 catch
1096 { }
959 } 1097 }
960 } 1098 }
961 1099
@@ -966,9 +1104,10 @@ namespace OpenSim.Region.Framework.Scenes
966 public void Teleport(Vector3 pos) 1104 public void Teleport(Vector3 pos)
967 { 1105 {
968 bool isFlying = false; 1106 bool isFlying = false;
1107
969 if (m_physicsActor != null) 1108 if (m_physicsActor != null)
970 isFlying = m_physicsActor.Flying; 1109 isFlying = m_physicsActor.Flying;
971 1110
972 RemoveFromPhysicalScene(); 1111 RemoveFromPhysicalScene();
973 Velocity = Vector3.Zero; 1112 Velocity = Vector3.Zero;
974 AbsolutePosition = pos; 1113 AbsolutePosition = pos;
@@ -980,6 +1119,7 @@ namespace OpenSim.Region.Framework.Scenes
980 } 1119 }
981 1120
982 SendTerseUpdateToAllClients(); 1121 SendTerseUpdateToAllClients();
1122
983 } 1123 }
984 1124
985 public void TeleportWithMomentum(Vector3 pos) 1125 public void TeleportWithMomentum(Vector3 pos)
@@ -1095,7 +1235,6 @@ namespace OpenSim.Region.Framework.Scenes
1095 pos.Z = ground + 1.5f; 1235 pos.Z = ground + 1.5f;
1096 AbsolutePosition = pos; 1236 AbsolutePosition = pos;
1097 } 1237 }
1098
1099 m_isChildAgent = false; 1238 m_isChildAgent = false;
1100 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 1239 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1101 MakeRootAgent(AbsolutePosition, m_flying); 1240 MakeRootAgent(AbsolutePosition, m_flying);
@@ -1193,6 +1332,7 @@ namespace OpenSim.Region.Framework.Scenes
1193 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); 1332 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902");
1194 1333
1195 m_pos = m_LastFinitePos; 1334 m_pos = m_LastFinitePos;
1335
1196 if (!m_pos.IsFinite()) 1336 if (!m_pos.IsFinite())
1197 { 1337 {
1198 m_pos.X = 127f; 1338 m_pos.X = 127f;
@@ -1259,7 +1399,6 @@ namespace OpenSim.Region.Framework.Scenes
1259 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1399 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1260 } 1400 }
1261 } 1401 }
1262
1263 lock (scriptedcontrols) 1402 lock (scriptedcontrols)
1264 { 1403 {
1265 if (scriptedcontrols.Count > 0) 1404 if (scriptedcontrols.Count > 0)
@@ -1274,6 +1413,9 @@ namespace OpenSim.Region.Framework.Scenes
1274 1413
1275 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1414 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1276 { 1415 {
1416 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1417 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1418
1277 // TODO: This doesn't prevent the user from walking yet. 1419 // TODO: This doesn't prevent the user from walking yet.
1278 // Setting parent ID would fix this, if we knew what value 1420 // Setting parent ID would fix this, if we knew what value
1279 // to use. Or we could add a m_isSitting variable. 1421 // to use. Or we could add a m_isSitting variable.
@@ -1322,12 +1464,20 @@ namespace OpenSim.Region.Framework.Scenes
1322 if (actor.Flying != oldflying) 1464 if (actor.Flying != oldflying)
1323 update_movementflag = true; 1465 update_movementflag = true;
1324 1466
1467 if (m_animator.m_jumping) // add for jumping
1468 update_movementflag = true;
1469
1325 if (q != m_bodyRot) 1470 if (q != m_bodyRot)
1326 { 1471 {
1327 m_bodyRot = q; 1472 m_bodyRot = q;
1328 update_rotation = true; 1473 update_rotation = true;
1329 } 1474 }
1330 1475
1476 //guilty until proven innocent..
1477 bool Nudging = true;
1478 //Basically, if there is at least one non-nudge control then we don't need
1479 //to worry about stopping the avatar
1480
1331 if (m_parentID == 0) 1481 if (m_parentID == 0)
1332 { 1482 {
1333 bool bAllowUpdateMoveToPosition = false; 1483 bool bAllowUpdateMoveToPosition = false;
@@ -1342,9 +1492,12 @@ namespace OpenSim.Region.Framework.Scenes
1342 else 1492 else
1343 dirVectors = Dir_Vectors; 1493 dirVectors = Dir_Vectors;
1344 1494
1345 // The fact that m_movementflag is a byte needs to be fixed 1495 bool[] isNudge = GetDirectionIsNudge();
1346 // it really should be a uint 1496
1347 uint nudgehack = 250; 1497
1498
1499
1500
1348 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1501 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1349 { 1502 {
1350 if (((uint)flags & (uint)DCF) != 0) 1503 if (((uint)flags & (uint)DCF) != 0)
@@ -1354,40 +1507,28 @@ namespace OpenSim.Region.Framework.Scenes
1354 try 1507 try
1355 { 1508 {
1356 agent_control_v3 += dirVectors[i]; 1509 agent_control_v3 += dirVectors[i];
1357 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1510 if (isNudge[i] == false)
1511 {
1512 Nudging = false;
1513 }
1358 } 1514 }
1359 catch (IndexOutOfRangeException) 1515 catch (IndexOutOfRangeException)
1360 { 1516 {
1361 // Why did I get this? 1517 // Why did I get this?
1362 } 1518 }
1363 1519
1364 if ((m_movementflag & (byte)(uint)DCF) == 0) 1520 if ((m_movementflag & (uint)DCF) == 0)
1365 { 1521 {
1366 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1367 {
1368 m_movementflag |= (byte)nudgehack;
1369 }
1370 m_movementflag += (byte)(uint)DCF; 1522 m_movementflag += (byte)(uint)DCF;
1371 update_movementflag = true; 1523 update_movementflag = true;
1372 } 1524 }
1373 } 1525 }
1374 else 1526 else
1375 { 1527 {
1376 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1528 if ((m_movementflag & (uint)DCF) != 0)
1377 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1378 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1379 ) // This or is for Nudge forward
1380 { 1529 {
1381 m_movementflag -= ((byte)(uint)DCF); 1530 m_movementflag -= (byte)(uint)DCF;
1382
1383 update_movementflag = true; 1531 update_movementflag = true;
1384 /*
1385 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1386 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1387 {
1388 m_log.Debug("Removed Hack flag");
1389 }
1390 */
1391 } 1532 }
1392 else 1533 else
1393 { 1534 {
@@ -1396,7 +1537,6 @@ namespace OpenSim.Region.Framework.Scenes
1396 } 1537 }
1397 i++; 1538 i++;
1398 } 1539 }
1399
1400 //Paupaw:Do Proper PID for Autopilot here 1540 //Paupaw:Do Proper PID for Autopilot here
1401 if (bResetMoveToPosition) 1541 if (bResetMoveToPosition)
1402 { 1542 {
@@ -1431,6 +1571,9 @@ namespace OpenSim.Region.Framework.Scenes
1431 // Ignore z component of vector 1571 // Ignore z component of vector
1432 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1572 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1433 LocalVectorToTarget2D.Normalize(); 1573 LocalVectorToTarget2D.Normalize();
1574
1575 //We're not nudging
1576 Nudging = false;
1434 agent_control_v3 += LocalVectorToTarget2D; 1577 agent_control_v3 += LocalVectorToTarget2D;
1435 1578
1436 // update avatar movement flags. the avatar coordinate system is as follows: 1579 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1521,13 +1664,13 @@ namespace OpenSim.Region.Framework.Scenes
1521 // m_log.DebugFormat( 1664 // m_log.DebugFormat(
1522 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1665 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1523 1666
1524 AddNewMovement(agent_control_v3, q); 1667 AddNewMovement(agent_control_v3, q, Nudging);
1525 1668
1526 1669
1527 } 1670 }
1528 } 1671 }
1529 1672
1530 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1673 if (update_movementflag && !SitGround)
1531 Animator.UpdateMovementAnimations(); 1674 Animator.UpdateMovementAnimations();
1532 1675
1533 m_scene.EventManager.TriggerOnClientMovement(this); 1676 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1542,7 +1685,6 @@ namespace OpenSim.Region.Framework.Scenes
1542 m_sitAtAutoTarget = false; 1685 m_sitAtAutoTarget = false;
1543 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1686 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1544 //proxy.PCode = (byte)PCode.ParticleSystem; 1687 //proxy.PCode = (byte)PCode.ParticleSystem;
1545
1546 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1688 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1547 proxyObjectGroup.AttachToScene(m_scene); 1689 proxyObjectGroup.AttachToScene(m_scene);
1548 1690
@@ -1584,7 +1726,7 @@ namespace OpenSim.Region.Framework.Scenes
1584 } 1726 }
1585 m_moveToPositionInProgress = true; 1727 m_moveToPositionInProgress = true;
1586 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1728 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1587 } 1729 }
1588 catch (Exception ex) 1730 catch (Exception ex)
1589 { 1731 {
1590 //Why did I get this error? 1732 //Why did I get this error?
@@ -1606,7 +1748,7 @@ namespace OpenSim.Region.Framework.Scenes
1606 Velocity = Vector3.Zero; 1748 Velocity = Vector3.Zero;
1607 SendFullUpdateToAllClients(); 1749 SendFullUpdateToAllClients();
1608 1750
1609 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1751 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1610 } 1752 }
1611 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1753 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1612 m_requestedSitTargetUUID = UUID.Zero; 1754 m_requestedSitTargetUUID = UUID.Zero;
@@ -1643,50 +1785,85 @@ namespace OpenSim.Region.Framework.Scenes
1643 1785
1644 if (m_parentID != 0) 1786 if (m_parentID != 0)
1645 { 1787 {
1646 m_log.Debug("StandupCode Executed"); 1788 SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID);
1647 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1648 if (part != null) 1789 if (part != null)
1649 { 1790 {
1791 part.TaskInventory.LockItemsForRead(true);
1650 TaskInventoryDictionary taskIDict = part.TaskInventory; 1792 TaskInventoryDictionary taskIDict = part.TaskInventory;
1651 if (taskIDict != null) 1793 if (taskIDict != null)
1652 { 1794 {
1653 lock (taskIDict) 1795 foreach (UUID taskID in taskIDict.Keys)
1654 { 1796 {
1655 foreach (UUID taskID in taskIDict.Keys) 1797 UnRegisterControlEventsToScript(LocalId, taskID);
1656 { 1798 taskIDict[taskID].PermsMask &= ~(
1657 UnRegisterControlEventsToScript(LocalId, taskID); 1799 2048 | //PERMISSION_CONTROL_CAMERA
1658 taskIDict[taskID].PermsMask &= ~( 1800 4); // PERMISSION_TAKE_CONTROLS
1659 2048 | //PERMISSION_CONTROL_CAMERA
1660 4); // PERMISSION_TAKE_CONTROLS
1661 }
1662 } 1801 }
1663
1664 } 1802 }
1803 part.TaskInventory.LockItemsForRead(false);
1665 // Reset sit target. 1804 // Reset sit target.
1666 if (part.GetAvatarOnSitTarget() == UUID) 1805 if (part.GetAvatarOnSitTarget() == UUID)
1667 part.SetAvatarOnSitTarget(UUID.Zero); 1806 part.SetAvatarOnSitTarget(UUID.Zero);
1668
1669 m_parentPosition = part.GetWorldPosition(); 1807 m_parentPosition = part.GetWorldPosition();
1670 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1808 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1671 } 1809 }
1810 // part.GetWorldRotation() is the rotation of the object being sat on
1811 // Rotation is the sittiing Av's rotation
1812
1813 Quaternion partRot;
1814// if (part.LinkNum == 1)
1815// { // Root prim of linkset
1816// partRot = part.ParentGroup.RootPart.RotationOffset;
1817// }
1818// else
1819// { // single or child prim
1820
1821// }
1822 if (part == null) //CW: Part may be gone. llDie() for example.
1823 {
1824 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1825 }
1826 else
1827 {
1828 partRot = part.GetWorldRotation();
1829 }
1830
1831 Quaternion partIRot = Quaternion.Inverse(partRot);
1832
1833 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1834 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1672 1835
1836
1673 if (m_physicsActor == null) 1837 if (m_physicsActor == null)
1674 { 1838 {
1675 AddToPhysicalScene(false); 1839 AddToPhysicalScene(false);
1676 } 1840 }
1677 1841 //CW: If the part isn't null then we can set the current position
1678 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1842 if (part != null)
1679 m_parentPosition = Vector3.Zero; 1843 {
1680 1844 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + ((m_pos - part.OffsetPosition) * partRot); // + av sit offset!
1681 m_parentID = 0; 1845 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1846 part.IsOccupied = false;
1847 part.ParentGroup.DeleteAvatar(ControllingClient.AgentId);
1848 }
1849 else
1850 {
1851 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1852 AbsolutePosition = m_lastWorldPosition;
1853 }
1854
1855 m_parentPosition = Vector3.Zero;
1856 m_parentID = 0;
1857 m_linkedPrim = UUID.Zero;
1858 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1682 SendFullUpdateToAllClients(); 1859 SendFullUpdateToAllClients();
1683 m_requestedSitTargetID = 0; 1860 m_requestedSitTargetID = 0;
1861
1684 if ((m_physicsActor != null) && (m_avHeight > 0)) 1862 if ((m_physicsActor != null) && (m_avHeight > 0))
1685 { 1863 {
1686 SetHeight(m_avHeight); 1864 SetHeight(m_avHeight);
1687 } 1865 }
1688 } 1866 }
1689
1690 Animator.TrySetMovementAnimation("STAND"); 1867 Animator.TrySetMovementAnimation("STAND");
1691 } 1868 }
1692 1869
@@ -1717,13 +1894,9 @@ namespace OpenSim.Region.Framework.Scenes
1717 Vector3 avSitOffSet = part.SitTargetPosition; 1894 Vector3 avSitOffSet = part.SitTargetPosition;
1718 Quaternion avSitOrientation = part.SitTargetOrientation; 1895 Quaternion avSitOrientation = part.SitTargetOrientation;
1719 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1896 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1720 1897 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1721 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1898 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1722 bool SitTargetisSet = 1899 if (SitTargetisSet && !SitTargetOccupied)
1723 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1724 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1725
1726 if (SitTargetisSet && SitTargetUnOccupied)
1727 { 1900 {
1728 //switch the target to this prim 1901 //switch the target to this prim
1729 return part; 1902 return part;
@@ -1737,84 +1910,164 @@ namespace OpenSim.Region.Framework.Scenes
1737 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1910 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1738 { 1911 {
1739 bool autopilot = true; 1912 bool autopilot = true;
1913 Vector3 autopilotTarget = new Vector3();
1914 Quaternion sitOrientation = Quaternion.Identity;
1740 Vector3 pos = new Vector3(); 1915 Vector3 pos = new Vector3();
1741 Quaternion sitOrientation = pSitOrientation;
1742 Vector3 cameraEyeOffset = Vector3.Zero; 1916 Vector3 cameraEyeOffset = Vector3.Zero;
1743 Vector3 cameraAtOffset = Vector3.Zero; 1917 Vector3 cameraAtOffset = Vector3.Zero;
1744 bool forceMouselook = false; 1918 bool forceMouselook = false;
1745 1919
1746 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1920 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1747 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1921 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1748 if (part != null) 1922 if (part == null) return;
1749 { 1923
1750 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1924 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1751 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1925 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1752 1926
1753 // Is a sit target available? 1927 // part is the prim to sit on
1754 Vector3 avSitOffSet = part.SitTargetPosition; 1928 // offset is the world-ref vector distance from that prim center to the click-spot
1755 Quaternion avSitOrientation = part.SitTargetOrientation; 1929 // UUID is the UUID of the Avatar doing the clicking
1756 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1930
1757 1931 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1758 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1932
1759 bool SitTargetisSet = 1933 // Is a sit target available?
1760 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1934 Vector3 avSitOffSet = part.SitTargetPosition;
1761 ( 1935 Quaternion avSitOrientation = part.SitTargetOrientation;
1762 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1936
1763 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1937 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1764 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1938 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1765 ) 1939 Quaternion partRot;
1766 )); 1940// if (part.LinkNum == 1)
1767 1941// { // Root prim of linkset
1768 if (SitTargetisSet && SitTargetUnOccupied) 1942// partRot = part.ParentGroup.RootPart.RotationOffset;
1769 { 1943// }
1770 part.SetAvatarOnSitTarget(UUID); 1944// else
1771 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1945// { // single or child prim
1772 sitOrientation = avSitOrientation; 1946 partRot = part.GetWorldRotation();
1773 autopilot = false; 1947// }
1774 } 1948 Quaternion partIRot = Quaternion.Inverse(partRot);
1775 1949//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1776 pos = part.AbsolutePosition + offset; 1950 // Sit analysis rewritten by KF 091125
1777 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1951 if (SitTargetisSet) // scipted sit
1778 //{ 1952 {
1779 // offset = pos; 1953 if (!part.IsOccupied)
1780 //autopilot = false; 1954 {
1781 //} 1955//Console.WriteLine("Scripted, unoccupied");
1782 if (m_physicsActor != null) 1956 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1783 { 1957 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1784 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1958
1785 // We can remove the physicsActor until they stand up. 1959 Quaternion nrot = avSitOrientation;
1786 m_sitAvatarHeight = m_physicsActor.Size.Z; 1960 if (!part.IsRoot)
1787
1788 if (autopilot)
1789 { 1961 {
1790 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1962 nrot = part.RotationOffset * avSitOrientation;
1791 {
1792 autopilot = false;
1793
1794 RemoveFromPhysicalScene();
1795 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
1796 }
1797 } 1963 }
1798 else 1964 sitOrientation = nrot; // Change rotatione to the scripted one
1965 OffsetRotation = nrot;
1966 autopilot = false; // Jump direct to scripted llSitPos()
1967 }
1968 else
1969 {
1970//Console.WriteLine("Scripted, occupied");
1971 return;
1972 }
1973 }
1974 else // Not Scripted
1975 {
1976 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
1977 {
1978 // large prim & offset, ignore if other Avs sitting
1979// offset.Z -= 0.05f;
1980 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
1981 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
1982
1983//Console.WriteLine(" offset ={0}", offset);
1984//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
1985//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
1986
1987 }
1988 else // small offset
1989 {
1990//Console.WriteLine("Small offset");
1991 if (!part.IsOccupied)
1992 {
1993 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
1994 autopilotTarget = part.AbsolutePosition;
1995//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget);
1996 }
1997 else return; // occupied small
1998 } // end large/small
1999 } // end Scripted/not
2000 cameraAtOffset = part.GetCameraAtOffset();
2001 cameraEyeOffset = part.GetCameraEyeOffset();
2002 forceMouselook = part.GetForceMouselook();
2003 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
2004 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
2005
2006 if (m_physicsActor != null)
2007 {
2008 // If we're not using the client autopilot, we're immediately warping the avatar to the location
2009 // We can remove the physicsActor until they stand up.
2010 m_sitAvatarHeight = m_physicsActor.Size.Z;
2011 if (autopilot)
2012 { // its not a scripted sit
2013// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
2014 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 256.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 256.0f) )
1799 { 2015 {
2016 autopilot = false; // close enough
2017 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2018 Not using the part's position because returning the AV to the last known standing
2019 position is likely to be more friendly, isn't it? */
1800 RemoveFromPhysicalScene(); 2020 RemoveFromPhysicalScene();
1801 } 2021 Velocity = Vector3.Zero;
2022 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
2023 } // else the autopilot will get us close
2024 }
2025 else
2026 { // its a scripted sit
2027 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2028 I *am* using the part's position this time because we have no real idea how far away
2029 the avatar is from the sit target. */
2030 RemoveFromPhysicalScene();
2031 Velocity = Vector3.Zero;
1802 } 2032 }
1803
1804 cameraAtOffset = part.GetCameraAtOffset();
1805 cameraEyeOffset = part.GetCameraEyeOffset();
1806 forceMouselook = part.GetForceMouselook();
1807 } 2033 }
1808 2034 else return; // physactor is null!
1809 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 2035
1810 m_requestedSitTargetUUID = targetID; 2036 Vector3 offsetr; // = offset * partIRot;
2037 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
2038 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
2039 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
2040 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
2041 //offsetr = offset * partIRot;
2042//
2043 // else
2044 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
2045 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
2046 // (offset * partRot);
2047 // }
2048
2049//Console.WriteLine(" ");
2050//Console.WriteLine("link number ={0}", part.LinkNum);
2051//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
2052//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
2053//Console.WriteLine("Click offst ={0}", offset);
2054//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
2055//Console.WriteLine("offsetr ={0}", offsetr);
2056//Console.WriteLine("Camera At ={0}", cameraAtOffset);
2057//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
2058
2059 //NOTE: SendSitResponse should be relative to the GROUP *NOT* THE PRIM if we're sitting on a child
2060 ControllingClient.SendSitResponse(part.ParentGroup.UUID, ((offset * part.RotationOffset) + part.OffsetPosition), sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
2061
2062 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1811 // This calls HandleAgentSit twice, once from here, and the client calls 2063 // This calls HandleAgentSit twice, once from here, and the client calls
1812 // HandleAgentSit itself after it gets to the location 2064 // HandleAgentSit itself after it gets to the location
1813 // It doesn't get to the location until we've moved them there though 2065 // It doesn't get to the location until we've moved them there though
1814 // which happens in HandleAgentSit :P 2066 // which happens in HandleAgentSit :P
1815 m_autopilotMoving = autopilot; 2067 m_autopilotMoving = autopilot;
1816 m_autoPilotTarget = pos; 2068 m_autoPilotTarget = autopilotTarget;
1817 m_sitAtAutoTarget = autopilot; 2069 m_sitAtAutoTarget = autopilot;
2070 m_initialSitTarget = autopilotTarget;
1818 if (!autopilot) 2071 if (!autopilot)
1819 HandleAgentSit(remoteClient, UUID); 2072 HandleAgentSit(remoteClient, UUID);
1820 } 2073 }
@@ -2109,47 +2362,130 @@ namespace OpenSim.Region.Framework.Scenes
2109 { 2362 {
2110 if (part != null) 2363 if (part != null)
2111 { 2364 {
2365//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2112 if (part.GetAvatarOnSitTarget() == UUID) 2366 if (part.GetAvatarOnSitTarget() == UUID)
2113 { 2367 {
2368//Console.WriteLine("Scripted Sit");
2369 // Scripted sit
2114 Vector3 sitTargetPos = part.SitTargetPosition; 2370 Vector3 sitTargetPos = part.SitTargetPosition;
2115 Quaternion sitTargetOrient = part.SitTargetOrientation; 2371 Quaternion sitTargetOrient = part.SitTargetOrientation;
2116
2117 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2118 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2119
2120 //Quaternion result = (sitTargetOrient * vq) * nq;
2121
2122 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2372 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2123 m_pos += SIT_TARGET_ADJUSTMENT; 2373 m_pos += SIT_TARGET_ADJUSTMENT;
2374 if (!part.IsRoot)
2375 {
2376 m_pos *= part.RotationOffset;
2377 }
2124 m_bodyRot = sitTargetOrient; 2378 m_bodyRot = sitTargetOrient;
2125 //Rotation = sitTargetOrient;
2126 m_parentPosition = part.AbsolutePosition; 2379 m_parentPosition = part.AbsolutePosition;
2127 2380 part.IsOccupied = true;
2128 //SendTerseUpdateToAllClients(); 2381 part.ParentGroup.AddAvatar(agentID);
2129 } 2382 }
2130 else 2383 else
2131 { 2384 {
2132 m_pos -= part.AbsolutePosition; 2385 // if m_avUnscriptedSitPos is zero then Av sits above center
2386 // Else Av sits at m_avUnscriptedSitPos
2387
2388 // Non-scripted sit by Kitto Flora 21Nov09
2389 // Calculate angle of line from prim to Av
2390 Quaternion partIRot;
2391// if (part.LinkNum == 1)
2392// { // Root prim of linkset
2393// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2394// }
2395// else
2396// { // single or child prim
2397 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2398// }
2399 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2400 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2401 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2402 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2403 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2404 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2405 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2406 // Av sits at world euler <0,0, z>, translated by part rotation
2407 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2408
2133 m_parentPosition = part.AbsolutePosition; 2409 m_parentPosition = part.AbsolutePosition;
2134 } 2410 part.IsOccupied = true;
2411 part.ParentGroup.AddAvatar(agentID);
2412 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2413 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2414 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2415 m_avUnscriptedSitPos; // adds click offset, if any
2416 //Set up raytrace to find top surface of prim
2417 Vector3 size = part.Scale;
2418 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2419 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2420 Vector3 down = new Vector3(0f, 0f, -1f);
2421//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2422 m_scene.PhysicsScene.RaycastWorld(
2423 start, // Vector3 position,
2424 down, // Vector3 direction,
2425 mag, // float length,
2426 SitAltitudeCallback); // retMethod
2427 } // end scripted/not
2135 } 2428 }
2136 else 2429 else // no Av
2137 { 2430 {
2138 return; 2431 return;
2139 } 2432 }
2140 } 2433 }
2141 m_parentID = m_requestedSitTargetID;
2142 2434
2435 //We want our offsets to reference the root prim, not the child we may have sat on
2436 if (!part.IsRoot)
2437 {
2438 m_parentID = part.ParentGroup.RootPart.LocalId;
2439 m_pos += part.OffsetPosition;
2440 }
2441 else
2442 {
2443 m_parentID = m_requestedSitTargetID;
2444 }
2445
2446 m_linkedPrim = part.UUID;
2447 if (part.GetAvatarOnSitTarget() != UUID)
2448 {
2449 m_offsetRotation = m_offsetRotation / part.RotationOffset;
2450 }
2143 Velocity = Vector3.Zero; 2451 Velocity = Vector3.Zero;
2144 RemoveFromPhysicalScene(); 2452 RemoveFromPhysicalScene();
2145
2146 Animator.TrySetMovementAnimation(sitAnimation); 2453 Animator.TrySetMovementAnimation(sitAnimation);
2147 SendFullUpdateToAllClients(); 2454 SendFullUpdateToAllClients();
2148 // This may seem stupid, but Our Full updates don't send avatar rotation :P 2455 SendTerseUpdateToAllClients();
2149 // So we're also sending a terse update (which has avatar rotation)
2150 // [Update] We do now.
2151 //SendTerseUpdateToAllClients();
2152 } 2456 }
2457
2458 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2459 {
2460 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2461 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2462 if(hitYN)
2463 {
2464 // m_pos = Av offset from prim center to make look like on center
2465 // m_parentPosition = Actual center pos of prim
2466 // collisionPoint = spot on prim where we want to sit
2467 // collisionPoint.Z = global sit surface height
2468 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2469 Quaternion partIRot;
2470// if (part.LinkNum == 1)
2471/// { // Root prim of linkset
2472// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2473// }
2474// else
2475// { // single or child prim
2476 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2477// }
2478 if (m_initialSitTarget != null)
2479 {
2480 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2481 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2482 //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2483 m_pos += offset;
2484 // ControllingClient.SendClearFollowCamProperties(part.UUID);
2485 }
2486
2487 }
2488 } // End SitAltitudeCallback KF.
2153 2489
2154 /// <summary> 2490 /// <summary>
2155 /// Event handler for the 'Always run' setting on the client 2491 /// Event handler for the 'Always run' setting on the client
@@ -2179,7 +2515,7 @@ namespace OpenSim.Region.Framework.Scenes
2179 /// </summary> 2515 /// </summary>
2180 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2516 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2181 /// <param name="rotation">The direction in which this avatar should now face. 2517 /// <param name="rotation">The direction in which this avatar should now face.
2182 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2518 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2183 { 2519 {
2184 if (m_isChildAgent) 2520 if (m_isChildAgent)
2185 { 2521 {
@@ -2220,15 +2556,18 @@ namespace OpenSim.Region.Framework.Scenes
2220 Rotation = rotation; 2556 Rotation = rotation;
2221 Vector3 direc = vec * rotation; 2557 Vector3 direc = vec * rotation;
2222 direc.Normalize(); 2558 direc.Normalize();
2559 PhysicsActor actor = m_physicsActor;
2560 if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up.
2223 2561
2224 direc *= 0.03f * 128f * m_speedModifier; 2562 direc *= 0.03f * 128f * m_speedModifier;
2225 2563
2226 PhysicsActor actor = m_physicsActor;
2227 if (actor != null) 2564 if (actor != null)
2228 { 2565 {
2229 if (actor.Flying) 2566// rm falling if (actor.Flying)
2567 if ((actor.Flying) || Animator.m_falling) // add for falling lateral speed
2230 { 2568 {
2231 direc *= 4.0f; 2569// rm speed mod direc *= 4.0f;
2570 direc *= 5.2f; // for speed mod
2232 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 2571 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
2233 //bool colliding = (m_physicsActor.IsColliding==true); 2572 //bool colliding = (m_physicsActor.IsColliding==true);
2234 //if (controlland) 2573 //if (controlland)
@@ -2241,22 +2580,30 @@ namespace OpenSim.Region.Framework.Scenes
2241 // m_log.Info("[AGENT]: Stop FLying"); 2580 // m_log.Info("[AGENT]: Stop FLying");
2242 //} 2581 //}
2243 } 2582 }
2583 /* This jumping section removed to SPA
2244 else if (!actor.Flying && actor.IsColliding) 2584 else if (!actor.Flying && actor.IsColliding)
2245 { 2585 {
2246 if (direc.Z > 2.0f) 2586 if (direc.Z > 2.0f)
2247 { 2587 {
2248 direc.Z *= 3.0f; 2588 if(m_animator.m_animTickJump == -1)
2249 2589 {
2250 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2590 direc.Z *= 3.0f; // jump
2251 Animator.TrySetMovementAnimation("PREJUMP"); 2591 }
2252 Animator.TrySetMovementAnimation("JUMP"); 2592 else
2593 {
2594 direc.Z *= 0.1f; // prejump
2595 }
2596 / * Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs
2597 Animator.TrySetMovementAnimation("PREJUMP");
2598 Animator.TrySetMovementAnimation("JUMP");
2599 * /
2253 } 2600 }
2254 } 2601 } */
2255 } 2602 }
2256 2603
2257 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2604 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2258 m_forceToApply = direc; 2605 m_forceToApply = direc;
2259 2606 m_isNudging = Nudging;
2260 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2607 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2261 } 2608 }
2262 2609
@@ -2271,7 +2618,7 @@ namespace OpenSim.Region.Framework.Scenes
2271 const float POSITION_TOLERANCE = 0.05f; 2618 const float POSITION_TOLERANCE = 0.05f;
2272 //const int TIME_MS_TOLERANCE = 3000; 2619 //const int TIME_MS_TOLERANCE = 3000;
2273 2620
2274 SendPrimUpdates(); 2621
2275 2622
2276 if (m_isChildAgent == false) 2623 if (m_isChildAgent == false)
2277 { 2624 {
@@ -2301,6 +2648,9 @@ namespace OpenSim.Region.Framework.Scenes
2301 CheckForBorderCrossing(); 2648 CheckForBorderCrossing();
2302 CheckForSignificantMovement(); // sends update to the modules. 2649 CheckForSignificantMovement(); // sends update to the modules.
2303 } 2650 }
2651
2652 //Sending prim updates AFTER the avatar terse updates are sent
2653 SendPrimUpdates();
2304 } 2654 }
2305 2655
2306 #endregion 2656 #endregion
@@ -3048,6 +3398,7 @@ namespace OpenSim.Region.Framework.Scenes
3048 m_callbackURI = cAgent.CallbackURI; 3398 m_callbackURI = cAgent.CallbackURI;
3049 3399
3050 m_pos = cAgent.Position; 3400 m_pos = cAgent.Position;
3401
3051 m_velocity = cAgent.Velocity; 3402 m_velocity = cAgent.Velocity;
3052 m_CameraCenter = cAgent.Center; 3403 m_CameraCenter = cAgent.Center;
3053 //m_avHeight = cAgent.Size.Z; 3404 //m_avHeight = cAgent.Size.Z;
@@ -3161,17 +3512,46 @@ namespace OpenSim.Region.Framework.Scenes
3161 /// </summary> 3512 /// </summary>
3162 public override void UpdateMovement() 3513 public override void UpdateMovement()
3163 { 3514 {
3164 if (m_forceToApply.HasValue) 3515 if (Animator!=null) // add for jumping
3165 { 3516 { // add for jumping
3166 Vector3 force = m_forceToApply.Value; 3517 // if (!m_animator.m_jumping) // add for jumping
3518 // { // add for jumping
3167 3519
3168 m_updateflag = true; 3520 if (m_forceToApply.HasValue) // this section realigned
3169// movementvector = force; 3521 {
3170 Velocity = force;
3171 3522
3172 m_forceToApply = null; 3523 Vector3 force = m_forceToApply.Value;
3173 } 3524 m_updateflag = true;
3174 } 3525if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3526 Velocity = force;
3527//Console.WriteLine("UM1 {0}", Velocity);
3528 m_forceToApply = null;
3529 }
3530 else
3531 {
3532 if (m_isNudging)
3533 {
3534 Vector3 force = Vector3.Zero;
3535
3536 m_updateflag = true;
3537if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3538 Velocity = force;
3539//Console.WriteLine("UM2 {0}", Velocity);
3540 m_isNudging = false;
3541 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3542 }
3543 else // add for jumping
3544 { // add for jumping
3545 Vector3 force = Vector3.Zero; // add for jumping
3546if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3547//Console.WriteLine("UM3 {0}", Velocity);
3548 Velocity = force; // add for jumping
3549 }
3550
3551 }
3552 // } // end realign
3553 } // add for jumping
3554 } // add for jumping
3175 3555
3176 /// <summary> 3556 /// <summary>
3177 /// Adds a physical representation of the avatar to the Physics plugin 3557 /// Adds a physical representation of the avatar to the Physics plugin
@@ -3216,18 +3596,29 @@ namespace OpenSim.Region.Framework.Scenes
3216 { 3596 {
3217 if (e == null) 3597 if (e == null)
3218 return; 3598 return;
3219 3599
3220 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3600 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3221 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3222 // as of this comment the interval is set in AddToPhysicalScene 3601 // as of this comment the interval is set in AddToPhysicalScene
3223 if (Animator!=null) 3602 if (Animator!=null)
3224 Animator.UpdateMovementAnimations(); 3603 {
3604 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3605 { // else its will lock out other animation changes, like ground sit.
3606 Animator.UpdateMovementAnimations();
3607 m_updateCount--;
3608 }
3609 }
3225 3610
3226 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3611 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3227 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3612 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3228 3613
3229 CollisionPlane = Vector4.UnitW; 3614 CollisionPlane = Vector4.UnitW;
3230 3615
3616 if (m_lastColCount != coldata.Count)
3617 {
3618 m_updateCount = UPDATE_COUNT;
3619 m_lastColCount = coldata.Count;
3620 }
3621
3231 if (coldata.Count != 0 && Animator != null) 3622 if (coldata.Count != 0 && Animator != null)
3232 { 3623 {
3233 switch (Animator.CurrentMovementAnimation) 3624 switch (Animator.CurrentMovementAnimation)
@@ -3257,6 +3648,148 @@ namespace OpenSim.Region.Framework.Scenes
3257 } 3648 }
3258 } 3649 }
3259 3650
3651 List<uint> thisHitColliders = new List<uint>();
3652 List<uint> endedColliders = new List<uint>();
3653 List<uint> startedColliders = new List<uint>();
3654
3655 foreach (uint localid in coldata.Keys)
3656 {
3657 thisHitColliders.Add(localid);
3658 if (!m_lastColliders.Contains(localid))
3659 {
3660 startedColliders.Add(localid);
3661 }
3662 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
3663 }
3664
3665 // calculate things that ended colliding
3666 foreach (uint localID in m_lastColliders)
3667 {
3668 if (!thisHitColliders.Contains(localID))
3669 {
3670 endedColliders.Add(localID);
3671 }
3672 }
3673 //add the items that started colliding this time to the last colliders list.
3674 foreach (uint localID in startedColliders)
3675 {
3676 m_lastColliders.Add(localID);
3677 }
3678 // remove things that ended colliding from the last colliders list
3679 foreach (uint localID in endedColliders)
3680 {
3681 m_lastColliders.Remove(localID);
3682 }
3683
3684 // do event notification
3685 if (startedColliders.Count > 0)
3686 {
3687 ColliderArgs StartCollidingMessage = new ColliderArgs();
3688 List<DetectedObject> colliding = new List<DetectedObject>();
3689 foreach (uint localId in startedColliders)
3690 {
3691 if (localId == 0)
3692 continue;
3693
3694 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3695 string data = "";
3696 if (obj != null)
3697 {
3698 DetectedObject detobj = new DetectedObject();
3699 detobj.keyUUID = obj.UUID;
3700 detobj.nameStr = obj.Name;
3701 detobj.ownerUUID = obj.OwnerID;
3702 detobj.posVector = obj.AbsolutePosition;
3703 detobj.rotQuat = obj.GetWorldRotation();
3704 detobj.velVector = obj.Velocity;
3705 detobj.colliderType = 0;
3706 detobj.groupUUID = obj.GroupID;
3707 colliding.Add(detobj);
3708 }
3709 }
3710
3711 if (colliding.Count > 0)
3712 {
3713 StartCollidingMessage.Colliders = colliding;
3714
3715 foreach (SceneObjectGroup att in Attachments)
3716 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
3717 }
3718 }
3719
3720 if (endedColliders.Count > 0)
3721 {
3722 ColliderArgs EndCollidingMessage = new ColliderArgs();
3723 List<DetectedObject> colliding = new List<DetectedObject>();
3724 foreach (uint localId in endedColliders)
3725 {
3726 if (localId == 0)
3727 continue;
3728
3729 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3730 string data = "";
3731 if (obj != null)
3732 {
3733 DetectedObject detobj = new DetectedObject();
3734 detobj.keyUUID = obj.UUID;
3735 detobj.nameStr = obj.Name;
3736 detobj.ownerUUID = obj.OwnerID;
3737 detobj.posVector = obj.AbsolutePosition;
3738 detobj.rotQuat = obj.GetWorldRotation();
3739 detobj.velVector = obj.Velocity;
3740 detobj.colliderType = 0;
3741 detobj.groupUUID = obj.GroupID;
3742 colliding.Add(detobj);
3743 }
3744 }
3745
3746 if (colliding.Count > 0)
3747 {
3748 EndCollidingMessage.Colliders = colliding;
3749
3750 foreach (SceneObjectGroup att in Attachments)
3751 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
3752 }
3753 }
3754
3755 if (thisHitColliders.Count > 0)
3756 {
3757 ColliderArgs CollidingMessage = new ColliderArgs();
3758 List<DetectedObject> colliding = new List<DetectedObject>();
3759 foreach (uint localId in thisHitColliders)
3760 {
3761 if (localId == 0)
3762 continue;
3763
3764 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3765 string data = "";
3766 if (obj != null)
3767 {
3768 DetectedObject detobj = new DetectedObject();
3769 detobj.keyUUID = obj.UUID;
3770 detobj.nameStr = obj.Name;
3771 detobj.ownerUUID = obj.OwnerID;
3772 detobj.posVector = obj.AbsolutePosition;
3773 detobj.rotQuat = obj.GetWorldRotation();
3774 detobj.velVector = obj.Velocity;
3775 detobj.colliderType = 0;
3776 detobj.groupUUID = obj.GroupID;
3777 colliding.Add(detobj);
3778 }
3779 }
3780
3781 if (colliding.Count > 0)
3782 {
3783 CollidingMessage.Colliders = colliding;
3784
3785 lock (m_attachments)
3786 {
3787 foreach (SceneObjectGroup att in m_attachments)
3788 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
3789 }
3790 }
3791 }
3792
3260 if (m_invulnerable) 3793 if (m_invulnerable)
3261 return; 3794 return;
3262 3795
@@ -3452,7 +3985,10 @@ namespace OpenSim.Region.Framework.Scenes
3452 m_scene = scene; 3985 m_scene = scene;
3453 3986
3454 RegisterToEvents(); 3987 RegisterToEvents();
3455 3988 if (m_controllingClient != null)
3989 {
3990 m_controllingClient.ProcessPendingPackets();
3991 }
3456 /* 3992 /*
3457 AbsolutePosition = client.StartPos; 3993 AbsolutePosition = client.StartPos;
3458 3994
@@ -3682,6 +4218,39 @@ namespace OpenSim.Region.Framework.Scenes
3682 return; 4218 return;
3683 } 4219 }
3684 4220
4221 XmlDocument doc = new XmlDocument();
4222 string stateData = String.Empty;
4223
4224 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
4225 if (attServ != null)
4226 {
4227 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
4228 stateData = attServ.Get(ControllingClient.AgentId.ToString());
4229 if (stateData != String.Empty)
4230 {
4231 try
4232 {
4233 doc.LoadXml(stateData);
4234 }
4235 catch { }
4236 }
4237 }
4238
4239 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
4240
4241 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
4242 if (nodes.Count > 0)
4243 {
4244 foreach (XmlNode n in nodes)
4245 {
4246 XmlElement elem = (XmlElement)n;
4247 string itemID = elem.GetAttribute("ItemID");
4248 string xml = elem.InnerXml;
4249
4250 itemData[new UUID(itemID)] = xml;
4251 }
4252 }
4253
3685 List<AvatarAttachment> attachments = m_appearance.GetAttachments(); 4254 List<AvatarAttachment> attachments = m_appearance.GetAttachments();
3686 foreach (AvatarAttachment attach in attachments) 4255 foreach (AvatarAttachment attach in attachments)
3687 { 4256 {
@@ -3702,7 +4271,30 @@ namespace OpenSim.Region.Framework.Scenes
3702 4271
3703 try 4272 try
3704 { 4273 {
3705 m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p); 4274 string xmlData;
4275 XmlDocument d = new XmlDocument();
4276 UUID asset;
4277 if (itemData.TryGetValue(itemID, out xmlData))
4278 {
4279 d.LoadXml(xmlData);
4280 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID);
4281
4282 // Rez from inventory
4283 asset
4284 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d);
4285
4286 }
4287 else
4288 {
4289 // Rez from inventory (with a null doc to let
4290 // CHANGED_OWNER happen)
4291 asset
4292 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, null);
4293 }
4294
4295 m_log.InfoFormat(
4296 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2}",
4297 p, itemID, asset);
3706 } 4298 }
3707 catch (Exception e) 4299 catch (Exception e)
3708 { 4300 {
@@ -3735,5 +4327,16 @@ namespace OpenSim.Region.Framework.Scenes
3735 m_reprioritization_called = false; 4327 m_reprioritization_called = false;
3736 } 4328 }
3737 } 4329 }
4330
4331 private Vector3 Quat2Euler(Quaternion rot){
4332 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4333 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4334 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4335 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4336 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4337 return(new Vector3(x,y,z));
4338 }
4339
4340
3738 } 4341 }
3739} 4342}