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.cs655
1 files changed, 473 insertions, 182 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 30eafd7..0b644b9 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Xml;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.Reflection; 31using System.Reflection;
31using System.Timers; 32using System.Timers;
@@ -73,7 +74,7 @@ namespace OpenSim.Region.Framework.Scenes
73// { 74// {
74// m_log.Debug("[ScenePresence] Destructor called"); 75// m_log.Debug("[ScenePresence] Destructor called");
75// } 76// }
76 77
77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 78 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
78 79
79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 80 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
@@ -89,7 +90,9 @@ namespace OpenSim.Region.Framework.Scenes
89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 90 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
90 /// issue #1716 91 /// issue #1716
91 /// </summary> 92 /// </summary>
92 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 93// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
94 // Value revised by KF 091121 by comparison with SL.
95 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f);
93 96
94 public UUID currentParcelUUID = UUID.Zero; 97 public UUID currentParcelUUID = UUID.Zero;
95 98
@@ -123,8 +126,11 @@ namespace OpenSim.Region.Framework.Scenes
123 public Vector3 lastKnownAllowedPosition; 126 public Vector3 lastKnownAllowedPosition;
124 public bool sentMessageAboutRestrictedParcelFlyingDown; 127 public bool sentMessageAboutRestrictedParcelFlyingDown;
125 public Vector4 CollisionPlane = Vector4.UnitW; 128 public Vector4 CollisionPlane = Vector4.UnitW;
126 129
130 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
131 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
127 private Vector3 m_lastPosition; 132 private Vector3 m_lastPosition;
133 private Vector3 m_lastWorldPosition;
128 private Quaternion m_lastRotation; 134 private Quaternion m_lastRotation;
129 private Vector3 m_lastVelocity; 135 private Vector3 m_lastVelocity;
130 //private int m_lastTerseSent; 136 //private int m_lastTerseSent;
@@ -134,7 +140,6 @@ namespace OpenSim.Region.Framework.Scenes
134 private Vector3? m_forceToApply; 140 private Vector3? m_forceToApply;
135 private uint m_requestedSitTargetID; 141 private uint m_requestedSitTargetID;
136 private UUID m_requestedSitTargetUUID; 142 private UUID m_requestedSitTargetUUID;
137 public bool SitGround = false;
138 143
139 private SendCourseLocationsMethod m_sendCourseLocationsMethod; 144 private SendCourseLocationsMethod m_sendCourseLocationsMethod;
140 145
@@ -157,7 +162,6 @@ namespace OpenSim.Region.Framework.Scenes
157 private int m_perfMonMS; 162 private int m_perfMonMS;
158 163
159 private bool m_setAlwaysRun; 164 private bool m_setAlwaysRun;
160
161 private bool m_forceFly; 165 private bool m_forceFly;
162 private bool m_flyDisabled; 166 private bool m_flyDisabled;
163 167
@@ -183,7 +187,8 @@ namespace OpenSim.Region.Framework.Scenes
183 protected RegionInfo m_regionInfo; 187 protected RegionInfo m_regionInfo;
184 protected ulong crossingFromRegion; 188 protected ulong crossingFromRegion;
185 189
186 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 190 private readonly Vector3[] Dir_Vectors = new Vector3[11];
191 private bool m_isNudging = false;
187 192
188 // Position of agent's camera in world (region cordinates) 193 // Position of agent's camera in world (region cordinates)
189 protected Vector3 m_CameraCenter; 194 protected Vector3 m_CameraCenter;
@@ -208,6 +213,7 @@ namespace OpenSim.Region.Framework.Scenes
208 private bool m_autopilotMoving; 213 private bool m_autopilotMoving;
209 private Vector3 m_autoPilotTarget; 214 private Vector3 m_autoPilotTarget;
210 private bool m_sitAtAutoTarget; 215 private bool m_sitAtAutoTarget;
216 private Vector3 m_initialSitTarget; //KF: First estimate of where to sit
211 217
212 private string m_nextSitAnimation = String.Empty; 218 private string m_nextSitAnimation = String.Empty;
213 219
@@ -218,6 +224,9 @@ namespace OpenSim.Region.Framework.Scenes
218 private bool m_followCamAuto; 224 private bool m_followCamAuto;
219 225
220 private int m_movementUpdateCount; 226 private int m_movementUpdateCount;
227 private int m_lastColCount = -1; //KF: Look for Collision chnages
228 private int m_updateCount = 0; //KF: Update Anims for a while
229 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
221 private const int NumMovementsBetweenRayCast = 5; 230 private const int NumMovementsBetweenRayCast = 5;
222 231
223 private bool CameraConstraintActive; 232 private bool CameraConstraintActive;
@@ -245,7 +254,9 @@ namespace OpenSim.Region.Framework.Scenes
245 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 254 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
246 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 255 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
247 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 256 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
248 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 257 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
258 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
259 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
249 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 260 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
250 } 261 }
251 262
@@ -452,7 +463,8 @@ namespace OpenSim.Region.Framework.Scenes
452 get 463 get
453 { 464 {
454 PhysicsActor actor = m_physicsActor; 465 PhysicsActor actor = m_physicsActor;
455 if (actor != null) 466// if (actor != null)
467 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting!
456 m_pos = actor.Position; 468 m_pos = actor.Position;
457 469
458 return m_parentPosition + m_pos; 470 return m_parentPosition + m_pos;
@@ -473,7 +485,8 @@ namespace OpenSim.Region.Framework.Scenes
473 } 485 }
474 } 486 }
475 487
476 m_pos = value; 488 if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting!
489 m_pos = value;
477 m_parentPosition = Vector3.Zero; 490 m_parentPosition = Vector3.Zero;
478 } 491 }
479 } 492 }
@@ -665,7 +678,7 @@ namespace OpenSim.Region.Framework.Scenes
665 CreateSceneViewer(); 678 CreateSceneViewer();
666 m_animator = new ScenePresenceAnimator(this); 679 m_animator = new ScenePresenceAnimator(this);
667 } 680 }
668 681
669 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() 682 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this()
670 { 683 {
671 m_rootRegionHandle = reginfo.RegionHandle; 684 m_rootRegionHandle = reginfo.RegionHandle;
@@ -697,16 +710,16 @@ namespace OpenSim.Region.Framework.Scenes
697 m_reprioritization_timer.AutoReset = false; 710 m_reprioritization_timer.AutoReset = false;
698 711
699 AdjustKnownSeeds(); 712 AdjustKnownSeeds();
700
701 // TODO: I think, this won't send anything, as we are still a child here...
702 Animator.TrySetMovementAnimation("STAND"); 713 Animator.TrySetMovementAnimation("STAND");
703
704 // we created a new ScenePresence (a new child agent) in a fresh region. 714 // we created a new ScenePresence (a new child agent) in a fresh region.
705 // Request info about all the (root) agents in this region 715 // 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) 716 // Note: This won't send data *to* other clients in that region (children don't send)
707 SendInitialFullUpdateToAllClients(); 717 SendInitialFullUpdateToAllClients();
708
709 RegisterToEvents(); 718 RegisterToEvents();
719 if (m_controllingClient != null)
720 {
721 m_controllingClient.ProcessPendingPackets();
722 }
710 SetDirectionVectors(); 723 SetDirectionVectors();
711 } 724 }
712 725
@@ -756,25 +769,47 @@ namespace OpenSim.Region.Framework.Scenes
756 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 769 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
757 Dir_Vectors[4] = Vector3.UnitZ; //UP 770 Dir_Vectors[4] = Vector3.UnitZ; //UP
758 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 771 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
759 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 772 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
760 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 773 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
761 Dir_Vectors[7] = -Vector3.UnitX; //BACK 774 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
775 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
776 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
762 } 777 }
763 778
764 private Vector3[] GetWalkDirectionVectors() 779 private Vector3[] GetWalkDirectionVectors()
765 { 780 {
766 Vector3[] vector = new Vector3[9]; 781 Vector3[] vector = new Vector3[11];
767 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 782 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
768 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 783 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
769 vector[2] = Vector3.UnitY; //LEFT 784 vector[2] = Vector3.UnitY; //LEFT
770 vector[3] = -Vector3.UnitY; //RIGHT 785 vector[3] = -Vector3.UnitY; //RIGHT
771 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 786 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
772 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 787 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
773 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 788 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
774 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 789 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
775 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 790 vector[8] = Vector3.UnitY; //LEFT_NUDGE
791 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
792 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
776 return vector; 793 return vector;
777 } 794 }
795
796 private bool[] GetDirectionIsNudge()
797 {
798 bool[] isNudge = new bool[11];
799 isNudge[0] = false; //FORWARD
800 isNudge[1] = false; //BACK
801 isNudge[2] = false; //LEFT
802 isNudge[3] = false; //RIGHT
803 isNudge[4] = false; //UP
804 isNudge[5] = false; //DOWN
805 isNudge[6] = true; //FORWARD_NUDGE
806 isNudge[7] = true; //BACK_NUDGE
807 isNudge[8] = true; //LEFT_NUDGE
808 isNudge[9] = true; //RIGHT_NUDGE
809 isNudge[10] = true; //DOWN_Nudge
810 return isNudge;
811 }
812
778 813
779 #endregion 814 #endregion
780 815
@@ -826,7 +861,6 @@ namespace OpenSim.Region.Framework.Scenes
826 m_grouptitle = gm.GetGroupTitle(m_uuid); 861 m_grouptitle = gm.GetGroupTitle(m_uuid);
827 862
828 m_rootRegionHandle = m_scene.RegionInfo.RegionHandle; 863 m_rootRegionHandle = m_scene.RegionInfo.RegionHandle;
829
830 m_scene.SetRootAgentScene(m_uuid); 864 m_scene.SetRootAgentScene(m_uuid);
831 865
832 // Moved this from SendInitialData to ensure that m_appearance is initialized 866 // Moved this from SendInitialData to ensure that m_appearance is initialized
@@ -845,6 +879,22 @@ namespace OpenSim.Region.Framework.Scenes
845 pos.Y = crossedBorder.BorderLine.Z - 1; 879 pos.Y = crossedBorder.BorderLine.Z - 1;
846 } 880 }
847 881
882 //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet.
883 //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent,
884 //they'll bypass the landing point. But I can't think of any decent way of fixing this.
885 if (KnownChildRegionHandles.Count == 0)
886 {
887 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
888 if (land != null)
889 {
890 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
891 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero && m_userLevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid) && land.LandData.OwnerID != m_uuid)
892 {
893 pos = land.LandData.UserLocation;
894 }
895 }
896 }
897
848 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 898 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
849 { 899 {
850 m_log.WarnFormat( 900 m_log.WarnFormat(
@@ -977,9 +1027,10 @@ namespace OpenSim.Region.Framework.Scenes
977 public void Teleport(Vector3 pos) 1027 public void Teleport(Vector3 pos)
978 { 1028 {
979 bool isFlying = false; 1029 bool isFlying = false;
1030
980 if (m_physicsActor != null) 1031 if (m_physicsActor != null)
981 isFlying = m_physicsActor.Flying; 1032 isFlying = m_physicsActor.Flying;
982 1033
983 RemoveFromPhysicalScene(); 1034 RemoveFromPhysicalScene();
984 Velocity = Vector3.Zero; 1035 Velocity = Vector3.Zero;
985 AbsolutePosition = pos; 1036 AbsolutePosition = pos;
@@ -991,6 +1042,7 @@ namespace OpenSim.Region.Framework.Scenes
991 } 1042 }
992 1043
993 SendTerseUpdateToAllClients(); 1044 SendTerseUpdateToAllClients();
1045
994 } 1046 }
995 1047
996 public void TeleportWithMomentum(Vector3 pos) 1048 public void TeleportWithMomentum(Vector3 pos)
@@ -1035,7 +1087,9 @@ namespace OpenSim.Region.Framework.Scenes
1035 { 1087 {
1036 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f)); 1088 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f));
1037 } 1089 }
1038 1090
1091 m_updateCount = UPDATE_COUNT; //KF: Trigger Anim updates to catch falling anim.
1092
1039 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId, 1093 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId,
1040 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient))); 1094 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient)));
1041 } 1095 }
@@ -1121,7 +1175,6 @@ namespace OpenSim.Region.Framework.Scenes
1121 pos.Z = ground + 1.5f; 1175 pos.Z = ground + 1.5f;
1122 AbsolutePosition = pos; 1176 AbsolutePosition = pos;
1123 } 1177 }
1124
1125 m_isChildAgent = false; 1178 m_isChildAgent = false;
1126 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 1179 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1127 MakeRootAgent(AbsolutePosition, m_flying); 1180 MakeRootAgent(AbsolutePosition, m_flying);
@@ -1220,6 +1273,7 @@ namespace OpenSim.Region.Framework.Scenes
1220 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); 1273 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902");
1221 1274
1222 m_pos = m_LastFinitePos; 1275 m_pos = m_LastFinitePos;
1276
1223 if (!m_pos.IsFinite()) 1277 if (!m_pos.IsFinite())
1224 { 1278 {
1225 m_pos.X = 127f; 1279 m_pos.X = 127f;
@@ -1286,7 +1340,6 @@ namespace OpenSim.Region.Framework.Scenes
1286 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1340 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1287 } 1341 }
1288 } 1342 }
1289
1290 lock (scriptedcontrols) 1343 lock (scriptedcontrols)
1291 { 1344 {
1292 if (scriptedcontrols.Count > 0) 1345 if (scriptedcontrols.Count > 0)
@@ -1301,12 +1354,8 @@ namespace OpenSim.Region.Framework.Scenes
1301 1354
1302 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1355 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1303 { 1356 {
1304 // TODO: This doesn't prevent the user from walking yet. 1357 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1305 // Setting parent ID would fix this, if we knew what value 1358 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1306 // to use. Or we could add a m_isSitting variable.
1307 //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1308 SitGround = true;
1309
1310 } 1359 }
1311 1360
1312 // In the future, these values might need to go global. 1361 // In the future, these values might need to go global.
@@ -1356,6 +1405,11 @@ namespace OpenSim.Region.Framework.Scenes
1356 update_rotation = true; 1405 update_rotation = true;
1357 } 1406 }
1358 1407
1408 //guilty until proven innocent..
1409 bool Nudging = true;
1410 //Basically, if there is at least one non-nudge control then we don't need
1411 //to worry about stopping the avatar
1412
1359 if (m_parentID == 0) 1413 if (m_parentID == 0)
1360 { 1414 {
1361 bool bAllowUpdateMoveToPosition = false; 1415 bool bAllowUpdateMoveToPosition = false;
@@ -1370,9 +1424,12 @@ namespace OpenSim.Region.Framework.Scenes
1370 else 1424 else
1371 dirVectors = Dir_Vectors; 1425 dirVectors = Dir_Vectors;
1372 1426
1373 // The fact that m_movementflag is a byte needs to be fixed 1427 bool[] isNudge = GetDirectionIsNudge();
1374 // it really should be a uint 1428
1375 uint nudgehack = 250; 1429
1430
1431
1432
1376 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1433 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1377 { 1434 {
1378 if (((uint)flags & (uint)DCF) != 0) 1435 if (((uint)flags & (uint)DCF) != 0)
@@ -1382,40 +1439,28 @@ namespace OpenSim.Region.Framework.Scenes
1382 try 1439 try
1383 { 1440 {
1384 agent_control_v3 += dirVectors[i]; 1441 agent_control_v3 += dirVectors[i];
1385 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1442 if (isNudge[i] == false)
1443 {
1444 Nudging = false;
1445 }
1386 } 1446 }
1387 catch (IndexOutOfRangeException) 1447 catch (IndexOutOfRangeException)
1388 { 1448 {
1389 // Why did I get this? 1449 // Why did I get this?
1390 } 1450 }
1391 1451
1392 if ((m_movementflag & (byte)(uint)DCF) == 0) 1452 if ((m_movementflag & (uint)DCF) == 0)
1393 { 1453 {
1394 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1395 {
1396 m_movementflag |= (byte)nudgehack;
1397 }
1398 m_movementflag += (byte)(uint)DCF; 1454 m_movementflag += (byte)(uint)DCF;
1399 update_movementflag = true; 1455 update_movementflag = true;
1400 } 1456 }
1401 } 1457 }
1402 else 1458 else
1403 { 1459 {
1404 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1460 if ((m_movementflag & (uint)DCF) != 0)
1405 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1406 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1407 ) // This or is for Nudge forward
1408 { 1461 {
1409 m_movementflag -= ((byte)(uint)DCF); 1462 m_movementflag -= (byte)(uint)DCF;
1410
1411 update_movementflag = true; 1463 update_movementflag = true;
1412 /*
1413 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1414 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1415 {
1416 m_log.Debug("Removed Hack flag");
1417 }
1418 */
1419 } 1464 }
1420 else 1465 else
1421 { 1466 {
@@ -1424,7 +1469,6 @@ namespace OpenSim.Region.Framework.Scenes
1424 } 1469 }
1425 i++; 1470 i++;
1426 } 1471 }
1427
1428 //Paupaw:Do Proper PID for Autopilot here 1472 //Paupaw:Do Proper PID for Autopilot here
1429 if (bResetMoveToPosition) 1473 if (bResetMoveToPosition)
1430 { 1474 {
@@ -1459,6 +1503,9 @@ namespace OpenSim.Region.Framework.Scenes
1459 // Ignore z component of vector 1503 // Ignore z component of vector
1460 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1504 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1461 LocalVectorToTarget2D.Normalize(); 1505 LocalVectorToTarget2D.Normalize();
1506
1507 //We're not nudging
1508 Nudging = false;
1462 agent_control_v3 += LocalVectorToTarget2D; 1509 agent_control_v3 += LocalVectorToTarget2D;
1463 1510
1464 // update avatar movement flags. the avatar coordinate system is as follows: 1511 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1547,13 +1594,13 @@ namespace OpenSim.Region.Framework.Scenes
1547 // m_log.DebugFormat( 1594 // m_log.DebugFormat(
1548 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1595 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1549 1596
1550 AddNewMovement(agent_control_v3, q); 1597 AddNewMovement(agent_control_v3, q, Nudging);
1551 1598
1552 1599
1553 } 1600 }
1554 } 1601 }
1555 1602
1556 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1603 if (update_movementflag)
1557 Animator.UpdateMovementAnimations(); 1604 Animator.UpdateMovementAnimations();
1558 1605
1559 m_scene.EventManager.TriggerOnClientMovement(this); 1606 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1568,7 +1615,6 @@ namespace OpenSim.Region.Framework.Scenes
1568 m_sitAtAutoTarget = false; 1615 m_sitAtAutoTarget = false;
1569 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1616 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1570 //proxy.PCode = (byte)PCode.ParticleSystem; 1617 //proxy.PCode = (byte)PCode.ParticleSystem;
1571
1572 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1618 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1573 proxyObjectGroup.AttachToScene(m_scene); 1619 proxyObjectGroup.AttachToScene(m_scene);
1574 1620
@@ -1610,7 +1656,7 @@ namespace OpenSim.Region.Framework.Scenes
1610 } 1656 }
1611 m_moveToPositionInProgress = true; 1657 m_moveToPositionInProgress = true;
1612 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1658 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1613 } 1659 }
1614 catch (Exception ex) 1660 catch (Exception ex)
1615 { 1661 {
1616 //Why did I get this error? 1662 //Why did I get this error?
@@ -1632,7 +1678,7 @@ namespace OpenSim.Region.Framework.Scenes
1632 Velocity = Vector3.Zero; 1678 Velocity = Vector3.Zero;
1633 SendFullUpdateToAllClients(); 1679 SendFullUpdateToAllClients();
1634 1680
1635 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1681 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1636 } 1682 }
1637 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1683 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1638 m_requestedSitTargetUUID = UUID.Zero; 1684 m_requestedSitTargetUUID = UUID.Zero;
@@ -1665,55 +1711,84 @@ namespace OpenSim.Region.Framework.Scenes
1665 /// </summary> 1711 /// </summary>
1666 public void StandUp() 1712 public void StandUp()
1667 { 1713 {
1668 if (SitGround)
1669 SitGround = false;
1670
1671 if (m_parentID != 0) 1714 if (m_parentID != 0)
1672 { 1715 {
1673 m_log.Debug("StandupCode Executed");
1674 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); 1716 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1675 if (part != null) 1717 if (part != null)
1676 { 1718 {
1719 part.TaskInventory.LockItemsForRead(true);
1677 TaskInventoryDictionary taskIDict = part.TaskInventory; 1720 TaskInventoryDictionary taskIDict = part.TaskInventory;
1678 if (taskIDict != null) 1721 if (taskIDict != null)
1679 { 1722 {
1680 lock (taskIDict) 1723 foreach (UUID taskID in taskIDict.Keys)
1681 { 1724 {
1682 foreach (UUID taskID in taskIDict.Keys) 1725 UnRegisterControlEventsToScript(LocalId, taskID);
1683 { 1726 taskIDict[taskID].PermsMask &= ~(
1684 UnRegisterControlEventsToScript(LocalId, taskID); 1727 2048 | //PERMISSION_CONTROL_CAMERA
1685 taskIDict[taskID].PermsMask &= ~( 1728 4); // PERMISSION_TAKE_CONTROLS
1686 2048 | //PERMISSION_CONTROL_CAMERA
1687 4); // PERMISSION_TAKE_CONTROLS
1688 }
1689 } 1729 }
1690
1691 } 1730 }
1731 part.TaskInventory.LockItemsForRead(false);
1692 // Reset sit target. 1732 // Reset sit target.
1693 if (part.GetAvatarOnSitTarget() == UUID) 1733 if (part.GetAvatarOnSitTarget() == UUID)
1694 part.SetAvatarOnSitTarget(UUID.Zero); 1734 part.SetAvatarOnSitTarget(UUID.Zero);
1695
1696 m_parentPosition = part.GetWorldPosition(); 1735 m_parentPosition = part.GetWorldPosition();
1697 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1736 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1698 } 1737 }
1738 // part.GetWorldRotation() is the rotation of the object being sat on
1739 // Rotation is the sittiing Av's rotation
1740
1741 Quaternion partRot;
1742// if (part.LinkNum == 1)
1743// { // Root prim of linkset
1744// partRot = part.ParentGroup.RootPart.RotationOffset;
1745// }
1746// else
1747// { // single or child prim
1748
1749// }
1750 if (part == null) //CW: Part may be gone. llDie() for example.
1751 {
1752 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1753 }
1754 else
1755 {
1756 partRot = part.GetWorldRotation();
1757 }
1758
1759 Quaternion partIRot = Quaternion.Inverse(partRot);
1699 1760
1761 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1762 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1763
1764
1700 if (m_physicsActor == null) 1765 if (m_physicsActor == null)
1701 { 1766 {
1702 AddToPhysicalScene(false); 1767 AddToPhysicalScene(false);
1703 } 1768 }
1704 1769 //CW: If the part isn't null then we can set the current position
1705 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1770 if (part != null)
1706 m_parentPosition = Vector3.Zero; 1771 {
1707 1772 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + (m_pos * partRot); // + av sit offset!
1708 m_parentID = 0; 1773 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1774 part.IsOccupied = false;
1775 }
1776 else
1777 {
1778 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1779 AbsolutePosition = m_lastWorldPosition;
1780 }
1781
1782 m_parentPosition = Vector3.Zero;
1783 m_parentID = 0;
1709 SendFullUpdateToAllClients(); 1784 SendFullUpdateToAllClients();
1710 m_requestedSitTargetID = 0; 1785 m_requestedSitTargetID = 0;
1786
1711 if ((m_physicsActor != null) && (m_avHeight > 0)) 1787 if ((m_physicsActor != null) && (m_avHeight > 0))
1712 { 1788 {
1713 SetHeight(m_avHeight); 1789 SetHeight(m_avHeight);
1714 } 1790 }
1715 } 1791 }
1716
1717 Animator.TrySetMovementAnimation("STAND"); 1792 Animator.TrySetMovementAnimation("STAND");
1718 } 1793 }
1719 1794
@@ -1744,13 +1819,9 @@ namespace OpenSim.Region.Framework.Scenes
1744 Vector3 avSitOffSet = part.SitTargetPosition; 1819 Vector3 avSitOffSet = part.SitTargetPosition;
1745 Quaternion avSitOrientation = part.SitTargetOrientation; 1820 Quaternion avSitOrientation = part.SitTargetOrientation;
1746 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1821 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1747 1822 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1748 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1823 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1749 bool SitTargetisSet = 1824 if (SitTargetisSet && !SitTargetOccupied)
1750 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1751 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1752
1753 if (SitTargetisSet && SitTargetUnOccupied)
1754 { 1825 {
1755 //switch the target to this prim 1826 //switch the target to this prim
1756 return part; 1827 return part;
@@ -1764,84 +1835,153 @@ namespace OpenSim.Region.Framework.Scenes
1764 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1835 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1765 { 1836 {
1766 bool autopilot = true; 1837 bool autopilot = true;
1838 Vector3 autopilotTarget = new Vector3();
1839 Quaternion sitOrientation = Quaternion.Identity;
1767 Vector3 pos = new Vector3(); 1840 Vector3 pos = new Vector3();
1768 Quaternion sitOrientation = pSitOrientation;
1769 Vector3 cameraEyeOffset = Vector3.Zero; 1841 Vector3 cameraEyeOffset = Vector3.Zero;
1770 Vector3 cameraAtOffset = Vector3.Zero; 1842 Vector3 cameraAtOffset = Vector3.Zero;
1771 bool forceMouselook = false; 1843 bool forceMouselook = false;
1772 1844
1773 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1845 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1774 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1846 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1775 if (part != null) 1847 if (part == null) return;
1776 { 1848
1777 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1849 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1778 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1850 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1779 1851
1780 // Is a sit target available? 1852 // part is the prim to sit on
1781 Vector3 avSitOffSet = part.SitTargetPosition; 1853 // offset is the world-ref vector distance from that prim center to the click-spot
1782 Quaternion avSitOrientation = part.SitTargetOrientation; 1854 // UUID is the UUID of the Avatar doing the clicking
1783 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1855
1784 1856 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1785 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1857
1786 bool SitTargetisSet = 1858 // Is a sit target available?
1787 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1859 Vector3 avSitOffSet = part.SitTargetPosition;
1788 ( 1860 Quaternion avSitOrientation = part.SitTargetOrientation;
1789 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1861
1790 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1862 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1791 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1863 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1792 ) 1864 Quaternion partRot;
1793 )); 1865// if (part.LinkNum == 1)
1794 1866// { // Root prim of linkset
1795 if (SitTargetisSet && SitTargetUnOccupied) 1867// partRot = part.ParentGroup.RootPart.RotationOffset;
1796 { 1868// }
1797 part.SetAvatarOnSitTarget(UUID); 1869// else
1798 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1870// { // single or child prim
1799 sitOrientation = avSitOrientation; 1871 partRot = part.GetWorldRotation();
1800 autopilot = false; 1872// }
1801 } 1873 Quaternion partIRot = Quaternion.Inverse(partRot);
1802 1874//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1803 pos = part.AbsolutePosition + offset; 1875 // Sit analysis rewritten by KF 091125
1804 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1876 if (SitTargetisSet) // scipted sit
1805 //{ 1877 {
1806 // offset = pos; 1878 if (!part.IsOccupied)
1807 //autopilot = false; 1879 {
1808 //} 1880//Console.WriteLine("Scripted, unoccupied");
1809 if (m_physicsActor != null) 1881 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1810 { 1882 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1811 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1883 sitOrientation = avSitOrientation; // Change rotatione to the scripted one
1812 // We can remove the physicsActor until they stand up. 1884 autopilot = false; // Jump direct to scripted llSitPos()
1813 m_sitAvatarHeight = m_physicsActor.Size.Z; 1885 }
1814 1886 else
1815 if (autopilot) 1887 {
1816 { 1888//Console.WriteLine("Scripted, occupied");
1817 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1889 return;
1818 { 1890 }
1819 autopilot = false; 1891 }
1892 else // Not Scripted
1893 {
1894 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
1895 {
1896 // large prim & offset, ignore if other Avs sitting
1897// offset.Z -= 0.05f;
1898 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
1899 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
1900
1901//Console.WriteLine(" offset ={0}", offset);
1902//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
1903//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
1904
1905 }
1906 else // small offset
1907 {
1908//Console.WriteLine("Small offset");
1909 if (!part.IsOccupied)
1910 {
1911 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
1912 autopilotTarget = part.AbsolutePosition;
1913//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget);
1914 }
1915 else return; // occupied small
1916 } // end large/small
1917 } // end Scripted/not
1918 cameraAtOffset = part.GetCameraAtOffset();
1919 cameraEyeOffset = part.GetCameraEyeOffset();
1920 forceMouselook = part.GetForceMouselook();
1921 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
1922 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
1820 1923
1821 RemoveFromPhysicalScene(); 1924 if (m_physicsActor != null)
1822 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 1925 {
1823 } 1926 // If we're not using the client autopilot, we're immediately warping the avatar to the location
1824 } 1927 // We can remove the physicsActor until they stand up.
1825 else 1928 m_sitAvatarHeight = m_physicsActor.Size.Z;
1929 if (autopilot)
1930 { // its not a scripted sit
1931// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
1932 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 2.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 2.0f) )
1826 { 1933 {
1934 autopilot = false; // close enough
1935 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1936 Not using the part's position because returning the AV to the last known standing
1937 position is likely to be more friendly, isn't it? */
1827 RemoveFromPhysicalScene(); 1938 RemoveFromPhysicalScene();
1828 } 1939 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
1940 } // else the autopilot will get us close
1941 }
1942 else
1943 { // its a scripted sit
1944 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1945 I *am* using the part's position this time because we have no real idea how far away
1946 the avatar is from the sit target. */
1947 RemoveFromPhysicalScene();
1829 } 1948 }
1830
1831 cameraAtOffset = part.GetCameraAtOffset();
1832 cameraEyeOffset = part.GetCameraEyeOffset();
1833 forceMouselook = part.GetForceMouselook();
1834 } 1949 }
1835 1950 else return; // physactor is null!
1836 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 1951
1837 m_requestedSitTargetUUID = targetID; 1952 Vector3 offsetr; // = offset * partIRot;
1953 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
1954 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
1955 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
1956 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
1957 offsetr = offset * partIRot;
1958//
1959 // else
1960 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
1961 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
1962 // (offset * partRot);
1963 // }
1964
1965//Console.WriteLine(" ");
1966//Console.WriteLine("link number ={0}", part.LinkNum);
1967//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
1968//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
1969//Console.WriteLine("Click offst ={0}", offset);
1970//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
1971//Console.WriteLine("offsetr ={0}", offsetr);
1972//Console.WriteLine("Camera At ={0}", cameraAtOffset);
1973//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
1974
1975 ControllingClient.SendSitResponse(part.UUID, offsetr, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
1976 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1838 // This calls HandleAgentSit twice, once from here, and the client calls 1977 // This calls HandleAgentSit twice, once from here, and the client calls
1839 // HandleAgentSit itself after it gets to the location 1978 // HandleAgentSit itself after it gets to the location
1840 // It doesn't get to the location until we've moved them there though 1979 // It doesn't get to the location until we've moved them there though
1841 // which happens in HandleAgentSit :P 1980 // which happens in HandleAgentSit :P
1842 m_autopilotMoving = autopilot; 1981 m_autopilotMoving = autopilot;
1843 m_autoPilotTarget = pos; 1982 m_autoPilotTarget = autopilotTarget;
1844 m_sitAtAutoTarget = autopilot; 1983 m_sitAtAutoTarget = autopilot;
1984 m_initialSitTarget = autopilotTarget;
1845 if (!autopilot) 1985 if (!autopilot)
1846 HandleAgentSit(remoteClient, UUID); 1986 HandleAgentSit(remoteClient, UUID);
1847 } 1987 }
@@ -2136,31 +2276,66 @@ namespace OpenSim.Region.Framework.Scenes
2136 { 2276 {
2137 if (part != null) 2277 if (part != null)
2138 { 2278 {
2279//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2139 if (part.GetAvatarOnSitTarget() == UUID) 2280 if (part.GetAvatarOnSitTarget() == UUID)
2140 { 2281 {
2282//Console.WriteLine("Scripted Sit");
2283 // Scripted sit
2141 Vector3 sitTargetPos = part.SitTargetPosition; 2284 Vector3 sitTargetPos = part.SitTargetPosition;
2142 Quaternion sitTargetOrient = part.SitTargetOrientation; 2285 Quaternion sitTargetOrient = part.SitTargetOrientation;
2143
2144 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2145 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2146
2147 //Quaternion result = (sitTargetOrient * vq) * nq;
2148
2149 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2286 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2150 m_pos += SIT_TARGET_ADJUSTMENT; 2287 m_pos += SIT_TARGET_ADJUSTMENT;
2151 m_bodyRot = sitTargetOrient; 2288 m_bodyRot = sitTargetOrient;
2152 //Rotation = sitTargetOrient;
2153 m_parentPosition = part.AbsolutePosition; 2289 m_parentPosition = part.AbsolutePosition;
2154 2290 part.IsOccupied = true;
2155 //SendTerseUpdateToAllClients(); 2291Console.WriteLine("Scripted Sit ofset {0}", m_pos);
2156 } 2292 }
2157 else 2293 else
2158 { 2294 {
2159 m_pos -= part.AbsolutePosition; 2295 // if m_avUnscriptedSitPos is zero then Av sits above center
2296 // Else Av sits at m_avUnscriptedSitPos
2297
2298 // Non-scripted sit by Kitto Flora 21Nov09
2299 // Calculate angle of line from prim to Av
2300 Quaternion partIRot;
2301// if (part.LinkNum == 1)
2302// { // Root prim of linkset
2303// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2304// }
2305// else
2306// { // single or child prim
2307 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2308// }
2309 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2310 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2311 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2312 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2313 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2314 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2315 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2316 // Av sits at world euler <0,0, z>, translated by part rotation
2317 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2318
2160 m_parentPosition = part.AbsolutePosition; 2319 m_parentPosition = part.AbsolutePosition;
2161 } 2320 part.IsOccupied = true;
2321 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2322 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2323 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2324 m_avUnscriptedSitPos; // adds click offset, if any
2325 //Set up raytrace to find top surface of prim
2326 Vector3 size = part.Scale;
2327 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2328 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2329 Vector3 down = new Vector3(0f, 0f, -1f);
2330//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2331 m_scene.PhysicsScene.RaycastWorld(
2332 start, // Vector3 position,
2333 down, // Vector3 direction,
2334 mag, // float length,
2335 SitAltitudeCallback); // retMethod
2336 } // end scripted/not
2162 } 2337 }
2163 else 2338 else // no Av
2164 { 2339 {
2165 return; 2340 return;
2166 } 2341 }
@@ -2172,11 +2347,36 @@ namespace OpenSim.Region.Framework.Scenes
2172 2347
2173 Animator.TrySetMovementAnimation(sitAnimation); 2348 Animator.TrySetMovementAnimation(sitAnimation);
2174 SendFullUpdateToAllClients(); 2349 SendFullUpdateToAllClients();
2175 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2176 // So we're also sending a terse update (which has avatar rotation)
2177 // [Update] We do now.
2178 //SendTerseUpdateToAllClients();
2179 } 2350 }
2351
2352 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2353 {
2354 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2355 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2356 if(hitYN)
2357 {
2358 // m_pos = Av offset from prim center to make look like on center
2359 // m_parentPosition = Actual center pos of prim
2360 // collisionPoint = spot on prim where we want to sit
2361 // collisionPoint.Z = global sit surface height
2362 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2363 Quaternion partIRot;
2364// if (part.LinkNum == 1)
2365/// { // Root prim of linkset
2366// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2367// }
2368// else
2369// { // single or child prim
2370 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2371// }
2372 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2373 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2374//Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2375 m_pos += offset;
2376// ControllingClient.SendClearFollowCamProperties(part.UUID);
2377
2378 }
2379 } // End SitAltitudeCallback KF.
2180 2380
2181 /// <summary> 2381 /// <summary>
2182 /// Event handler for the 'Always run' setting on the client 2382 /// Event handler for the 'Always run' setting on the client
@@ -2206,7 +2406,7 @@ namespace OpenSim.Region.Framework.Scenes
2206 /// </summary> 2406 /// </summary>
2207 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2407 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2208 /// <param name="rotation">The direction in which this avatar should now face. 2408 /// <param name="rotation">The direction in which this avatar should now face.
2209 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2409 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2210 { 2410 {
2211 if (m_isChildAgent) 2411 if (m_isChildAgent)
2212 { 2412 {
@@ -2247,10 +2447,11 @@ namespace OpenSim.Region.Framework.Scenes
2247 Rotation = rotation; 2447 Rotation = rotation;
2248 Vector3 direc = vec * rotation; 2448 Vector3 direc = vec * rotation;
2249 direc.Normalize(); 2449 direc.Normalize();
2450 PhysicsActor actor = m_physicsActor;
2451 if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up.
2250 2452
2251 direc *= 0.03f * 128f * m_speedModifier; 2453 direc *= 0.03f * 128f * m_speedModifier;
2252 2454
2253 PhysicsActor actor = m_physicsActor;
2254 if (actor != null) 2455 if (actor != null)
2255 { 2456 {
2256 if (actor.Flying) 2457 if (actor.Flying)
@@ -2272,18 +2473,25 @@ namespace OpenSim.Region.Framework.Scenes
2272 { 2473 {
2273 if (direc.Z > 2.0f) 2474 if (direc.Z > 2.0f)
2274 { 2475 {
2275 direc.Z *= 3.0f; 2476 if(m_animator.m_animTickJump == -1)
2276 2477 {
2277 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2478 direc.Z *= 3.0f; // jump
2278 Animator.TrySetMovementAnimation("PREJUMP"); 2479 }
2279 Animator.TrySetMovementAnimation("JUMP"); 2480 else
2481 {
2482 direc.Z *= 0.1f; // prejump
2483 }
2484 /* Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs
2485 Animator.TrySetMovementAnimation("PREJUMP");
2486 Animator.TrySetMovementAnimation("JUMP");
2487 */
2280 } 2488 }
2281 } 2489 }
2282 } 2490 }
2283 2491
2284 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2492 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2285 m_forceToApply = direc; 2493 m_forceToApply = direc;
2286 2494 m_isNudging = Nudging;
2287 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2495 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2288 } 2496 }
2289 2497
@@ -2298,7 +2506,7 @@ namespace OpenSim.Region.Framework.Scenes
2298 const float POSITION_TOLERANCE = 0.05f; 2506 const float POSITION_TOLERANCE = 0.05f;
2299 //const int TIME_MS_TOLERANCE = 3000; 2507 //const int TIME_MS_TOLERANCE = 3000;
2300 2508
2301 SendPrimUpdates(); 2509
2302 2510
2303 if (m_newCoarseLocations) 2511 if (m_newCoarseLocations)
2304 { 2512 {
@@ -2334,6 +2542,9 @@ namespace OpenSim.Region.Framework.Scenes
2334 CheckForBorderCrossing(); 2542 CheckForBorderCrossing();
2335 CheckForSignificantMovement(); // sends update to the modules. 2543 CheckForSignificantMovement(); // sends update to the modules.
2336 } 2544 }
2545
2546 //Sending prim updates AFTER the avatar terse updates are sent
2547 SendPrimUpdates();
2337 } 2548 }
2338 2549
2339 #endregion 2550 #endregion
@@ -3150,6 +3361,7 @@ namespace OpenSim.Region.Framework.Scenes
3150 m_callbackURI = cAgent.CallbackURI; 3361 m_callbackURI = cAgent.CallbackURI;
3151 3362
3152 m_pos = cAgent.Position; 3363 m_pos = cAgent.Position;
3364
3153 m_velocity = cAgent.Velocity; 3365 m_velocity = cAgent.Velocity;
3154 m_CameraCenter = cAgent.Center; 3366 m_CameraCenter = cAgent.Center;
3155 //m_avHeight = cAgent.Size.Z; 3367 //m_avHeight = cAgent.Size.Z;
@@ -3238,14 +3450,25 @@ namespace OpenSim.Region.Framework.Scenes
3238 { 3450 {
3239 if (m_forceToApply.HasValue) 3451 if (m_forceToApply.HasValue)
3240 { 3452 {
3241 Vector3 force = m_forceToApply.Value;
3242 3453
3454 Vector3 force = m_forceToApply.Value;
3243 m_updateflag = true; 3455 m_updateflag = true;
3244// movementvector = force;
3245 Velocity = force; 3456 Velocity = force;
3246 3457
3247 m_forceToApply = null; 3458 m_forceToApply = null;
3248 } 3459 }
3460 else
3461 {
3462 if (m_isNudging)
3463 {
3464 Vector3 force = Vector3.Zero;
3465
3466 m_updateflag = true;
3467 Velocity = force;
3468 m_isNudging = false;
3469 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3470 }
3471 }
3249 } 3472 }
3250 3473
3251 public override void SetText(string text, Vector3 color, double alpha) 3474 public override void SetText(string text, Vector3 color, double alpha)
@@ -3296,18 +3519,29 @@ namespace OpenSim.Region.Framework.Scenes
3296 { 3519 {
3297 if (e == null) 3520 if (e == null)
3298 return; 3521 return;
3299 3522
3300 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3523 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3301 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3302 // as of this comment the interval is set in AddToPhysicalScene 3524 // as of this comment the interval is set in AddToPhysicalScene
3303 if (Animator!=null) 3525 if (Animator!=null)
3304 Animator.UpdateMovementAnimations(); 3526 {
3527 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3528 { // else its will lock out other animation changes, like ground sit.
3529 Animator.UpdateMovementAnimations();
3530 m_updateCount--;
3531 }
3532 }
3305 3533
3306 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3534 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3307 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3535 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3308 3536
3309 CollisionPlane = Vector4.UnitW; 3537 CollisionPlane = Vector4.UnitW;
3310 3538
3539 if (m_lastColCount != coldata.Count)
3540 {
3541 m_updateCount = UPDATE_COUNT;
3542 m_lastColCount = coldata.Count;
3543 }
3544
3311 if (coldata.Count != 0 && Animator != null) 3545 if (coldata.Count != 0 && Animator != null)
3312 { 3546 {
3313 switch (Animator.CurrentMovementAnimation) 3547 switch (Animator.CurrentMovementAnimation)
@@ -3511,7 +3745,10 @@ namespace OpenSim.Region.Framework.Scenes
3511 m_scene = scene; 3745 m_scene = scene;
3512 3746
3513 RegisterToEvents(); 3747 RegisterToEvents();
3514 3748 if (m_controllingClient != null)
3749 {
3750 m_controllingClient.ProcessPendingPackets();
3751 }
3515 /* 3752 /*
3516 AbsolutePosition = client.StartPos; 3753 AbsolutePosition = client.StartPos;
3517 3754
@@ -3742,6 +3979,32 @@ namespace OpenSim.Region.Framework.Scenes
3742 return; 3979 return;
3743 } 3980 }
3744 3981
3982 XmlDocument doc = new XmlDocument();
3983 string stateData = String.Empty;
3984
3985 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
3986 if (attServ != null)
3987 {
3988 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
3989 stateData = attServ.Get(ControllingClient.AgentId.ToString());
3990 doc.LoadXml(stateData);
3991 }
3992
3993 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
3994
3995 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
3996 if (nodes.Count > 0)
3997 {
3998 foreach (XmlNode n in nodes)
3999 {
4000 XmlElement elem = (XmlElement)n;
4001 string itemID = elem.GetAttribute("ItemID");
4002 string xml = elem.InnerXml;
4003
4004 itemData[new UUID(itemID)] = xml;
4005 }
4006 }
4007
3745 List<int> attPoints = m_appearance.GetAttachedPoints(); 4008 List<int> attPoints = m_appearance.GetAttachedPoints();
3746 foreach (int p in attPoints) 4009 foreach (int p in attPoints)
3747 { 4010 {
@@ -3761,9 +4024,26 @@ namespace OpenSim.Region.Framework.Scenes
3761 4024
3762 try 4025 try
3763 { 4026 {
3764 // Rez from inventory 4027 string xmlData;
3765 UUID asset 4028 XmlDocument d = new XmlDocument();
3766 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p); 4029 UUID asset;
4030 if (itemData.TryGetValue(itemID, out xmlData))
4031 {
4032 d.LoadXml(xmlData);
4033 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID);
4034
4035 // Rez from inventory
4036 asset
4037 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d);
4038
4039 }
4040 else
4041 {
4042 // Rez from inventory (with a null doc to let
4043 // CHANGED_OWNER happen)
4044 asset
4045 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, null);
4046 }
3767 4047
3768 m_log.InfoFormat( 4048 m_log.InfoFormat(
3769 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})", 4049 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})",
@@ -3914,5 +4194,16 @@ namespace OpenSim.Region.Framework.Scenes
3914 m_reprioritization_called = false; 4194 m_reprioritization_called = false;
3915 } 4195 }
3916 } 4196 }
4197
4198 private Vector3 Quat2Euler(Quaternion rot){
4199 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4200 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4201 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4202 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4203 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4204 return(new Vector3(x,y,z));
4205 }
4206
4207
3917 } 4208 }
3918} 4209}