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.cs1062
1 files changed, 834 insertions, 228 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index c223b4b..06e3c0e 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Xml;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.Reflection; 31using System.Reflection;
31using System.Timers; 32using System.Timers;
@@ -72,7 +73,7 @@ namespace OpenSim.Region.Framework.Scenes
72// { 73// {
73// m_log.Debug("[ScenePresence] Destructor called"); 74// m_log.Debug("[ScenePresence] Destructor called");
74// } 75// }
75 76
76 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
77 78
78 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
@@ -88,7 +89,9 @@ namespace OpenSim.Region.Framework.Scenes
88 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
89 /// issue #1716 90 /// issue #1716
90 /// </summary> 91 /// </summary>
91 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 92// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
93 // Value revised by KF 091121 by comparison with SL.
94 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f);
92 95
93 public UUID currentParcelUUID = UUID.Zero; 96 public UUID currentParcelUUID = UUID.Zero;
94 97
@@ -122,8 +125,11 @@ namespace OpenSim.Region.Framework.Scenes
122 public Vector3 lastKnownAllowedPosition; 125 public Vector3 lastKnownAllowedPosition;
123 public bool sentMessageAboutRestrictedParcelFlyingDown; 126 public bool sentMessageAboutRestrictedParcelFlyingDown;
124 public Vector4 CollisionPlane = Vector4.UnitW; 127 public Vector4 CollisionPlane = Vector4.UnitW;
125 128
129 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
130 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
126 private Vector3 m_lastPosition; 131 private Vector3 m_lastPosition;
132 private Vector3 m_lastWorldPosition;
127 private Quaternion m_lastRotation; 133 private Quaternion m_lastRotation;
128 private Vector3 m_lastVelocity; 134 private Vector3 m_lastVelocity;
129 //private int m_lastTerseSent; 135 //private int m_lastTerseSent;
@@ -156,7 +162,6 @@ namespace OpenSim.Region.Framework.Scenes
156 private int m_perfMonMS; 162 private int m_perfMonMS;
157 163
158 private bool m_setAlwaysRun; 164 private bool m_setAlwaysRun;
159
160 private bool m_forceFly; 165 private bool m_forceFly;
161 private bool m_flyDisabled; 166 private bool m_flyDisabled;
162 167
@@ -180,7 +185,8 @@ namespace OpenSim.Region.Framework.Scenes
180 protected RegionInfo m_regionInfo; 185 protected RegionInfo m_regionInfo;
181 protected ulong crossingFromRegion; 186 protected ulong crossingFromRegion;
182 187
183 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 188 private readonly Vector3[] Dir_Vectors = new Vector3[11];
189 private bool m_isNudging = false;
184 190
185 // Position of agent's camera in world (region cordinates) 191 // Position of agent's camera in world (region cordinates)
186 protected Vector3 m_CameraCenter; 192 protected Vector3 m_CameraCenter;
@@ -205,17 +211,25 @@ namespace OpenSim.Region.Framework.Scenes
205 private bool m_autopilotMoving; 211 private bool m_autopilotMoving;
206 private Vector3 m_autoPilotTarget; 212 private Vector3 m_autoPilotTarget;
207 private bool m_sitAtAutoTarget; 213 private bool m_sitAtAutoTarget;
214 private Vector3 m_initialSitTarget = Vector3.Zero; //KF: First estimate of where to sit
208 215
209 private string m_nextSitAnimation = String.Empty; 216 private string m_nextSitAnimation = String.Empty;
210 217
211 //PauPaw:Proper PID Controler for autopilot************ 218 //PauPaw:Proper PID Controler for autopilot************
212 private bool m_moveToPositionInProgress; 219 private bool m_moveToPositionInProgress;
213 private Vector3 m_moveToPositionTarget; 220 private Vector3 m_moveToPositionTarget;
221 private Quaternion m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
214 222
215 private bool m_followCamAuto; 223 private bool m_followCamAuto;
216 224
217 private int m_movementUpdateCount; 225 private int m_movementUpdateCount;
226 private int m_lastColCount = -1; //KF: Look for Collision chnages
227 private int m_updateCount = 0; //KF: Update Anims for a while
228 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
218 private const int NumMovementsBetweenRayCast = 5; 229 private const int NumMovementsBetweenRayCast = 5;
230 private List<uint> m_lastColliders = new List<uint>();
231
232 private object m_syncRoot = new Object();
219 233
220 private bool CameraConstraintActive; 234 private bool CameraConstraintActive;
221 //private int m_moveToPositionStateStatus; 235 //private int m_moveToPositionStateStatus;
@@ -242,7 +256,9 @@ namespace OpenSim.Region.Framework.Scenes
242 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 256 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
243 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 257 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
244 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 258 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
245 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 259 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
260 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
261 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
246 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 262 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
247 } 263 }
248 264
@@ -449,9 +465,18 @@ namespace OpenSim.Region.Framework.Scenes
449 get 465 get
450 { 466 {
451 PhysicsActor actor = m_physicsActor; 467 PhysicsActor actor = m_physicsActor;
452 if (actor != null) 468// if (actor != null)
469 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting!
453 m_pos = actor.Position; 470 m_pos = actor.Position;
454 471
472 // If we're sitting, we need to update our position
473 if (m_parentID != 0)
474 {
475 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
476 if (part != null)
477 m_parentPosition = part.AbsolutePosition;
478 }
479
455 return m_parentPosition + m_pos; 480 return m_parentPosition + m_pos;
456 } 481 }
457 set 482 set
@@ -470,7 +495,8 @@ namespace OpenSim.Region.Framework.Scenes
470 } 495 }
471 } 496 }
472 497
473 m_pos = value; 498 if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting!
499 m_pos = value;
474 m_parentPosition = Vector3.Zero; 500 m_parentPosition = Vector3.Zero;
475 } 501 }
476 } 502 }
@@ -514,10 +540,39 @@ namespace OpenSim.Region.Framework.Scenes
514 } 540 }
515 } 541 }
516 542
543 public Quaternion OffsetRotation
544 {
545 get { return m_offsetRotation; }
546 set { m_offsetRotation = value; }
547 }
548
517 public Quaternion Rotation 549 public Quaternion Rotation
518 { 550 {
519 get { return m_bodyRot; } 551 get {
520 set { m_bodyRot = value; } 552 if (m_parentID != 0)
553 {
554 if (m_offsetRotation != null)
555 {
556 return m_offsetRotation;
557 }
558 else
559 {
560 return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
561 }
562
563 }
564 else
565 {
566 return m_bodyRot;
567 }
568 }
569 set {
570 m_bodyRot = value;
571 if (m_parentID != 0)
572 {
573 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
574 }
575 }
521 } 576 }
522 577
523 public Quaternion PreviousRotation 578 public Quaternion PreviousRotation
@@ -542,11 +597,21 @@ namespace OpenSim.Region.Framework.Scenes
542 597
543 private uint m_parentID; 598 private uint m_parentID;
544 599
600
601 private UUID m_linkedPrim;
602
545 public uint ParentID 603 public uint ParentID
546 { 604 {
547 get { return m_parentID; } 605 get { return m_parentID; }
548 set { m_parentID = value; } 606 set { m_parentID = value; }
549 } 607 }
608
609 public UUID LinkedPrim
610 {
611 get { return m_linkedPrim; }
612 set { m_linkedPrim = value; }
613 }
614
550 public float Health 615 public float Health
551 { 616 {
552 get { return m_health; } 617 get { return m_health; }
@@ -668,7 +733,7 @@ namespace OpenSim.Region.Framework.Scenes
668 CreateSceneViewer(); 733 CreateSceneViewer();
669 m_animator = new ScenePresenceAnimator(this); 734 m_animator = new ScenePresenceAnimator(this);
670 } 735 }
671 736
672 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() 737 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this()
673 { 738 {
674 m_rootRegionHandle = reginfo.RegionHandle; 739 m_rootRegionHandle = reginfo.RegionHandle;
@@ -700,16 +765,16 @@ namespace OpenSim.Region.Framework.Scenes
700 m_reprioritization_timer.AutoReset = false; 765 m_reprioritization_timer.AutoReset = false;
701 766
702 AdjustKnownSeeds(); 767 AdjustKnownSeeds();
703
704 // TODO: I think, this won't send anything, as we are still a child here...
705 Animator.TrySetMovementAnimation("STAND"); 768 Animator.TrySetMovementAnimation("STAND");
706
707 // we created a new ScenePresence (a new child agent) in a fresh region. 769 // we created a new ScenePresence (a new child agent) in a fresh region.
708 // Request info about all the (root) agents in this region 770 // Request info about all the (root) agents in this region
709 // Note: This won't send data *to* other clients in that region (children don't send) 771 // Note: This won't send data *to* other clients in that region (children don't send)
710 SendInitialFullUpdateToAllClients(); 772 SendInitialFullUpdateToAllClients();
711
712 RegisterToEvents(); 773 RegisterToEvents();
774 if (m_controllingClient != null)
775 {
776 m_controllingClient.ProcessPendingPackets();
777 }
713 SetDirectionVectors(); 778 SetDirectionVectors();
714 } 779 }
715 780
@@ -759,25 +824,47 @@ namespace OpenSim.Region.Framework.Scenes
759 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 824 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
760 Dir_Vectors[4] = Vector3.UnitZ; //UP 825 Dir_Vectors[4] = Vector3.UnitZ; //UP
761 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 826 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
762 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 827 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
763 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 828 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
764 Dir_Vectors[7] = -Vector3.UnitX; //BACK 829 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
830 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
831 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
765 } 832 }
766 833
767 private Vector3[] GetWalkDirectionVectors() 834 private Vector3[] GetWalkDirectionVectors()
768 { 835 {
769 Vector3[] vector = new Vector3[9]; 836 Vector3[] vector = new Vector3[11];
770 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 837 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
771 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 838 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
772 vector[2] = Vector3.UnitY; //LEFT 839 vector[2] = Vector3.UnitY; //LEFT
773 vector[3] = -Vector3.UnitY; //RIGHT 840 vector[3] = -Vector3.UnitY; //RIGHT
774 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 841 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
775 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 842 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
776 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 843 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
777 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 844 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
778 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 845 vector[8] = Vector3.UnitY; //LEFT_NUDGE
846 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
847 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
779 return vector; 848 return vector;
780 } 849 }
850
851 private bool[] GetDirectionIsNudge()
852 {
853 bool[] isNudge = new bool[11];
854 isNudge[0] = false; //FORWARD
855 isNudge[1] = false; //BACK
856 isNudge[2] = false; //LEFT
857 isNudge[3] = false; //RIGHT
858 isNudge[4] = false; //UP
859 isNudge[5] = false; //DOWN
860 isNudge[6] = true; //FORWARD_NUDGE
861 isNudge[7] = true; //BACK_NUDGE
862 isNudge[8] = true; //LEFT_NUDGE
863 isNudge[9] = true; //RIGHT_NUDGE
864 isNudge[10] = true; //DOWN_Nudge
865 return isNudge;
866 }
867
781 868
782 #endregion 869 #endregion
783 870
@@ -839,6 +926,52 @@ namespace OpenSim.Region.Framework.Scenes
839 pos.Y = crossedBorder.BorderLine.Z - 1; 926 pos.Y = crossedBorder.BorderLine.Z - 1;
840 } 927 }
841 928
929 //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet.
930 //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent,
931 //they'll bypass the landing point. But I can't think of any decent way of fixing this.
932 if (KnownChildRegionHandles.Count == 0)
933 {
934 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
935 if (land != null)
936 {
937 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
938 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)
939 {
940 pos = land.LandData.UserLocation;
941 }
942 }
943 }
944
945 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0)
946 {
947 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128);
948
949 if (pos.X < 0)
950 {
951 emergencyPos.X = (int)Constants.RegionSize + pos.X;
952 if (!(pos.Y < 0))
953 emergencyPos.Y = pos.Y;
954 if (!(pos.Z < 0))
955 emergencyPos.Z = pos.Z;
956 }
957 if (pos.Y < 0)
958 {
959 emergencyPos.Y = (int)Constants.RegionSize + pos.Y;
960 if (!(pos.X < 0))
961 emergencyPos.X = pos.X;
962 if (!(pos.Z < 0))
963 emergencyPos.Z = pos.Z;
964 }
965 if (pos.Z < 0)
966 {
967 emergencyPos.Z = 128;
968 if (!(pos.Y < 0))
969 emergencyPos.Y = pos.Y;
970 if (!(pos.X < 0))
971 emergencyPos.X = pos.X;
972 }
973 }
974
842 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 975 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
843 { 976 {
844 m_log.WarnFormat( 977 m_log.WarnFormat(
@@ -960,12 +1093,17 @@ namespace OpenSim.Region.Framework.Scenes
960 { 1093 {
961 if (PhysicsActor != null) 1094 if (PhysicsActor != null)
962 { 1095 {
963 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1096 try
964 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall; 1097 {
965 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); 1098 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
966 m_physicsActor.UnSubscribeEvents(); 1099 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall;
967 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1100 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
968 PhysicsActor = null; 1101 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1102 m_physicsActor.UnSubscribeEvents();
1103 PhysicsActor = null;
1104 }
1105 catch
1106 { }
969 } 1107 }
970 } 1108 }
971 1109
@@ -976,9 +1114,10 @@ namespace OpenSim.Region.Framework.Scenes
976 public void Teleport(Vector3 pos) 1114 public void Teleport(Vector3 pos)
977 { 1115 {
978 bool isFlying = false; 1116 bool isFlying = false;
1117
979 if (m_physicsActor != null) 1118 if (m_physicsActor != null)
980 isFlying = m_physicsActor.Flying; 1119 isFlying = m_physicsActor.Flying;
981 1120
982 RemoveFromPhysicalScene(); 1121 RemoveFromPhysicalScene();
983 Velocity = Vector3.Zero; 1122 Velocity = Vector3.Zero;
984 AbsolutePosition = pos; 1123 AbsolutePosition = pos;
@@ -990,6 +1129,7 @@ namespace OpenSim.Region.Framework.Scenes
990 } 1129 }
991 1130
992 SendTerseUpdateToAllClients(); 1131 SendTerseUpdateToAllClients();
1132
993 } 1133 }
994 1134
995 public void TeleportWithMomentum(Vector3 pos) 1135 public void TeleportWithMomentum(Vector3 pos)
@@ -1103,7 +1243,6 @@ namespace OpenSim.Region.Framework.Scenes
1103 pos.Z = ground + 1.5f; 1243 pos.Z = ground + 1.5f;
1104 AbsolutePosition = pos; 1244 AbsolutePosition = pos;
1105 } 1245 }
1106
1107 m_isChildAgent = false; 1246 m_isChildAgent = false;
1108 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 1247 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1109 MakeRootAgent(AbsolutePosition, m_flying); 1248 MakeRootAgent(AbsolutePosition, m_flying);
@@ -1202,6 +1341,7 @@ namespace OpenSim.Region.Framework.Scenes
1202 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); 1341 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902");
1203 1342
1204 m_pos = m_LastFinitePos; 1343 m_pos = m_LastFinitePos;
1344
1205 if (!m_pos.IsFinite()) 1345 if (!m_pos.IsFinite())
1206 { 1346 {
1207 m_pos.X = 127f; 1347 m_pos.X = 127f;
@@ -1268,7 +1408,6 @@ namespace OpenSim.Region.Framework.Scenes
1268 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1408 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1269 } 1409 }
1270 } 1410 }
1271
1272 lock (scriptedcontrols) 1411 lock (scriptedcontrols)
1273 { 1412 {
1274 if (scriptedcontrols.Count > 0) 1413 if (scriptedcontrols.Count > 0)
@@ -1283,6 +1422,9 @@ namespace OpenSim.Region.Framework.Scenes
1283 1422
1284 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1423 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1285 { 1424 {
1425 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1426 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1427
1286 // TODO: This doesn't prevent the user from walking yet. 1428 // TODO: This doesn't prevent the user from walking yet.
1287 // Setting parent ID would fix this, if we knew what value 1429 // Setting parent ID would fix this, if we knew what value
1288 // to use. Or we could add a m_isSitting variable. 1430 // to use. Or we could add a m_isSitting variable.
@@ -1331,12 +1473,20 @@ namespace OpenSim.Region.Framework.Scenes
1331 if (actor.Flying != oldflying) 1473 if (actor.Flying != oldflying)
1332 update_movementflag = true; 1474 update_movementflag = true;
1333 1475
1476 if (m_animator.m_jumping) // add for jumping
1477 update_movementflag = true;
1478
1334 if (q != m_bodyRot) 1479 if (q != m_bodyRot)
1335 { 1480 {
1336 m_bodyRot = q; 1481 m_bodyRot = q;
1337 update_rotation = true; 1482 update_rotation = true;
1338 } 1483 }
1339 1484
1485 //guilty until proven innocent..
1486 bool Nudging = true;
1487 //Basically, if there is at least one non-nudge control then we don't need
1488 //to worry about stopping the avatar
1489
1340 if (m_parentID == 0) 1490 if (m_parentID == 0)
1341 { 1491 {
1342 bool bAllowUpdateMoveToPosition = false; 1492 bool bAllowUpdateMoveToPosition = false;
@@ -1351,9 +1501,12 @@ namespace OpenSim.Region.Framework.Scenes
1351 else 1501 else
1352 dirVectors = Dir_Vectors; 1502 dirVectors = Dir_Vectors;
1353 1503
1354 // The fact that m_movementflag is a byte needs to be fixed 1504 bool[] isNudge = GetDirectionIsNudge();
1355 // it really should be a uint 1505
1356 uint nudgehack = 250; 1506
1507
1508
1509
1357 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1510 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1358 { 1511 {
1359 if (((uint)flags & (uint)DCF) != 0) 1512 if (((uint)flags & (uint)DCF) != 0)
@@ -1363,40 +1516,28 @@ namespace OpenSim.Region.Framework.Scenes
1363 try 1516 try
1364 { 1517 {
1365 agent_control_v3 += dirVectors[i]; 1518 agent_control_v3 += dirVectors[i];
1366 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1519 if (isNudge[i] == false)
1520 {
1521 Nudging = false;
1522 }
1367 } 1523 }
1368 catch (IndexOutOfRangeException) 1524 catch (IndexOutOfRangeException)
1369 { 1525 {
1370 // Why did I get this? 1526 // Why did I get this?
1371 } 1527 }
1372 1528
1373 if ((m_movementflag & (byte)(uint)DCF) == 0) 1529 if ((m_movementflag & (uint)DCF) == 0)
1374 { 1530 {
1375 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1376 {
1377 m_movementflag |= (byte)nudgehack;
1378 }
1379 m_movementflag += (byte)(uint)DCF; 1531 m_movementflag += (byte)(uint)DCF;
1380 update_movementflag = true; 1532 update_movementflag = true;
1381 } 1533 }
1382 } 1534 }
1383 else 1535 else
1384 { 1536 {
1385 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1537 if ((m_movementflag & (uint)DCF) != 0)
1386 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1387 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1388 ) // This or is for Nudge forward
1389 { 1538 {
1390 m_movementflag -= ((byte)(uint)DCF); 1539 m_movementflag -= (byte)(uint)DCF;
1391
1392 update_movementflag = true; 1540 update_movementflag = true;
1393 /*
1394 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1395 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1396 {
1397 m_log.Debug("Removed Hack flag");
1398 }
1399 */
1400 } 1541 }
1401 else 1542 else
1402 { 1543 {
@@ -1405,7 +1546,6 @@ namespace OpenSim.Region.Framework.Scenes
1405 } 1546 }
1406 i++; 1547 i++;
1407 } 1548 }
1408
1409 //Paupaw:Do Proper PID for Autopilot here 1549 //Paupaw:Do Proper PID for Autopilot here
1410 if (bResetMoveToPosition) 1550 if (bResetMoveToPosition)
1411 { 1551 {
@@ -1440,6 +1580,9 @@ namespace OpenSim.Region.Framework.Scenes
1440 // Ignore z component of vector 1580 // Ignore z component of vector
1441 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1581 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1442 LocalVectorToTarget2D.Normalize(); 1582 LocalVectorToTarget2D.Normalize();
1583
1584 //We're not nudging
1585 Nudging = false;
1443 agent_control_v3 += LocalVectorToTarget2D; 1586 agent_control_v3 += LocalVectorToTarget2D;
1444 1587
1445 // update avatar movement flags. the avatar coordinate system is as follows: 1588 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1530,13 +1673,13 @@ namespace OpenSim.Region.Framework.Scenes
1530 // m_log.DebugFormat( 1673 // m_log.DebugFormat(
1531 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1674 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1532 1675
1533 AddNewMovement(agent_control_v3, q); 1676 AddNewMovement(agent_control_v3, q, Nudging);
1534 1677
1535 1678
1536 } 1679 }
1537 } 1680 }
1538 1681
1539 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1682 if (update_movementflag && !SitGround)
1540 Animator.UpdateMovementAnimations(); 1683 Animator.UpdateMovementAnimations();
1541 1684
1542 m_scene.EventManager.TriggerOnClientMovement(this); 1685 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1551,7 +1694,6 @@ namespace OpenSim.Region.Framework.Scenes
1551 m_sitAtAutoTarget = false; 1694 m_sitAtAutoTarget = false;
1552 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1695 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1553 //proxy.PCode = (byte)PCode.ParticleSystem; 1696 //proxy.PCode = (byte)PCode.ParticleSystem;
1554
1555 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1697 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1556 proxyObjectGroup.AttachToScene(m_scene); 1698 proxyObjectGroup.AttachToScene(m_scene);
1557 1699
@@ -1593,7 +1735,7 @@ namespace OpenSim.Region.Framework.Scenes
1593 } 1735 }
1594 m_moveToPositionInProgress = true; 1736 m_moveToPositionInProgress = true;
1595 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1737 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1596 } 1738 }
1597 catch (Exception ex) 1739 catch (Exception ex)
1598 { 1740 {
1599 //Why did I get this error? 1741 //Why did I get this error?
@@ -1615,7 +1757,7 @@ namespace OpenSim.Region.Framework.Scenes
1615 Velocity = Vector3.Zero; 1757 Velocity = Vector3.Zero;
1616 SendFullUpdateToAllClients(); 1758 SendFullUpdateToAllClients();
1617 1759
1618 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1760 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1619 } 1761 }
1620 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1762 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1621 m_requestedSitTargetUUID = UUID.Zero; 1763 m_requestedSitTargetUUID = UUID.Zero;
@@ -1652,50 +1794,85 @@ namespace OpenSim.Region.Framework.Scenes
1652 1794
1653 if (m_parentID != 0) 1795 if (m_parentID != 0)
1654 { 1796 {
1655 m_log.Debug("StandupCode Executed"); 1797 SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID);
1656 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1657 if (part != null) 1798 if (part != null)
1658 { 1799 {
1800 part.TaskInventory.LockItemsForRead(true);
1659 TaskInventoryDictionary taskIDict = part.TaskInventory; 1801 TaskInventoryDictionary taskIDict = part.TaskInventory;
1660 if (taskIDict != null) 1802 if (taskIDict != null)
1661 { 1803 {
1662 lock (taskIDict) 1804 foreach (UUID taskID in taskIDict.Keys)
1663 { 1805 {
1664 foreach (UUID taskID in taskIDict.Keys) 1806 UnRegisterControlEventsToScript(LocalId, taskID);
1665 { 1807 taskIDict[taskID].PermsMask &= ~(
1666 UnRegisterControlEventsToScript(LocalId, taskID); 1808 2048 | //PERMISSION_CONTROL_CAMERA
1667 taskIDict[taskID].PermsMask &= ~( 1809 4); // PERMISSION_TAKE_CONTROLS
1668 2048 | //PERMISSION_CONTROL_CAMERA
1669 4); // PERMISSION_TAKE_CONTROLS
1670 }
1671 } 1810 }
1672
1673 } 1811 }
1812 part.TaskInventory.LockItemsForRead(false);
1674 // Reset sit target. 1813 // Reset sit target.
1675 if (part.GetAvatarOnSitTarget() == UUID) 1814 if (part.GetAvatarOnSitTarget() == UUID)
1676 part.SetAvatarOnSitTarget(UUID.Zero); 1815 part.SetAvatarOnSitTarget(UUID.Zero);
1677
1678 m_parentPosition = part.GetWorldPosition(); 1816 m_parentPosition = part.GetWorldPosition();
1679 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1817 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1680 } 1818 }
1819 // part.GetWorldRotation() is the rotation of the object being sat on
1820 // Rotation is the sittiing Av's rotation
1821
1822 Quaternion partRot;
1823// if (part.LinkNum == 1)
1824// { // Root prim of linkset
1825// partRot = part.ParentGroup.RootPart.RotationOffset;
1826// }
1827// else
1828// { // single or child prim
1829
1830// }
1831 if (part == null) //CW: Part may be gone. llDie() for example.
1832 {
1833 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1834 }
1835 else
1836 {
1837 partRot = part.GetWorldRotation();
1838 }
1839
1840 Quaternion partIRot = Quaternion.Inverse(partRot);
1841
1842 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1843 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1681 1844
1845
1682 if (m_physicsActor == null) 1846 if (m_physicsActor == null)
1683 { 1847 {
1684 AddToPhysicalScene(false); 1848 AddToPhysicalScene(false);
1685 } 1849 }
1686 1850 //CW: If the part isn't null then we can set the current position
1687 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1851 if (part != null)
1688 m_parentPosition = Vector3.Zero; 1852 {
1689 1853 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + ((m_pos - part.OffsetPosition) * partRot); // + av sit offset!
1690 m_parentID = 0; 1854 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1855 part.IsOccupied = false;
1856 part.ParentGroup.DeleteAvatar(ControllingClient.AgentId);
1857 }
1858 else
1859 {
1860 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1861 AbsolutePosition = m_lastWorldPosition;
1862 }
1863
1864 m_parentPosition = Vector3.Zero;
1865 m_parentID = 0;
1866 m_linkedPrim = UUID.Zero;
1867 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1691 SendFullUpdateToAllClients(); 1868 SendFullUpdateToAllClients();
1692 m_requestedSitTargetID = 0; 1869 m_requestedSitTargetID = 0;
1870
1693 if ((m_physicsActor != null) && (m_avHeight > 0)) 1871 if ((m_physicsActor != null) && (m_avHeight > 0))
1694 { 1872 {
1695 SetHeight(m_avHeight); 1873 SetHeight(m_avHeight);
1696 } 1874 }
1697 } 1875 }
1698
1699 Animator.TrySetMovementAnimation("STAND"); 1876 Animator.TrySetMovementAnimation("STAND");
1700 } 1877 }
1701 1878
@@ -1726,13 +1903,9 @@ namespace OpenSim.Region.Framework.Scenes
1726 Vector3 avSitOffSet = part.SitTargetPosition; 1903 Vector3 avSitOffSet = part.SitTargetPosition;
1727 Quaternion avSitOrientation = part.SitTargetOrientation; 1904 Quaternion avSitOrientation = part.SitTargetOrientation;
1728 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1905 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1729 1906 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1730 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1907 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1731 bool SitTargetisSet = 1908 if (SitTargetisSet && !SitTargetOccupied)
1732 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1733 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1734
1735 if (SitTargetisSet && SitTargetUnOccupied)
1736 { 1909 {
1737 //switch the target to this prim 1910 //switch the target to this prim
1738 return part; 1911 return part;
@@ -1746,84 +1919,164 @@ namespace OpenSim.Region.Framework.Scenes
1746 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1919 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1747 { 1920 {
1748 bool autopilot = true; 1921 bool autopilot = true;
1922 Vector3 autopilotTarget = new Vector3();
1923 Quaternion sitOrientation = Quaternion.Identity;
1749 Vector3 pos = new Vector3(); 1924 Vector3 pos = new Vector3();
1750 Quaternion sitOrientation = pSitOrientation;
1751 Vector3 cameraEyeOffset = Vector3.Zero; 1925 Vector3 cameraEyeOffset = Vector3.Zero;
1752 Vector3 cameraAtOffset = Vector3.Zero; 1926 Vector3 cameraAtOffset = Vector3.Zero;
1753 bool forceMouselook = false; 1927 bool forceMouselook = false;
1754 1928
1755 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1929 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1756 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1930 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1757 if (part != null) 1931 if (part == null) return;
1758 { 1932
1759 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1933 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1760 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1934 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1761 1935
1762 // Is a sit target available? 1936 // part is the prim to sit on
1763 Vector3 avSitOffSet = part.SitTargetPosition; 1937 // offset is the world-ref vector distance from that prim center to the click-spot
1764 Quaternion avSitOrientation = part.SitTargetOrientation; 1938 // UUID is the UUID of the Avatar doing the clicking
1765 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1939
1766 1940 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1767 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1941
1768 bool SitTargetisSet = 1942 // Is a sit target available?
1769 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1943 Vector3 avSitOffSet = part.SitTargetPosition;
1770 ( 1944 Quaternion avSitOrientation = part.SitTargetOrientation;
1771 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1945
1772 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1946 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1773 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1947 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1774 ) 1948 Quaternion partRot;
1775 )); 1949// if (part.LinkNum == 1)
1776 1950// { // Root prim of linkset
1777 if (SitTargetisSet && SitTargetUnOccupied) 1951// partRot = part.ParentGroup.RootPart.RotationOffset;
1778 { 1952// }
1779 part.SetAvatarOnSitTarget(UUID); 1953// else
1780 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1954// { // single or child prim
1781 sitOrientation = avSitOrientation; 1955 partRot = part.GetWorldRotation();
1782 autopilot = false; 1956// }
1783 } 1957 Quaternion partIRot = Quaternion.Inverse(partRot);
1784 1958//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1785 pos = part.AbsolutePosition + offset; 1959 // Sit analysis rewritten by KF 091125
1786 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1960 if (SitTargetisSet) // scipted sit
1787 //{ 1961 {
1788 // offset = pos; 1962 if (!part.IsOccupied)
1789 //autopilot = false; 1963 {
1790 //} 1964//Console.WriteLine("Scripted, unoccupied");
1791 if (m_physicsActor != null) 1965 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1792 { 1966 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1793 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1967
1794 // We can remove the physicsActor until they stand up. 1968 Quaternion nrot = avSitOrientation;
1795 m_sitAvatarHeight = m_physicsActor.Size.Z; 1969 if (!part.IsRoot)
1796
1797 if (autopilot)
1798 { 1970 {
1799 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1971 nrot = part.RotationOffset * avSitOrientation;
1800 {
1801 autopilot = false;
1802
1803 RemoveFromPhysicalScene();
1804 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
1805 }
1806 } 1972 }
1807 else 1973 sitOrientation = nrot; // Change rotatione to the scripted one
1974 OffsetRotation = nrot;
1975 autopilot = false; // Jump direct to scripted llSitPos()
1976 }
1977 else
1978 {
1979//Console.WriteLine("Scripted, occupied");
1980 return;
1981 }
1982 }
1983 else // Not Scripted
1984 {
1985 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
1986 {
1987 // large prim & offset, ignore if other Avs sitting
1988// offset.Z -= 0.05f;
1989 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
1990 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
1991
1992//Console.WriteLine(" offset ={0}", offset);
1993//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
1994//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
1995
1996 }
1997 else // small offset
1998 {
1999//Console.WriteLine("Small offset");
2000 if (!part.IsOccupied)
2001 {
2002 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
2003 autopilotTarget = part.AbsolutePosition;
2004//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget);
2005 }
2006 else return; // occupied small
2007 } // end large/small
2008 } // end Scripted/not
2009 cameraAtOffset = part.GetCameraAtOffset();
2010 cameraEyeOffset = part.GetCameraEyeOffset();
2011 forceMouselook = part.GetForceMouselook();
2012 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
2013 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
2014
2015 if (m_physicsActor != null)
2016 {
2017 // If we're not using the client autopilot, we're immediately warping the avatar to the location
2018 // We can remove the physicsActor until they stand up.
2019 m_sitAvatarHeight = m_physicsActor.Size.Z;
2020 if (autopilot)
2021 { // its not a scripted sit
2022// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
2023 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 256.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 256.0f) )
1808 { 2024 {
2025 autopilot = false; // close enough
2026 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2027 Not using the part's position because returning the AV to the last known standing
2028 position is likely to be more friendly, isn't it? */
1809 RemoveFromPhysicalScene(); 2029 RemoveFromPhysicalScene();
1810 } 2030 Velocity = Vector3.Zero;
2031 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
2032 } // else the autopilot will get us close
2033 }
2034 else
2035 { // its a scripted sit
2036 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2037 I *am* using the part's position this time because we have no real idea how far away
2038 the avatar is from the sit target. */
2039 RemoveFromPhysicalScene();
2040 Velocity = Vector3.Zero;
1811 } 2041 }
1812
1813 cameraAtOffset = part.GetCameraAtOffset();
1814 cameraEyeOffset = part.GetCameraEyeOffset();
1815 forceMouselook = part.GetForceMouselook();
1816 } 2042 }
1817 2043 else return; // physactor is null!
1818 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 2044
1819 m_requestedSitTargetUUID = targetID; 2045 Vector3 offsetr; // = offset * partIRot;
2046 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
2047 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
2048 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
2049 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
2050 //offsetr = offset * partIRot;
2051//
2052 // else
2053 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
2054 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
2055 // (offset * partRot);
2056 // }
2057
2058//Console.WriteLine(" ");
2059//Console.WriteLine("link number ={0}", part.LinkNum);
2060//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
2061//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
2062//Console.WriteLine("Click offst ={0}", offset);
2063//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
2064//Console.WriteLine("offsetr ={0}", offsetr);
2065//Console.WriteLine("Camera At ={0}", cameraAtOffset);
2066//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
2067
2068 //NOTE: SendSitResponse should be relative to the GROUP *NOT* THE PRIM if we're sitting on a child
2069 ControllingClient.SendSitResponse(part.ParentGroup.UUID, ((offset * part.RotationOffset) + part.OffsetPosition), sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
2070
2071 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1820 // This calls HandleAgentSit twice, once from here, and the client calls 2072 // This calls HandleAgentSit twice, once from here, and the client calls
1821 // HandleAgentSit itself after it gets to the location 2073 // HandleAgentSit itself after it gets to the location
1822 // It doesn't get to the location until we've moved them there though 2074 // It doesn't get to the location until we've moved them there though
1823 // which happens in HandleAgentSit :P 2075 // which happens in HandleAgentSit :P
1824 m_autopilotMoving = autopilot; 2076 m_autopilotMoving = autopilot;
1825 m_autoPilotTarget = pos; 2077 m_autoPilotTarget = autopilotTarget;
1826 m_sitAtAutoTarget = autopilot; 2078 m_sitAtAutoTarget = autopilot;
2079 m_initialSitTarget = autopilotTarget;
1827 if (!autopilot) 2080 if (!autopilot)
1828 HandleAgentSit(remoteClient, UUID); 2081 HandleAgentSit(remoteClient, UUID);
1829 } 2082 }
@@ -2118,47 +2371,130 @@ namespace OpenSim.Region.Framework.Scenes
2118 { 2371 {
2119 if (part != null) 2372 if (part != null)
2120 { 2373 {
2374//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2121 if (part.GetAvatarOnSitTarget() == UUID) 2375 if (part.GetAvatarOnSitTarget() == UUID)
2122 { 2376 {
2377//Console.WriteLine("Scripted Sit");
2378 // Scripted sit
2123 Vector3 sitTargetPos = part.SitTargetPosition; 2379 Vector3 sitTargetPos = part.SitTargetPosition;
2124 Quaternion sitTargetOrient = part.SitTargetOrientation; 2380 Quaternion sitTargetOrient = part.SitTargetOrientation;
2125
2126 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2127 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2128
2129 //Quaternion result = (sitTargetOrient * vq) * nq;
2130
2131 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2381 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2132 m_pos += SIT_TARGET_ADJUSTMENT; 2382 m_pos += SIT_TARGET_ADJUSTMENT;
2383 if (!part.IsRoot)
2384 {
2385 m_pos *= part.RotationOffset;
2386 }
2133 m_bodyRot = sitTargetOrient; 2387 m_bodyRot = sitTargetOrient;
2134 //Rotation = sitTargetOrient;
2135 m_parentPosition = part.AbsolutePosition; 2388 m_parentPosition = part.AbsolutePosition;
2136 2389 part.IsOccupied = true;
2137 //SendTerseUpdateToAllClients(); 2390 part.ParentGroup.AddAvatar(agentID);
2138 } 2391 }
2139 else 2392 else
2140 { 2393 {
2141 m_pos -= part.AbsolutePosition; 2394 // if m_avUnscriptedSitPos is zero then Av sits above center
2395 // Else Av sits at m_avUnscriptedSitPos
2396
2397 // Non-scripted sit by Kitto Flora 21Nov09
2398 // Calculate angle of line from prim to Av
2399 Quaternion partIRot;
2400// if (part.LinkNum == 1)
2401// { // Root prim of linkset
2402// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2403// }
2404// else
2405// { // single or child prim
2406 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2407// }
2408 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2409 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2410 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2411 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2412 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2413 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2414 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2415 // Av sits at world euler <0,0, z>, translated by part rotation
2416 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2417
2142 m_parentPosition = part.AbsolutePosition; 2418 m_parentPosition = part.AbsolutePosition;
2143 } 2419 part.IsOccupied = true;
2420 part.ParentGroup.AddAvatar(agentID);
2421 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2422 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2423 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2424 m_avUnscriptedSitPos; // adds click offset, if any
2425 //Set up raytrace to find top surface of prim
2426 Vector3 size = part.Scale;
2427 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2428 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2429 Vector3 down = new Vector3(0f, 0f, -1f);
2430//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2431 m_scene.PhysicsScene.RaycastWorld(
2432 start, // Vector3 position,
2433 down, // Vector3 direction,
2434 mag, // float length,
2435 SitAltitudeCallback); // retMethod
2436 } // end scripted/not
2144 } 2437 }
2145 else 2438 else // no Av
2146 { 2439 {
2147 return; 2440 return;
2148 } 2441 }
2149 } 2442 }
2150 m_parentID = m_requestedSitTargetID;
2151 2443
2444 //We want our offsets to reference the root prim, not the child we may have sat on
2445 if (!part.IsRoot)
2446 {
2447 m_parentID = part.ParentGroup.RootPart.LocalId;
2448 m_pos += part.OffsetPosition;
2449 }
2450 else
2451 {
2452 m_parentID = m_requestedSitTargetID;
2453 }
2454
2455 m_linkedPrim = part.UUID;
2456 if (part.GetAvatarOnSitTarget() != UUID)
2457 {
2458 m_offsetRotation = m_offsetRotation / part.RotationOffset;
2459 }
2152 Velocity = Vector3.Zero; 2460 Velocity = Vector3.Zero;
2153 RemoveFromPhysicalScene(); 2461 RemoveFromPhysicalScene();
2154
2155 Animator.TrySetMovementAnimation(sitAnimation); 2462 Animator.TrySetMovementAnimation(sitAnimation);
2156 SendFullUpdateToAllClients(); 2463 SendFullUpdateToAllClients();
2157 // This may seem stupid, but Our Full updates don't send avatar rotation :P 2464 SendTerseUpdateToAllClients();
2158 // So we're also sending a terse update (which has avatar rotation)
2159 // [Update] We do now.
2160 //SendTerseUpdateToAllClients();
2161 } 2465 }
2466
2467 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2468 {
2469 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2470 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2471 if(hitYN)
2472 {
2473 // m_pos = Av offset from prim center to make look like on center
2474 // m_parentPosition = Actual center pos of prim
2475 // collisionPoint = spot on prim where we want to sit
2476 // collisionPoint.Z = global sit surface height
2477 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2478 Quaternion partIRot;
2479// if (part.LinkNum == 1)
2480/// { // Root prim of linkset
2481// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2482// }
2483// else
2484// { // single or child prim
2485 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2486// }
2487 if (m_initialSitTarget != null)
2488 {
2489 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2490 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2491 //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2492 m_pos += offset;
2493 // ControllingClient.SendClearFollowCamProperties(part.UUID);
2494 }
2495
2496 }
2497 } // End SitAltitudeCallback KF.
2162 2498
2163 /// <summary> 2499 /// <summary>
2164 /// Event handler for the 'Always run' setting on the client 2500 /// Event handler for the 'Always run' setting on the client
@@ -2188,7 +2524,7 @@ namespace OpenSim.Region.Framework.Scenes
2188 /// </summary> 2524 /// </summary>
2189 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2525 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2190 /// <param name="rotation">The direction in which this avatar should now face. 2526 /// <param name="rotation">The direction in which this avatar should now face.
2191 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2527 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2192 { 2528 {
2193 if (m_isChildAgent) 2529 if (m_isChildAgent)
2194 { 2530 {
@@ -2229,15 +2565,18 @@ namespace OpenSim.Region.Framework.Scenes
2229 Rotation = rotation; 2565 Rotation = rotation;
2230 Vector3 direc = vec * rotation; 2566 Vector3 direc = vec * rotation;
2231 direc.Normalize(); 2567 direc.Normalize();
2568 PhysicsActor actor = m_physicsActor;
2569 if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up.
2232 2570
2233 direc *= 0.03f * 128f * m_speedModifier; 2571 direc *= 0.03f * 128f * m_speedModifier;
2234 2572
2235 PhysicsActor actor = m_physicsActor;
2236 if (actor != null) 2573 if (actor != null)
2237 { 2574 {
2238 if (actor.Flying) 2575// rm falling if (actor.Flying)
2576 if ((actor.Flying) || Animator.m_falling) // add for falling lateral speed
2239 { 2577 {
2240 direc *= 4.0f; 2578// rm speed mod direc *= 4.0f;
2579 direc *= 5.2f; // for speed mod
2241 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 2580 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
2242 //bool colliding = (m_physicsActor.IsColliding==true); 2581 //bool colliding = (m_physicsActor.IsColliding==true);
2243 //if (controlland) 2582 //if (controlland)
@@ -2250,22 +2589,30 @@ namespace OpenSim.Region.Framework.Scenes
2250 // m_log.Info("[AGENT]: Stop FLying"); 2589 // m_log.Info("[AGENT]: Stop FLying");
2251 //} 2590 //}
2252 } 2591 }
2592 /* This jumping section removed to SPA
2253 else if (!actor.Flying && actor.IsColliding) 2593 else if (!actor.Flying && actor.IsColliding)
2254 { 2594 {
2255 if (direc.Z > 2.0f) 2595 if (direc.Z > 2.0f)
2256 { 2596 {
2257 direc.Z *= 3.0f; 2597 if(m_animator.m_animTickJump == -1)
2258 2598 {
2259 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2599 direc.Z *= 3.0f; // jump
2260 Animator.TrySetMovementAnimation("PREJUMP"); 2600 }
2261 Animator.TrySetMovementAnimation("JUMP"); 2601 else
2602 {
2603 direc.Z *= 0.1f; // prejump
2604 }
2605 / * Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs
2606 Animator.TrySetMovementAnimation("PREJUMP");
2607 Animator.TrySetMovementAnimation("JUMP");
2608 * /
2262 } 2609 }
2263 } 2610 } */
2264 } 2611 }
2265 2612
2266 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2613 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2267 m_forceToApply = direc; 2614 m_forceToApply = direc;
2268 2615 m_isNudging = Nudging;
2269 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2616 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2270 } 2617 }
2271 2618
@@ -2280,7 +2627,7 @@ namespace OpenSim.Region.Framework.Scenes
2280 const float POSITION_TOLERANCE = 0.05f; 2627 const float POSITION_TOLERANCE = 0.05f;
2281 //const int TIME_MS_TOLERANCE = 3000; 2628 //const int TIME_MS_TOLERANCE = 3000;
2282 2629
2283 SendPrimUpdates(); 2630
2284 2631
2285 if (m_isChildAgent == false) 2632 if (m_isChildAgent == false)
2286 { 2633 {
@@ -2310,6 +2657,9 @@ namespace OpenSim.Region.Framework.Scenes
2310 CheckForBorderCrossing(); 2657 CheckForBorderCrossing();
2311 CheckForSignificantMovement(); // sends update to the modules. 2658 CheckForSignificantMovement(); // sends update to the modules.
2312 } 2659 }
2660
2661 //Sending prim updates AFTER the avatar terse updates are sent
2662 SendPrimUpdates();
2313 } 2663 }
2314 2664
2315 #endregion 2665 #endregion
@@ -2513,66 +2863,69 @@ namespace OpenSim.Region.Framework.Scenes
2513 /// <param name="visualParam"></param> 2863 /// <param name="visualParam"></param>
2514 public void SetAppearance(Primitive.TextureEntry textureEntry, byte[] visualParams) 2864 public void SetAppearance(Primitive.TextureEntry textureEntry, byte[] visualParams)
2515 { 2865 {
2516 if (m_physicsActor != null) 2866 lock (m_syncRoot)
2517 { 2867 {
2518 if (!IsChildAgent) 2868 if (m_physicsActor != null)
2519 { 2869 {
2520 // This may seem like it's redundant, remove the avatar from the physics scene 2870 if (!IsChildAgent)
2521 // just to add it back again, but it saves us from having to update 2871 {
2522 // 3 variables 10 times a second. 2872 // This may seem like it's redundant, remove the avatar from the physics scene
2523 bool flyingTemp = m_physicsActor.Flying; 2873 // just to add it back again, but it saves us from having to update
2524 RemoveFromPhysicalScene(); 2874 // 3 variables 10 times a second.
2525 //m_scene.PhysicsScene.RemoveAvatar(m_physicsActor); 2875 bool flyingTemp = m_physicsActor.Flying;
2876 RemoveFromPhysicalScene();
2877 //m_scene.PhysicsScene.RemoveAvatar(m_physicsActor);
2526 2878
2527 //PhysicsActor = null; 2879 //PhysicsActor = null;
2528 2880
2529 AddToPhysicalScene(flyingTemp); 2881 AddToPhysicalScene(flyingTemp);
2882 }
2530 } 2883 }
2531 }
2532 2884
2533 #region Bake Cache Check 2885 #region Bake Cache Check
2534 2886
2535 if (textureEntry != null) 2887 if (textureEntry != null)
2536 {
2537 for (int i = 0; i < BAKE_INDICES.Length; i++)
2538 { 2888 {
2539 int j = BAKE_INDICES[i]; 2889 for (int i = 0; i < BAKE_INDICES.Length; i++)
2540 Primitive.TextureEntryFace face = textureEntry.FaceTextures[j];
2541
2542 if (face != null && face.TextureID != AppearanceManager.DEFAULT_AVATAR_TEXTURE)
2543 { 2890 {
2544 if (m_scene.AssetService.Get(face.TextureID.ToString()) == null) 2891 int j = BAKE_INDICES[i];
2892 Primitive.TextureEntryFace face = textureEntry.FaceTextures[j];
2893
2894 if (face != null && face.TextureID != AppearanceManager.DEFAULT_AVATAR_TEXTURE)
2545 { 2895 {
2546 m_log.Warn("[APPEARANCE]: Missing baked texture " + face.TextureID + " (" + j + ") for avatar " + this.Name); 2896 if (m_scene.AssetService.Get(face.TextureID.ToString()) == null)
2547 this.ControllingClient.SendRebakeAvatarTextures(face.TextureID); 2897 {
2898 m_log.Warn("[APPEARANCE]: Missing baked texture " + face.TextureID + " (" + j + ") for avatar " + this.Name);
2899 this.ControllingClient.SendRebakeAvatarTextures(face.TextureID);
2900 }
2548 } 2901 }
2549 } 2902 }
2550 }
2551 2903
2552 } 2904 }
2553 2905
2554 2906
2555 #endregion Bake Cache Check 2907 #endregion Bake Cache Check
2556 2908
2557 m_appearance.SetAppearance(textureEntry, visualParams); 2909 m_appearance.SetAppearance(textureEntry, visualParams);
2558 if (m_appearance.AvatarHeight > 0) 2910 if (m_appearance.AvatarHeight > 0)
2559 SetHeight(m_appearance.AvatarHeight); 2911 SetHeight(m_appearance.AvatarHeight);
2560 2912
2561 // This is not needed, because only the transient data changed 2913 // This is not needed, because only the transient data changed
2562 //AvatarData adata = new AvatarData(m_appearance); 2914 //AvatarData adata = new AvatarData(m_appearance);
2563 //m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata); 2915 //m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata);
2564 2916
2565 SendAppearanceToAllOtherAgents(); 2917 SendAppearanceToAllOtherAgents();
2566 if (!m_startAnimationSet) 2918 if (!m_startAnimationSet)
2567 { 2919 {
2568 Animator.UpdateMovementAnimations(); 2920 Animator.UpdateMovementAnimations();
2569 m_startAnimationSet = true; 2921 m_startAnimationSet = true;
2570 } 2922 }
2571 2923
2572 Vector3 pos = m_pos; 2924 Vector3 pos = m_pos;
2573 pos.Z += m_appearance.HipOffset; 2925 pos.Z += m_appearance.HipOffset;
2574 2926
2575 m_controllingClient.SendAvatarDataImmediate(this); 2927 m_controllingClient.SendAvatarDataImmediate(this);
2928 }
2576 } 2929 }
2577 2930
2578 public void SetWearable(int wearableId, AvatarWearable wearable) 2931 public void SetWearable(int wearableId, AvatarWearable wearable)
@@ -3095,6 +3448,7 @@ namespace OpenSim.Region.Framework.Scenes
3095 m_callbackURI = cAgent.CallbackURI; 3448 m_callbackURI = cAgent.CallbackURI;
3096 3449
3097 m_pos = cAgent.Position; 3450 m_pos = cAgent.Position;
3451
3098 m_velocity = cAgent.Velocity; 3452 m_velocity = cAgent.Velocity;
3099 m_CameraCenter = cAgent.Center; 3453 m_CameraCenter = cAgent.Center;
3100 //m_avHeight = cAgent.Size.Z; 3454 //m_avHeight = cAgent.Size.Z;
@@ -3203,17 +3557,46 @@ namespace OpenSim.Region.Framework.Scenes
3203 /// </summary> 3557 /// </summary>
3204 public override void UpdateMovement() 3558 public override void UpdateMovement()
3205 { 3559 {
3206 if (m_forceToApply.HasValue) 3560 if (Animator!=null) // add for jumping
3207 { 3561 { // add for jumping
3208 Vector3 force = m_forceToApply.Value; 3562 // if (!m_animator.m_jumping) // add for jumping
3563 // { // add for jumping
3209 3564
3210 m_updateflag = true; 3565 if (m_forceToApply.HasValue) // this section realigned
3211// movementvector = force; 3566 {
3212 Velocity = force;
3213 3567
3214 m_forceToApply = null; 3568 Vector3 force = m_forceToApply.Value;
3215 } 3569 m_updateflag = true;
3216 } 3570if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3571 Velocity = force;
3572//Console.WriteLine("UM1 {0}", Velocity);
3573 m_forceToApply = null;
3574 }
3575 else
3576 {
3577 if (m_isNudging)
3578 {
3579 Vector3 force = Vector3.Zero;
3580
3581 m_updateflag = true;
3582if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3583 Velocity = force;
3584//Console.WriteLine("UM2 {0}", Velocity);
3585 m_isNudging = false;
3586 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3587 }
3588 else // add for jumping
3589 { // add for jumping
3590 Vector3 force = Vector3.Zero; // add for jumping
3591if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3592//Console.WriteLine("UM3 {0}", Velocity);
3593 Velocity = force; // add for jumping
3594 }
3595
3596 }
3597 // } // end realign
3598 } // add for jumping
3599 } // add for jumping
3217 3600
3218 /// <summary> 3601 /// <summary>
3219 /// Adds a physical representation of the avatar to the Physics plugin 3602 /// Adds a physical representation of the avatar to the Physics plugin
@@ -3258,18 +3641,29 @@ namespace OpenSim.Region.Framework.Scenes
3258 { 3641 {
3259 if (e == null) 3642 if (e == null)
3260 return; 3643 return;
3261 3644
3262 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3645 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3263 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3264 // as of this comment the interval is set in AddToPhysicalScene 3646 // as of this comment the interval is set in AddToPhysicalScene
3265 if (Animator!=null) 3647 if (Animator!=null)
3266 Animator.UpdateMovementAnimations(); 3648 {
3649 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3650 { // else its will lock out other animation changes, like ground sit.
3651 Animator.UpdateMovementAnimations();
3652 m_updateCount--;
3653 }
3654 }
3267 3655
3268 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3656 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3269 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3657 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3270 3658
3271 CollisionPlane = Vector4.UnitW; 3659 CollisionPlane = Vector4.UnitW;
3272 3660
3661 if (m_lastColCount != coldata.Count)
3662 {
3663 m_updateCount = UPDATE_COUNT;
3664 m_lastColCount = coldata.Count;
3665 }
3666
3273 if (coldata.Count != 0 && Animator != null) 3667 if (coldata.Count != 0 && Animator != null)
3274 { 3668 {
3275 switch (Animator.CurrentMovementAnimation) 3669 switch (Animator.CurrentMovementAnimation)
@@ -3299,6 +3693,148 @@ namespace OpenSim.Region.Framework.Scenes
3299 } 3693 }
3300 } 3694 }
3301 3695
3696 List<uint> thisHitColliders = new List<uint>();
3697 List<uint> endedColliders = new List<uint>();
3698 List<uint> startedColliders = new List<uint>();
3699
3700 foreach (uint localid in coldata.Keys)
3701 {
3702 thisHitColliders.Add(localid);
3703 if (!m_lastColliders.Contains(localid))
3704 {
3705 startedColliders.Add(localid);
3706 }
3707 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
3708 }
3709
3710 // calculate things that ended colliding
3711 foreach (uint localID in m_lastColliders)
3712 {
3713 if (!thisHitColliders.Contains(localID))
3714 {
3715 endedColliders.Add(localID);
3716 }
3717 }
3718 //add the items that started colliding this time to the last colliders list.
3719 foreach (uint localID in startedColliders)
3720 {
3721 m_lastColliders.Add(localID);
3722 }
3723 // remove things that ended colliding from the last colliders list
3724 foreach (uint localID in endedColliders)
3725 {
3726 m_lastColliders.Remove(localID);
3727 }
3728
3729 // do event notification
3730 if (startedColliders.Count > 0)
3731 {
3732 ColliderArgs StartCollidingMessage = new ColliderArgs();
3733 List<DetectedObject> colliding = new List<DetectedObject>();
3734 foreach (uint localId in startedColliders)
3735 {
3736 if (localId == 0)
3737 continue;
3738
3739 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3740 string data = "";
3741 if (obj != null)
3742 {
3743 DetectedObject detobj = new DetectedObject();
3744 detobj.keyUUID = obj.UUID;
3745 detobj.nameStr = obj.Name;
3746 detobj.ownerUUID = obj.OwnerID;
3747 detobj.posVector = obj.AbsolutePosition;
3748 detobj.rotQuat = obj.GetWorldRotation();
3749 detobj.velVector = obj.Velocity;
3750 detobj.colliderType = 0;
3751 detobj.groupUUID = obj.GroupID;
3752 colliding.Add(detobj);
3753 }
3754 }
3755
3756 if (colliding.Count > 0)
3757 {
3758 StartCollidingMessage.Colliders = colliding;
3759
3760 foreach (SceneObjectGroup att in Attachments)
3761 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
3762 }
3763 }
3764
3765 if (endedColliders.Count > 0)
3766 {
3767 ColliderArgs EndCollidingMessage = new ColliderArgs();
3768 List<DetectedObject> colliding = new List<DetectedObject>();
3769 foreach (uint localId in endedColliders)
3770 {
3771 if (localId == 0)
3772 continue;
3773
3774 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3775 string data = "";
3776 if (obj != null)
3777 {
3778 DetectedObject detobj = new DetectedObject();
3779 detobj.keyUUID = obj.UUID;
3780 detobj.nameStr = obj.Name;
3781 detobj.ownerUUID = obj.OwnerID;
3782 detobj.posVector = obj.AbsolutePosition;
3783 detobj.rotQuat = obj.GetWorldRotation();
3784 detobj.velVector = obj.Velocity;
3785 detobj.colliderType = 0;
3786 detobj.groupUUID = obj.GroupID;
3787 colliding.Add(detobj);
3788 }
3789 }
3790
3791 if (colliding.Count > 0)
3792 {
3793 EndCollidingMessage.Colliders = colliding;
3794
3795 foreach (SceneObjectGroup att in Attachments)
3796 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
3797 }
3798 }
3799
3800 if (thisHitColliders.Count > 0)
3801 {
3802 ColliderArgs CollidingMessage = new ColliderArgs();
3803 List<DetectedObject> colliding = new List<DetectedObject>();
3804 foreach (uint localId in thisHitColliders)
3805 {
3806 if (localId == 0)
3807 continue;
3808
3809 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3810 string data = "";
3811 if (obj != null)
3812 {
3813 DetectedObject detobj = new DetectedObject();
3814 detobj.keyUUID = obj.UUID;
3815 detobj.nameStr = obj.Name;
3816 detobj.ownerUUID = obj.OwnerID;
3817 detobj.posVector = obj.AbsolutePosition;
3818 detobj.rotQuat = obj.GetWorldRotation();
3819 detobj.velVector = obj.Velocity;
3820 detobj.colliderType = 0;
3821 detobj.groupUUID = obj.GroupID;
3822 colliding.Add(detobj);
3823 }
3824 }
3825
3826 if (colliding.Count > 0)
3827 {
3828 CollidingMessage.Colliders = colliding;
3829
3830 lock (m_attachments)
3831 {
3832 foreach (SceneObjectGroup att in m_attachments)
3833 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
3834 }
3835 }
3836 }
3837
3302 if (m_invulnerable) 3838 if (m_invulnerable)
3303 return; 3839 return;
3304 3840
@@ -3494,7 +4030,10 @@ namespace OpenSim.Region.Framework.Scenes
3494 m_scene = scene; 4030 m_scene = scene;
3495 4031
3496 RegisterToEvents(); 4032 RegisterToEvents();
3497 4033 if (m_controllingClient != null)
4034 {
4035 m_controllingClient.ProcessPendingPackets();
4036 }
3498 /* 4037 /*
3499 AbsolutePosition = client.StartPos; 4038 AbsolutePosition = client.StartPos;
3500 4039
@@ -3724,6 +4263,39 @@ namespace OpenSim.Region.Framework.Scenes
3724 return; 4263 return;
3725 } 4264 }
3726 4265
4266 XmlDocument doc = new XmlDocument();
4267 string stateData = String.Empty;
4268
4269 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
4270 if (attServ != null)
4271 {
4272 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
4273 stateData = attServ.Get(ControllingClient.AgentId.ToString());
4274 if (stateData != String.Empty)
4275 {
4276 try
4277 {
4278 doc.LoadXml(stateData);
4279 }
4280 catch { }
4281 }
4282 }
4283
4284 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
4285
4286 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
4287 if (nodes.Count > 0)
4288 {
4289 foreach (XmlNode n in nodes)
4290 {
4291 XmlElement elem = (XmlElement)n;
4292 string itemID = elem.GetAttribute("ItemID");
4293 string xml = elem.InnerXml;
4294
4295 itemData[new UUID(itemID)] = xml;
4296 }
4297 }
4298
3727 List<int> attPoints = m_appearance.GetAttachedPoints(); 4299 List<int> attPoints = m_appearance.GetAttachedPoints();
3728 foreach (int p in attPoints) 4300 foreach (int p in attPoints)
3729 { 4301 {
@@ -3743,7 +4315,30 @@ namespace OpenSim.Region.Framework.Scenes
3743 4315
3744 try 4316 try
3745 { 4317 {
3746 m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p); 4318 string xmlData;
4319 XmlDocument d = new XmlDocument();
4320 UUID asset;
4321 if (itemData.TryGetValue(itemID, out xmlData))
4322 {
4323 d.LoadXml(xmlData);
4324 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID);
4325
4326 // Rez from inventory
4327 asset
4328 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d);
4329
4330 }
4331 else
4332 {
4333 // Rez from inventory (with a null doc to let
4334 // CHANGED_OWNER happen)
4335 asset
4336 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, null);
4337 }
4338
4339 m_log.InfoFormat(
4340 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2}",
4341 p, itemID, asset);
3747 } 4342 }
3748 catch (Exception e) 4343 catch (Exception e)
3749 { 4344 {
@@ -3776,5 +4371,16 @@ namespace OpenSim.Region.Framework.Scenes
3776 m_reprioritization_called = false; 4371 m_reprioritization_called = false;
3777 } 4372 }
3778 } 4373 }
4374
4375 private Vector3 Quat2Euler(Quaternion rot){
4376 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4377 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4378 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4379 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4380 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4381 return(new Vector3(x,y,z));
4382 }
4383
4384
3779 } 4385 }
3780} 4386}