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.cs1027
1 files changed, 835 insertions, 192 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 51b8dcc..fd03e93 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Xml;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.Reflection; 31using System.Reflection;
31using System.Timers; 32using System.Timers;
@@ -72,7 +73,7 @@ namespace OpenSim.Region.Framework.Scenes
72// { 73// {
73// m_log.Debug("[ScenePresence] Destructor called"); 74// m_log.Debug("[ScenePresence] Destructor called");
74// } 75// }
75 76
76 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
77 78
78// private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes(); 79// private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes();
@@ -87,7 +88,9 @@ namespace OpenSim.Region.Framework.Scenes
87 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 88 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
88 /// issue #1716 89 /// issue #1716
89 /// </summary> 90 /// </summary>
90 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 91// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
92 // Value revised by KF 091121 by comparison with SL.
93 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f);
91 94
92 public UUID currentParcelUUID = UUID.Zero; 95 public UUID currentParcelUUID = UUID.Zero;
93 96
@@ -110,6 +113,7 @@ namespace OpenSim.Region.Framework.Scenes
110 { 113 {
111 get { return m_attachments; } 114 get { return m_attachments; }
112 } 115 }
116
113 protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>(); 117 protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>();
114 118
115 private Dictionary<UUID, ScriptControllers> scriptedcontrols = new Dictionary<UUID, ScriptControllers>(); 119 private Dictionary<UUID, ScriptControllers> scriptedcontrols = new Dictionary<UUID, ScriptControllers>();
@@ -119,10 +123,12 @@ namespace OpenSim.Region.Framework.Scenes
119 private SceneObjectGroup proxyObjectGroup; 123 private SceneObjectGroup proxyObjectGroup;
120 //private SceneObjectPart proxyObjectPart = null; 124 //private SceneObjectPart proxyObjectPart = null;
121 public Vector3 lastKnownAllowedPosition; 125 public Vector3 lastKnownAllowedPosition;
122 public bool sentMessageAboutRestrictedParcelFlyingDown;
123 public Vector4 CollisionPlane = Vector4.UnitW; 126 public Vector4 CollisionPlane = Vector4.UnitW;
124 127
128 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
129 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
125 private Vector3 m_lastPosition; 130 private Vector3 m_lastPosition;
131 private Vector3 m_lastWorldPosition;
126 private Quaternion m_lastRotation; 132 private Quaternion m_lastRotation;
127 private Vector3 m_lastVelocity; 133 private Vector3 m_lastVelocity;
128 //private int m_lastTerseSent; 134 //private int m_lastTerseSent;
@@ -130,6 +136,11 @@ namespace OpenSim.Region.Framework.Scenes
130 private bool m_updateflag; 136 private bool m_updateflag;
131 private byte m_movementflag; 137 private byte m_movementflag;
132 private Vector3? m_forceToApply; 138 private Vector3? m_forceToApply;
139 private int m_userFlags;
140 public int UserFlags
141 {
142 get { return m_userFlags; }
143 }
133 private TeleportFlags m_teleportFlags; 144 private TeleportFlags m_teleportFlags;
134 public TeleportFlags TeleportFlags 145 public TeleportFlags TeleportFlags
135 { 146 {
@@ -160,9 +171,10 @@ namespace OpenSim.Region.Framework.Scenes
160 private int m_perfMonMS; 171 private int m_perfMonMS;
161 172
162 private bool m_setAlwaysRun; 173 private bool m_setAlwaysRun;
163
164 private bool m_forceFly; 174 private bool m_forceFly;
165 private bool m_flyDisabled; 175 private bool m_flyDisabled;
176 private bool m_flyingOld; // add for fly velocity control
177 public bool m_wasFlying; // add for fly velocity control
166 178
167 private float m_speedModifier = 1.0f; 179 private float m_speedModifier = 1.0f;
168 180
@@ -181,7 +193,8 @@ namespace OpenSim.Region.Framework.Scenes
181 protected RegionInfo m_regionInfo; 193 protected RegionInfo m_regionInfo;
182 protected ulong crossingFromRegion; 194 protected ulong crossingFromRegion;
183 195
184 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 196 private readonly Vector3[] Dir_Vectors = new Vector3[11];
197 private bool m_isNudging = false;
185 198
186 // Position of agent's camera in world (region cordinates) 199 // Position of agent's camera in world (region cordinates)
187 protected Vector3 m_CameraCenter; 200 protected Vector3 m_CameraCenter;
@@ -206,17 +219,25 @@ namespace OpenSim.Region.Framework.Scenes
206 private bool m_autopilotMoving; 219 private bool m_autopilotMoving;
207 private Vector3 m_autoPilotTarget; 220 private Vector3 m_autoPilotTarget;
208 private bool m_sitAtAutoTarget; 221 private bool m_sitAtAutoTarget;
222 private Vector3 m_initialSitTarget = Vector3.Zero; //KF: First estimate of where to sit
209 223
210 private string m_nextSitAnimation = String.Empty; 224 private string m_nextSitAnimation = String.Empty;
211 225
212 //PauPaw:Proper PID Controler for autopilot************ 226 //PauPaw:Proper PID Controler for autopilot************
213 private bool m_moveToPositionInProgress; 227 private bool m_moveToPositionInProgress;
214 private Vector3 m_moveToPositionTarget; 228 private Vector3 m_moveToPositionTarget;
229 private Quaternion m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
215 230
216 private bool m_followCamAuto; 231 private bool m_followCamAuto;
217 232
218 private int m_movementUpdateCount; 233 private int m_movementUpdateCount;
234 private int m_lastColCount = -1; //KF: Look for Collision chnages
235 private int m_updateCount = 0; //KF: Update Anims for a while
236 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
219 private const int NumMovementsBetweenRayCast = 5; 237 private const int NumMovementsBetweenRayCast = 5;
238 private List<uint> m_lastColliders = new List<uint>();
239
240 private object m_syncRoot = new Object();
220 241
221 private bool CameraConstraintActive; 242 private bool CameraConstraintActive;
222 //private int m_moveToPositionStateStatus; 243 //private int m_moveToPositionStateStatus;
@@ -243,7 +264,9 @@ namespace OpenSim.Region.Framework.Scenes
243 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 264 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
244 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 265 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
245 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 266 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
246 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 267 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
268 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
269 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
247 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 270 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
248 } 271 }
249 272
@@ -450,7 +473,8 @@ namespace OpenSim.Region.Framework.Scenes
450 get 473 get
451 { 474 {
452 PhysicsActor actor = m_physicsActor; 475 PhysicsActor actor = m_physicsActor;
453 if (actor != null) 476// if (actor != null)
477 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting!
454 m_pos = actor.Position; 478 m_pos = actor.Position;
455 else 479 else
456 { 480 {
@@ -472,7 +496,7 @@ namespace OpenSim.Region.Framework.Scenes
472 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); 496 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
473 if (part != null) 497 if (part != null)
474 { 498 {
475 return m_parentPosition + (m_pos * part.GetWorldRotation()); 499 return part.AbsolutePosition + (m_pos * part.GetWorldRotation());
476 } 500 }
477 else 501 else
478 { 502 {
@@ -499,7 +523,8 @@ namespace OpenSim.Region.Framework.Scenes
499 } 523 }
500 } 524 }
501 525
502 m_pos = value; 526 if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting!
527 m_pos = value;
503 m_parentPosition = Vector3.Zero; 528 m_parentPosition = Vector3.Zero;
504 } 529 }
505 } 530 }
@@ -543,10 +568,39 @@ namespace OpenSim.Region.Framework.Scenes
543 } 568 }
544 } 569 }
545 570
571 public Quaternion OffsetRotation
572 {
573 get { return m_offsetRotation; }
574 set { m_offsetRotation = value; }
575 }
576
546 public Quaternion Rotation 577 public Quaternion Rotation
547 { 578 {
548 get { return m_bodyRot; } 579 get {
549 set { m_bodyRot = value; } 580 if (m_parentID != 0)
581 {
582 if (m_offsetRotation != null)
583 {
584 return m_offsetRotation;
585 }
586 else
587 {
588 return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
589 }
590
591 }
592 else
593 {
594 return m_bodyRot;
595 }
596 }
597 set {
598 m_bodyRot = value;
599 if (m_parentID != 0)
600 {
601 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
602 }
603 }
550 } 604 }
551 605
552 public Quaternion PreviousRotation 606 public Quaternion PreviousRotation
@@ -571,11 +625,21 @@ namespace OpenSim.Region.Framework.Scenes
571 625
572 private uint m_parentID; 626 private uint m_parentID;
573 627
628
629 private UUID m_linkedPrim;
630
574 public uint ParentID 631 public uint ParentID
575 { 632 {
576 get { return m_parentID; } 633 get { return m_parentID; }
577 set { m_parentID = value; } 634 set { m_parentID = value; }
578 } 635 }
636
637 public UUID LinkedPrim
638 {
639 get { return m_linkedPrim; }
640 set { m_linkedPrim = value; }
641 }
642
579 public float Health 643 public float Health
580 { 644 {
581 get { return m_health; } 645 get { return m_health; }
@@ -697,7 +761,7 @@ namespace OpenSim.Region.Framework.Scenes
697 CreateSceneViewer(); 761 CreateSceneViewer();
698 m_animator = new ScenePresenceAnimator(this); 762 m_animator = new ScenePresenceAnimator(this);
699 } 763 }
700 764
701 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() 765 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this()
702 { 766 {
703 m_rootRegionHandle = reginfo.RegionHandle; 767 m_rootRegionHandle = reginfo.RegionHandle;
@@ -711,6 +775,7 @@ namespace OpenSim.Region.Framework.Scenes
711 m_localId = m_scene.AllocateLocalId(); 775 m_localId = m_scene.AllocateLocalId();
712 776
713 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid); 777 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid);
778 m_userFlags = account.UserFlags;
714 779
715 if (account != null) 780 if (account != null)
716 m_userLevel = account.UserLevel; 781 m_userLevel = account.UserLevel;
@@ -729,10 +794,7 @@ namespace OpenSim.Region.Framework.Scenes
729 m_reprioritization_timer.AutoReset = false; 794 m_reprioritization_timer.AutoReset = false;
730 795
731 AdjustKnownSeeds(); 796 AdjustKnownSeeds();
732
733 // TODO: I think, this won't send anything, as we are still a child here...
734 Animator.TrySetMovementAnimation("STAND"); 797 Animator.TrySetMovementAnimation("STAND");
735
736 // we created a new ScenePresence (a new child agent) in a fresh region. 798 // we created a new ScenePresence (a new child agent) in a fresh region.
737 // Request info about all the (root) agents in this region 799 // Request info about all the (root) agents in this region
738 // Note: This won't send data *to* other clients in that region (children don't send) 800 // Note: This won't send data *to* other clients in that region (children don't send)
@@ -783,25 +845,47 @@ namespace OpenSim.Region.Framework.Scenes
783 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 845 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
784 Dir_Vectors[4] = Vector3.UnitZ; //UP 846 Dir_Vectors[4] = Vector3.UnitZ; //UP
785 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 847 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
786 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 848 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
787 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 849 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
788 Dir_Vectors[7] = -Vector3.UnitX; //BACK 850 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
851 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
852 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
789 } 853 }
790 854
791 private Vector3[] GetWalkDirectionVectors() 855 private Vector3[] GetWalkDirectionVectors()
792 { 856 {
793 Vector3[] vector = new Vector3[9]; 857 Vector3[] vector = new Vector3[11];
794 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 858 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
795 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 859 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
796 vector[2] = Vector3.UnitY; //LEFT 860 vector[2] = Vector3.UnitY; //LEFT
797 vector[3] = -Vector3.UnitY; //RIGHT 861 vector[3] = -Vector3.UnitY; //RIGHT
798 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 862 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
799 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 863 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
800 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 864 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
801 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 865 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
802 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 866 vector[8] = Vector3.UnitY; //LEFT_NUDGE
867 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
868 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
803 return vector; 869 return vector;
804 } 870 }
871
872 private bool[] GetDirectionIsNudge()
873 {
874 bool[] isNudge = new bool[11];
875 isNudge[0] = false; //FORWARD
876 isNudge[1] = false; //BACK
877 isNudge[2] = false; //LEFT
878 isNudge[3] = false; //RIGHT
879 isNudge[4] = false; //UP
880 isNudge[5] = false; //DOWN
881 isNudge[6] = true; //FORWARD_NUDGE
882 isNudge[7] = true; //BACK_NUDGE
883 isNudge[8] = true; //LEFT_NUDGE
884 isNudge[9] = true; //RIGHT_NUDGE
885 isNudge[10] = true; //DOWN_Nudge
886 return isNudge;
887 }
888
805 889
806 #endregion 890 #endregion
807 891
@@ -863,6 +947,62 @@ namespace OpenSim.Region.Framework.Scenes
863 pos.Y = crossedBorder.BorderLine.Z - 1; 947 pos.Y = crossedBorder.BorderLine.Z - 1;
864 } 948 }
865 949
950 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
951 if (land != null)
952 {
953 // If we come in via login, landmark or map, we want to
954 // honor landing points. If we come in via Lure, we want
955 // to ignore them.
956 if ((m_teleportFlags & (TeleportFlags.ViaLogin | TeleportFlags.ViaRegionID)) == (TeleportFlags.ViaLogin | TeleportFlags.ViaRegionID) ||
957 (m_teleportFlags & TeleportFlags.ViaLandmark) != 0 ||
958 (m_teleportFlags & TeleportFlags.ViaLocation) != 0)
959 {
960 // Don't restrict gods, estate managers, or land owners to
961 // the TP point. This behaviour mimics agni.
962 if (land.LandData.LandingType == (byte)LandingType.LandingPoint &&
963 land.LandData.UserLocation != Vector3.Zero &&
964 GodLevel < 200 &&
965 ((land.LandData.OwnerID != m_uuid &&
966 (!m_scene.Permissions.IsGod(m_uuid)) &&
967 (!m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid))) || (m_teleportFlags & TeleportFlags.ViaLocation) != 0))
968 {
969 pos = land.LandData.UserLocation;
970 }
971 }
972
973 land.SendLandUpdateToClient(ControllingClient);
974 }
975
976 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0)
977 {
978 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128);
979
980 if (pos.X < 0)
981 {
982 emergencyPos.X = (int)Constants.RegionSize + pos.X;
983 if (!(pos.Y < 0))
984 emergencyPos.Y = pos.Y;
985 if (!(pos.Z < 0))
986 emergencyPos.Z = pos.Z;
987 }
988 if (pos.Y < 0)
989 {
990 emergencyPos.Y = (int)Constants.RegionSize + pos.Y;
991 if (!(pos.X < 0))
992 emergencyPos.X = pos.X;
993 if (!(pos.Z < 0))
994 emergencyPos.Z = pos.Z;
995 }
996 if (pos.Z < 0)
997 {
998 emergencyPos.Z = 128;
999 if (!(pos.Y < 0))
1000 emergencyPos.Y = pos.Y;
1001 if (!(pos.X < 0))
1002 emergencyPos.X = pos.X;
1003 }
1004 }
1005
866 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 1006 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
867 { 1007 {
868 m_log.WarnFormat( 1008 m_log.WarnFormat(
@@ -987,16 +1127,21 @@ namespace OpenSim.Region.Framework.Scenes
987 /// <summary> 1127 /// <summary>
988 /// Removes physics plugin scene representation of this agent if it exists. 1128 /// Removes physics plugin scene representation of this agent if it exists.
989 /// </summary> 1129 /// </summary>
990 private void RemoveFromPhysicalScene() 1130 public void RemoveFromPhysicalScene()
991 { 1131 {
992 if (PhysicsActor != null) 1132 if (PhysicsActor != null)
993 { 1133 {
994 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1134 try
995 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall; 1135 {
996 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); 1136 m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
997 m_physicsActor.UnSubscribeEvents(); 1137 m_physicsActor.OnOutOfBounds -= OutOfBoundsCall;
998 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1138 m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
999 PhysicsActor = null; 1139 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1140 m_physicsActor.UnSubscribeEvents();
1141 PhysicsActor = null;
1142 }
1143 catch
1144 { }
1000 } 1145 }
1001 } 1146 }
1002 1147
@@ -1007,11 +1152,13 @@ namespace OpenSim.Region.Framework.Scenes
1007 public void Teleport(Vector3 pos) 1152 public void Teleport(Vector3 pos)
1008 { 1153 {
1009 bool isFlying = false; 1154 bool isFlying = false;
1155
1010 if (m_physicsActor != null) 1156 if (m_physicsActor != null)
1011 isFlying = m_physicsActor.Flying; 1157 isFlying = m_physicsActor.Flying;
1012 1158
1013 RemoveFromPhysicalScene(); 1159 RemoveFromPhysicalScene();
1014 Velocity = Vector3.Zero; 1160 Velocity = Vector3.Zero;
1161 CheckLandingPoint(ref pos);
1015 AbsolutePosition = pos; 1162 AbsolutePosition = pos;
1016 AddToPhysicalScene(isFlying); 1163 AddToPhysicalScene(isFlying);
1017 if (m_appearance != null) 1164 if (m_appearance != null)
@@ -1021,6 +1168,7 @@ namespace OpenSim.Region.Framework.Scenes
1021 } 1168 }
1022 1169
1023 SendTerseUpdateToAllClients(); 1170 SendTerseUpdateToAllClients();
1171
1024 } 1172 }
1025 1173
1026 public void TeleportWithMomentum(Vector3 pos) 1174 public void TeleportWithMomentum(Vector3 pos)
@@ -1030,6 +1178,7 @@ namespace OpenSim.Region.Framework.Scenes
1030 isFlying = m_physicsActor.Flying; 1178 isFlying = m_physicsActor.Flying;
1031 1179
1032 RemoveFromPhysicalScene(); 1180 RemoveFromPhysicalScene();
1181 CheckLandingPoint(ref pos);
1033 AbsolutePosition = pos; 1182 AbsolutePosition = pos;
1034 AddToPhysicalScene(isFlying); 1183 AddToPhysicalScene(isFlying);
1035 if (m_appearance != null) 1184 if (m_appearance != null)
@@ -1241,6 +1390,7 @@ namespace OpenSim.Region.Framework.Scenes
1241 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); 1390 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902");
1242 1391
1243 m_pos = m_LastFinitePos; 1392 m_pos = m_LastFinitePos;
1393
1244 if (!m_pos.IsFinite()) 1394 if (!m_pos.IsFinite())
1245 { 1395 {
1246 m_pos.X = 127f; 1396 m_pos.X = 127f;
@@ -1307,7 +1457,6 @@ namespace OpenSim.Region.Framework.Scenes
1307 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1457 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1308 } 1458 }
1309 } 1459 }
1310
1311 lock (scriptedcontrols) 1460 lock (scriptedcontrols)
1312 { 1461 {
1313 if (scriptedcontrols.Count > 0) 1462 if (scriptedcontrols.Count > 0)
@@ -1322,6 +1471,9 @@ namespace OpenSim.Region.Framework.Scenes
1322 1471
1323 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1472 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1324 { 1473 {
1474 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1475 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1476
1325 // TODO: This doesn't prevent the user from walking yet. 1477 // TODO: This doesn't prevent the user from walking yet.
1326 // Setting parent ID would fix this, if we knew what value 1478 // Setting parent ID would fix this, if we knew what value
1327 // to use. Or we could add a m_isSitting variable. 1479 // to use. Or we could add a m_isSitting variable.
@@ -1370,12 +1522,20 @@ namespace OpenSim.Region.Framework.Scenes
1370 if (actor.Flying != oldflying) 1522 if (actor.Flying != oldflying)
1371 update_movementflag = true; 1523 update_movementflag = true;
1372 1524
1525 if (m_animator.m_jumping) // add for jumping
1526 update_movementflag = true;
1527
1373 if (q != m_bodyRot) 1528 if (q != m_bodyRot)
1374 { 1529 {
1375 m_bodyRot = q; 1530 m_bodyRot = q;
1376 update_rotation = true; 1531 update_rotation = true;
1377 } 1532 }
1378 1533
1534 //guilty until proven innocent..
1535 bool Nudging = true;
1536 //Basically, if there is at least one non-nudge control then we don't need
1537 //to worry about stopping the avatar
1538
1379 if (m_parentID == 0) 1539 if (m_parentID == 0)
1380 { 1540 {
1381 bool bAllowUpdateMoveToPosition = false; 1541 bool bAllowUpdateMoveToPosition = false;
@@ -1390,9 +1550,12 @@ namespace OpenSim.Region.Framework.Scenes
1390 else 1550 else
1391 dirVectors = Dir_Vectors; 1551 dirVectors = Dir_Vectors;
1392 1552
1393 // The fact that m_movementflag is a byte needs to be fixed 1553 bool[] isNudge = GetDirectionIsNudge();
1394 // it really should be a uint 1554
1395 uint nudgehack = 250; 1555
1556
1557
1558
1396 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1559 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1397 { 1560 {
1398 if (((uint)flags & (uint)DCF) != 0) 1561 if (((uint)flags & (uint)DCF) != 0)
@@ -1402,40 +1565,28 @@ namespace OpenSim.Region.Framework.Scenes
1402 try 1565 try
1403 { 1566 {
1404 agent_control_v3 += dirVectors[i]; 1567 agent_control_v3 += dirVectors[i];
1405 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1568 if (isNudge[i] == false)
1569 {
1570 Nudging = false;
1571 }
1406 } 1572 }
1407 catch (IndexOutOfRangeException) 1573 catch (IndexOutOfRangeException)
1408 { 1574 {
1409 // Why did I get this? 1575 // Why did I get this?
1410 } 1576 }
1411 1577
1412 if ((m_movementflag & (byte)(uint)DCF) == 0) 1578 if ((m_movementflag & (uint)DCF) == 0)
1413 { 1579 {
1414 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1415 {
1416 m_movementflag |= (byte)nudgehack;
1417 }
1418 m_movementflag += (byte)(uint)DCF; 1580 m_movementflag += (byte)(uint)DCF;
1419 update_movementflag = true; 1581 update_movementflag = true;
1420 } 1582 }
1421 } 1583 }
1422 else 1584 else
1423 { 1585 {
1424 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1586 if ((m_movementflag & (uint)DCF) != 0)
1425 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1426 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1427 ) // This or is for Nudge forward
1428 { 1587 {
1429 m_movementflag -= ((byte)(uint)DCF); 1588 m_movementflag -= (byte)(uint)DCF;
1430
1431 update_movementflag = true; 1589 update_movementflag = true;
1432 /*
1433 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1434 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1435 {
1436 m_log.Debug("Removed Hack flag");
1437 }
1438 */
1439 } 1590 }
1440 else 1591 else
1441 { 1592 {
@@ -1444,7 +1595,6 @@ namespace OpenSim.Region.Framework.Scenes
1444 } 1595 }
1445 i++; 1596 i++;
1446 } 1597 }
1447
1448 //Paupaw:Do Proper PID for Autopilot here 1598 //Paupaw:Do Proper PID for Autopilot here
1449 if (bResetMoveToPosition) 1599 if (bResetMoveToPosition)
1450 { 1600 {
@@ -1479,6 +1629,9 @@ namespace OpenSim.Region.Framework.Scenes
1479 // Ignore z component of vector 1629 // Ignore z component of vector
1480 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1630 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1481 LocalVectorToTarget2D.Normalize(); 1631 LocalVectorToTarget2D.Normalize();
1632
1633 //We're not nudging
1634 Nudging = false;
1482 agent_control_v3 += LocalVectorToTarget2D; 1635 agent_control_v3 += LocalVectorToTarget2D;
1483 1636
1484 // update avatar movement flags. the avatar coordinate system is as follows: 1637 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1569,13 +1722,13 @@ namespace OpenSim.Region.Framework.Scenes
1569 // m_log.DebugFormat( 1722 // m_log.DebugFormat(
1570 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1723 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1571 1724
1572 AddNewMovement(agent_control_v3, q); 1725 AddNewMovement(agent_control_v3, q, Nudging);
1573 1726
1574 1727
1575 } 1728 }
1576 } 1729 }
1577 1730
1578 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1731 if (update_movementflag && !SitGround)
1579 Animator.UpdateMovementAnimations(); 1732 Animator.UpdateMovementAnimations();
1580 1733
1581 m_scene.EventManager.TriggerOnClientMovement(this); 1734 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1590,7 +1743,6 @@ namespace OpenSim.Region.Framework.Scenes
1590 m_sitAtAutoTarget = false; 1743 m_sitAtAutoTarget = false;
1591 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1744 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1592 //proxy.PCode = (byte)PCode.ParticleSystem; 1745 //proxy.PCode = (byte)PCode.ParticleSystem;
1593
1594 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1746 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1595 proxyObjectGroup.AttachToScene(m_scene); 1747 proxyObjectGroup.AttachToScene(m_scene);
1596 1748
@@ -1631,8 +1783,8 @@ namespace OpenSim.Region.Framework.Scenes
1631 return; 1783 return;
1632 } 1784 }
1633 m_moveToPositionInProgress = true; 1785 m_moveToPositionInProgress = true;
1634 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1786 m_moveToPositionTarget = new Vector3(locx, locy, locz + (m_appearance.AvatarHeight / 2.0f));
1635 } 1787 }
1636 catch (Exception ex) 1788 catch (Exception ex)
1637 { 1789 {
1638 //Why did I get this error? 1790 //Why did I get this error?
@@ -1654,7 +1806,7 @@ namespace OpenSim.Region.Framework.Scenes
1654 Velocity = Vector3.Zero; 1806 Velocity = Vector3.Zero;
1655 SendAvatarDataToAllAgents(); 1807 SendAvatarDataToAllAgents();
1656 1808
1657 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1809 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1658 } 1810 }
1659 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1811 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1660 m_requestedSitTargetUUID = UUID.Zero; 1812 m_requestedSitTargetUUID = UUID.Zero;
@@ -1691,25 +1843,22 @@ namespace OpenSim.Region.Framework.Scenes
1691 1843
1692 if (m_parentID != 0) 1844 if (m_parentID != 0)
1693 { 1845 {
1694 m_log.Debug("StandupCode Executed"); 1846 SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID);
1695 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1696 if (part != null) 1847 if (part != null)
1697 { 1848 {
1849 part.TaskInventory.LockItemsForRead(true);
1698 TaskInventoryDictionary taskIDict = part.TaskInventory; 1850 TaskInventoryDictionary taskIDict = part.TaskInventory;
1699 if (taskIDict != null) 1851 if (taskIDict != null)
1700 { 1852 {
1701 lock (taskIDict) 1853 foreach (UUID taskID in taskIDict.Keys)
1702 { 1854 {
1703 foreach (UUID taskID in taskIDict.Keys) 1855 UnRegisterControlEventsToScript(LocalId, taskID);
1704 { 1856 taskIDict[taskID].PermsMask &= ~(
1705 UnRegisterControlEventsToScript(LocalId, taskID); 1857 2048 | //PERMISSION_CONTROL_CAMERA
1706 taskIDict[taskID].PermsMask &= ~( 1858 4); // PERMISSION_TAKE_CONTROLS
1707 2048 | //PERMISSION_CONTROL_CAMERA
1708 4); // PERMISSION_TAKE_CONTROLS
1709 }
1710 } 1859 }
1711
1712 } 1860 }
1861 part.TaskInventory.LockItemsForRead(false);
1713 // Reset sit target. 1862 // Reset sit target.
1714 if (part.GetAvatarOnSitTarget() == UUID) 1863 if (part.GetAvatarOnSitTarget() == UUID)
1715 part.SitTargetAvatar = UUID.Zero; 1864 part.SitTargetAvatar = UUID.Zero;
@@ -1718,16 +1867,55 @@ namespace OpenSim.Region.Framework.Scenes
1718 m_parentPosition = part.GetWorldPosition(); 1867 m_parentPosition = part.GetWorldPosition();
1719 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1868 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1720 } 1869 }
1870 // part.GetWorldRotation() is the rotation of the object being sat on
1871 // Rotation is the sittiing Av's rotation
1872
1873 Quaternion partRot;
1874// if (part.LinkNum == 1)
1875// { // Root prim of linkset
1876// partRot = part.ParentGroup.RootPart.RotationOffset;
1877// }
1878// else
1879// { // single or child prim
1880
1881// }
1882 if (part == null) //CW: Part may be gone. llDie() for example.
1883 {
1884 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1885 }
1886 else
1887 {
1888 partRot = part.GetWorldRotation();
1889 }
1890
1891 Quaternion partIRot = Quaternion.Inverse(partRot);
1721 1892
1893 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1894 Vector3 avStandUp = new Vector3(0.3f, 0f, 0f) * avatarRot; // 0.3M infront of av
1895
1896
1722 if (m_physicsActor == null) 1897 if (m_physicsActor == null)
1723 { 1898 {
1724 AddToPhysicalScene(false); 1899 AddToPhysicalScene(false);
1725 } 1900 }
1726 1901 //CW: If the part isn't null then we can set the current position
1727 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1902 if (part != null)
1728 m_parentPosition = Vector3.Zero; 1903 {
1729 1904 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + ((m_pos - part.OffsetPosition) * partRot); // + av sit offset!
1730 m_parentID = 0; 1905 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1906 part.IsOccupied = false;
1907 part.ParentGroup.DeleteAvatar(ControllingClient.AgentId);
1908 }
1909 else
1910 {
1911 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1912 AbsolutePosition = m_lastWorldPosition;
1913 }
1914
1915 m_parentPosition = Vector3.Zero;
1916 m_parentID = 0;
1917 m_linkedPrim = UUID.Zero;
1918 m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1731 SendAvatarDataToAllAgents(); 1919 SendAvatarDataToAllAgents();
1732 m_requestedSitTargetID = 0; 1920 m_requestedSitTargetID = 0;
1733 if (m_physicsActor != null && m_appearance != null) 1921 if (m_physicsActor != null && m_appearance != null)
@@ -1736,7 +1924,6 @@ namespace OpenSim.Region.Framework.Scenes
1736 SetHeight(m_appearance.AvatarHeight); 1924 SetHeight(m_appearance.AvatarHeight);
1737 } 1925 }
1738 } 1926 }
1739
1740 Animator.TrySetMovementAnimation("STAND"); 1927 Animator.TrySetMovementAnimation("STAND");
1741 } 1928 }
1742 1929
@@ -1767,13 +1954,9 @@ namespace OpenSim.Region.Framework.Scenes
1767 Vector3 avSitOffSet = part.SitTargetPosition; 1954 Vector3 avSitOffSet = part.SitTargetPosition;
1768 Quaternion avSitOrientation = part.SitTargetOrientation; 1955 Quaternion avSitOrientation = part.SitTargetOrientation;
1769 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1956 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1770 1957 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1771 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1958 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1772 bool SitTargetisSet = 1959 if (SitTargetisSet && !SitTargetOccupied)
1773 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1774 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1775
1776 if (SitTargetisSet && SitTargetUnOccupied)
1777 { 1960 {
1778 //switch the target to this prim 1961 //switch the target to this prim
1779 return part; 1962 return part;
@@ -1787,85 +1970,168 @@ namespace OpenSim.Region.Framework.Scenes
1787 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1970 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1788 { 1971 {
1789 bool autopilot = true; 1972 bool autopilot = true;
1973 Vector3 autopilotTarget = new Vector3();
1974 Quaternion sitOrientation = Quaternion.Identity;
1790 Vector3 pos = new Vector3(); 1975 Vector3 pos = new Vector3();
1791 Quaternion sitOrientation = pSitOrientation;
1792 Vector3 cameraEyeOffset = Vector3.Zero; 1976 Vector3 cameraEyeOffset = Vector3.Zero;
1793 Vector3 cameraAtOffset = Vector3.Zero; 1977 Vector3 cameraAtOffset = Vector3.Zero;
1794 bool forceMouselook = false; 1978 bool forceMouselook = false;
1795 1979
1796 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1980 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1797 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1981 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1798 if (part != null) 1982 if (part == null) return;
1799 { 1983
1800 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1984 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1801 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1985 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1802 1986
1803 // Is a sit target available? 1987 // part is the prim to sit on
1804 Vector3 avSitOffSet = part.SitTargetPosition; 1988 // offset is the world-ref vector distance from that prim center to the click-spot
1805 Quaternion avSitOrientation = part.SitTargetOrientation; 1989 // UUID is the UUID of the Avatar doing the clicking
1806 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1990
1807 1991 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1808 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1992
1809 bool SitTargetisSet = 1993 // Is a sit target available?
1810 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1994 Vector3 avSitOffSet = part.SitTargetPosition;
1811 ( 1995 Quaternion avSitOrientation = part.SitTargetOrientation;
1812 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1996
1813 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1997 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1814 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1998 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1815 ) 1999 Quaternion partRot;
1816 )); 2000// if (part.LinkNum == 1)
1817 2001// { // Root prim of linkset
1818 if (SitTargetisSet && SitTargetUnOccupied) 2002// partRot = part.ParentGroup.RootPart.RotationOffset;
1819 { 2003// }
1820 part.SitTargetAvatar = UUID; 2004// else
1821 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 2005// { // single or child prim
1822 sitOrientation = avSitOrientation; 2006 partRot = part.GetWorldRotation();
1823 autopilot = false; 2007// }
1824 } 2008 Quaternion partIRot = Quaternion.Inverse(partRot);
1825 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 2009//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1826 2010 // Sit analysis rewritten by KF 091125
1827 pos = part.AbsolutePosition + offset; 2011 if (SitTargetisSet) // scipted sit
1828 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 2012 {
1829 //{ 2013 if (!part.IsOccupied)
1830 // offset = pos; 2014 {
1831 //autopilot = false; 2015//Console.WriteLine("Scripted, unoccupied");
1832 //} 2016 part.SitTargetAvatar = UUID; // set that Av will be on it
1833 if (m_physicsActor != null) 2017 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1834 { 2018
1835 // If we're not using the client autopilot, we're immediately warping the avatar to the location 2019 Quaternion nrot = avSitOrientation;
1836 // We can remove the physicsActor until they stand up. 2020 if (!part.IsRoot)
1837 m_sitAvatarHeight = m_physicsActor.Size.Z;
1838
1839 if (autopilot)
1840 { 2021 {
1841 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 2022 nrot = part.RotationOffset * avSitOrientation;
1842 {
1843 autopilot = false;
1844
1845 RemoveFromPhysicalScene();
1846 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
1847 }
1848 } 2023 }
1849 else 2024 sitOrientation = nrot; // Change rotatione to the scripted one
2025 OffsetRotation = nrot;
2026 autopilot = false; // Jump direct to scripted llSitPos()
2027 }
2028 else
2029 {
2030//Console.WriteLine("Scripted, occupied");
2031 return;
2032 }
2033 }
2034 else // Not Scripted
2035 {
2036 if ( (Math.Abs(offset.X) > 0.1f) || (Math.Abs(offset.Y) > 0.1f) ) // Changed 0.5M to 0.1M as they want to be able to sit close together
2037 {
2038 // large prim & offset, ignore if other Avs sitting
2039// offset.Z -= 0.05f;
2040 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
2041 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
2042
2043//Console.WriteLine(" offset ={0}", offset);
2044//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
2045//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
2046
2047 }
2048 else // small offset
2049 {
2050//Console.WriteLine("Small offset");
2051 if (!part.IsOccupied)
2052 {
2053 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
2054 autopilotTarget = part.AbsolutePosition;
2055//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget);
2056 }
2057 else return; // occupied small
2058 } // end large/small
2059 } // end Scripted/not
2060
2061 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2062
2063 cameraAtOffset = part.GetCameraAtOffset();
2064 cameraEyeOffset = part.GetCameraEyeOffset();
2065 forceMouselook = part.GetForceMouselook();
2066 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
2067 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
2068
2069 if (m_physicsActor != null)
2070 {
2071 // If we're not using the client autopilot, we're immediately warping the avatar to the location
2072 // We can remove the physicsActor until they stand up.
2073 m_sitAvatarHeight = m_physicsActor.Size.Z;
2074 if (autopilot)
2075 { // its not a scripted sit
2076// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
2077 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 256.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 256.0f) )
1850 { 2078 {
2079 autopilot = false; // close enough
2080 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2081 Not using the part's position because returning the AV to the last known standing
2082 position is likely to be more friendly, isn't it? */
1851 RemoveFromPhysicalScene(); 2083 RemoveFromPhysicalScene();
1852 } 2084 Velocity = Vector3.Zero;
2085 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
2086 } // else the autopilot will get us close
2087 }
2088 else
2089 { // its a scripted sit
2090 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
2091 I *am* using the part's position this time because we have no real idea how far away
2092 the avatar is from the sit target. */
2093 RemoveFromPhysicalScene();
2094 Velocity = Vector3.Zero;
1853 } 2095 }
1854
1855 cameraAtOffset = part.GetCameraAtOffset();
1856 cameraEyeOffset = part.GetCameraEyeOffset();
1857 forceMouselook = part.GetForceMouselook();
1858 } 2096 }
1859 2097 else return; // physactor is null!
1860 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 2098
1861 m_requestedSitTargetUUID = targetID; 2099 Vector3 offsetr; // = offset * partIRot;
2100 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
2101 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
2102 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
2103 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
2104 //offsetr = offset * partIRot;
2105//
2106 // }
2107 // else
2108 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
2109 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
2110 // (offset * partRot);
2111 // }
2112
2113//Console.WriteLine(" ");
2114//Console.WriteLine("link number ={0}", part.LinkNum);
2115//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
2116//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
2117//Console.WriteLine("Click offst ={0}", offset);
2118//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
2119//Console.WriteLine("offsetr ={0}", offsetr);
2120//Console.WriteLine("Camera At ={0}", cameraAtOffset);
2121//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
2122
2123 //NOTE: SendSitResponse should be relative to the GROUP *NOT* THE PRIM if we're sitting on a child
2124 ControllingClient.SendSitResponse(part.ParentGroup.UUID, ((offset * part.RotationOffset) + part.OffsetPosition), sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
2125
2126 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1862 // This calls HandleAgentSit twice, once from here, and the client calls 2127 // This calls HandleAgentSit twice, once from here, and the client calls
1863 // HandleAgentSit itself after it gets to the location 2128 // HandleAgentSit itself after it gets to the location
1864 // It doesn't get to the location until we've moved them there though 2129 // It doesn't get to the location until we've moved them there though
1865 // which happens in HandleAgentSit :P 2130 // which happens in HandleAgentSit :P
1866 m_autopilotMoving = autopilot; 2131 m_autopilotMoving = autopilot;
1867 m_autoPilotTarget = pos; 2132 m_autoPilotTarget = autopilotTarget;
1868 m_sitAtAutoTarget = autopilot; 2133 m_sitAtAutoTarget = autopilot;
2134 m_initialSitTarget = autopilotTarget;
1869 if (!autopilot) 2135 if (!autopilot)
1870 HandleAgentSit(remoteClient, UUID); 2136 HandleAgentSit(remoteClient, UUID);
1871 } 2137 }
@@ -2160,47 +2426,130 @@ namespace OpenSim.Region.Framework.Scenes
2160 { 2426 {
2161 if (part != null) 2427 if (part != null)
2162 { 2428 {
2429//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2163 if (part.GetAvatarOnSitTarget() == UUID) 2430 if (part.GetAvatarOnSitTarget() == UUID)
2164 { 2431 {
2432//Console.WriteLine("Scripted Sit");
2433 // Scripted sit
2165 Vector3 sitTargetPos = part.SitTargetPosition; 2434 Vector3 sitTargetPos = part.SitTargetPosition;
2166 Quaternion sitTargetOrient = part.SitTargetOrientation; 2435 Quaternion sitTargetOrient = part.SitTargetOrientation;
2167
2168 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2169 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2170
2171 //Quaternion result = (sitTargetOrient * vq) * nq;
2172
2173 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2436 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2174 m_pos += SIT_TARGET_ADJUSTMENT; 2437 m_pos += SIT_TARGET_ADJUSTMENT;
2438 if (!part.IsRoot)
2439 {
2440 m_pos *= part.RotationOffset;
2441 }
2175 m_bodyRot = sitTargetOrient; 2442 m_bodyRot = sitTargetOrient;
2176 //Rotation = sitTargetOrient;
2177 m_parentPosition = part.AbsolutePosition; 2443 m_parentPosition = part.AbsolutePosition;
2178 2444 part.IsOccupied = true;
2179 //SendTerseUpdateToAllClients(); 2445 part.ParentGroup.AddAvatar(agentID);
2180 } 2446 }
2181 else 2447 else
2182 { 2448 {
2183 m_pos -= part.AbsolutePosition; 2449 // if m_avUnscriptedSitPos is zero then Av sits above center
2450 // Else Av sits at m_avUnscriptedSitPos
2451
2452 // Non-scripted sit by Kitto Flora 21Nov09
2453 // Calculate angle of line from prim to Av
2454 Quaternion partIRot;
2455// if (part.LinkNum == 1)
2456// { // Root prim of linkset
2457// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2458// }
2459// else
2460// { // single or child prim
2461 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2462// }
2463 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2464 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2465 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2466 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2467 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2468 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2469 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2470 // Av sits at world euler <0,0, z>, translated by part rotation
2471 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2472
2184 m_parentPosition = part.AbsolutePosition; 2473 m_parentPosition = part.AbsolutePosition;
2185 } 2474 part.IsOccupied = true;
2475 part.ParentGroup.AddAvatar(agentID);
2476 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2477 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2478 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2479 m_avUnscriptedSitPos; // adds click offset, if any
2480 //Set up raytrace to find top surface of prim
2481 Vector3 size = part.Scale;
2482 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2483 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2484 Vector3 down = new Vector3(0f, 0f, -1f);
2485//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2486 m_scene.PhysicsScene.RaycastWorld(
2487 start, // Vector3 position,
2488 down, // Vector3 direction,
2489 mag, // float length,
2490 SitAltitudeCallback); // retMethod
2491 } // end scripted/not
2186 } 2492 }
2187 else 2493 else // no Av
2188 { 2494 {
2189 return; 2495 return;
2190 } 2496 }
2191 } 2497 }
2192 m_parentID = m_requestedSitTargetID;
2193 2498
2499 //We want our offsets to reference the root prim, not the child we may have sat on
2500 if (!part.IsRoot)
2501 {
2502 m_parentID = part.ParentGroup.RootPart.LocalId;
2503 m_pos += part.OffsetPosition;
2504 }
2505 else
2506 {
2507 m_parentID = m_requestedSitTargetID;
2508 }
2509
2510 m_linkedPrim = part.UUID;
2511 if (part.GetAvatarOnSitTarget() != UUID)
2512 {
2513 m_offsetRotation = m_offsetRotation / part.RotationOffset;
2514 }
2194 Velocity = Vector3.Zero; 2515 Velocity = Vector3.Zero;
2195 RemoveFromPhysicalScene(); 2516 RemoveFromPhysicalScene();
2196
2197 Animator.TrySetMovementAnimation(sitAnimation); 2517 Animator.TrySetMovementAnimation(sitAnimation);
2198 SendAvatarDataToAllAgents(); 2518 SendAvatarDataToAllAgents();
2199 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2200 // So we're also sending a terse update (which has avatar rotation)
2201 // [Update] We do now.
2202 //SendTerseUpdateToAllClients(); 2519 //SendTerseUpdateToAllClients();
2203 } 2520 }
2521
2522 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2523 {
2524 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2525 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2526 if(hitYN)
2527 {
2528 // m_pos = Av offset from prim center to make look like on center
2529 // m_parentPosition = Actual center pos of prim
2530 // collisionPoint = spot on prim where we want to sit
2531 // collisionPoint.Z = global sit surface height
2532 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2533 Quaternion partIRot;
2534// if (part.LinkNum == 1)
2535/// { // Root prim of linkset
2536// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2537// }
2538// else
2539// { // single or child prim
2540 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2541// }
2542 if (m_initialSitTarget != null)
2543 {
2544 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2545 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2546 //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2547 m_pos += offset;
2548 // ControllingClient.SendClearFollowCamProperties(part.UUID);
2549 }
2550
2551 }
2552 } // End SitAltitudeCallback KF.
2204 2553
2205 /// <summary> 2554 /// <summary>
2206 /// Event handler for the 'Always run' setting on the client 2555 /// Event handler for the 'Always run' setting on the client
@@ -2230,12 +2579,13 @@ namespace OpenSim.Region.Framework.Scenes
2230 /// </summary> 2579 /// </summary>
2231 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2580 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2232 /// <param name="rotation">The direction in which this avatar should now face. 2581 /// <param name="rotation">The direction in which this avatar should now face.
2233 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2582 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2234 { 2583 {
2235 if (m_isChildAgent) 2584 if (m_isChildAgent)
2236 { 2585 {
2237 // WHAT??? 2586 // WHAT???
2238 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!"); 2587 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent");
2588
2239 return; 2589 return;
2240 } 2590 }
2241 2591
@@ -2244,15 +2594,26 @@ namespace OpenSim.Region.Framework.Scenes
2244 Rotation = rotation; 2594 Rotation = rotation;
2245 Vector3 direc = vec * rotation; 2595 Vector3 direc = vec * rotation;
2246 direc.Normalize(); 2596 direc.Normalize();
2597 PhysicsActor actor = m_physicsActor;
2598
2599 if (actor.Flying != m_flyingOld) // add for fly velocity control
2600 {
2601 m_flyingOld = actor.Flying; // add for fly velocity control
2602 if (!actor.Flying) m_wasFlying = true; // add for fly velocity control
2603 }
2604
2605 if (m_physicsActor.IsColliding == true) m_wasFlying = false; // add for fly velocity control
2606
2607 if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up.
2247 2608
2248 direc *= 0.03f * 128f * m_speedModifier; 2609 direc *= 0.03f * 128f * m_speedModifier;
2249 2610
2250 PhysicsActor actor = m_physicsActor;
2251 if (actor != null) 2611 if (actor != null)
2252 { 2612 {
2253 if (actor.Flying) 2613 if (actor.Flying)
2254 { 2614 {
2255 direc *= 4.0f; 2615// rm speed mod direc *= 4.0f;
2616 direc *= 5.2f; // for speed mod
2256 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 2617 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
2257 //bool colliding = (m_physicsActor.IsColliding==true); 2618 //bool colliding = (m_physicsActor.IsColliding==true);
2258 //if (controlland) 2619 //if (controlland)
@@ -2265,22 +2626,34 @@ namespace OpenSim.Region.Framework.Scenes
2265 // m_log.Info("[AGENT]: Stop FLying"); 2626 // m_log.Info("[AGENT]: Stop FLying");
2266 //} 2627 //}
2267 } 2628 }
2629 if (Animator.m_falling && m_wasFlying) // if falling from flying, disable motion add
2630 {
2631 direc *= 0.0f;
2632 }
2633 /* This jumping section removed to SPA
2268 else if (!actor.Flying && actor.IsColliding) 2634 else if (!actor.Flying && actor.IsColliding)
2269 { 2635 {
2270 if (direc.Z > 2.0f) 2636 if (direc.Z > 2.0f)
2271 { 2637 {
2272 direc.Z *= 3.0f; 2638 if(m_animator.m_animTickJump == -1)
2273 2639 {
2274 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2640 direc.Z *= 3.0f; // jump
2275 Animator.TrySetMovementAnimation("PREJUMP"); 2641 }
2276 Animator.TrySetMovementAnimation("JUMP"); 2642 else
2643 {
2644 direc.Z *= 0.1f; // prejump
2645 }
2646 / * Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs
2647 Animator.TrySetMovementAnimation("PREJUMP");
2648 Animator.TrySetMovementAnimation("JUMP");
2649 * /
2277 } 2650 }
2278 } 2651 } */
2279 } 2652 }
2280 2653
2281 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2654 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2282 m_forceToApply = direc; 2655 m_forceToApply = direc;
2283 2656 m_isNudging = Nudging;
2284 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2657 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2285 } 2658 }
2286 2659
@@ -2329,6 +2702,9 @@ namespace OpenSim.Region.Framework.Scenes
2329 2702
2330 CheckForSignificantMovement(); // sends update to the modules. 2703 CheckForSignificantMovement(); // sends update to the modules.
2331 } 2704 }
2705
2706 //Sending prim updates AFTER the avatar terse updates are sent
2707 SendPrimUpdates();
2332 } 2708 }
2333 2709
2334 #endregion 2710 #endregion
@@ -3133,6 +3509,7 @@ namespace OpenSim.Region.Framework.Scenes
3133 m_callbackURI = cAgent.CallbackURI; 3509 m_callbackURI = cAgent.CallbackURI;
3134 3510
3135 m_pos = cAgent.Position; 3511 m_pos = cAgent.Position;
3512
3136 m_velocity = cAgent.Velocity; 3513 m_velocity = cAgent.Velocity;
3137 m_CameraCenter = cAgent.Center; 3514 m_CameraCenter = cAgent.Center;
3138 m_CameraAtAxis = cAgent.AtAxis; 3515 m_CameraAtAxis = cAgent.AtAxis;
@@ -3251,20 +3628,45 @@ namespace OpenSim.Region.Framework.Scenes
3251 /// </summary> 3628 /// </summary>
3252 public override void UpdateMovement() 3629 public override void UpdateMovement()
3253 { 3630 {
3254 if (m_forceToApply.HasValue) 3631 if (Animator!=null) // add for jumping
3255 { 3632 { // add for jumping
3256 Vector3 force = m_forceToApply.Value; 3633 // if (!m_animator.m_jumping) // add for jumping
3257 3634 // { // add for jumping
3258 m_updateflag = true;
3259 3635
3260 // The magic constant 0.95f seems to make walking feel less jerky, 3636 if (m_forceToApply.HasValue) // this section realigned
3261 // probably because it hackishly accounts for the overall latency of 3637 {
3262 // these Velocity updates -- Diva
3263 Velocity = force * .95F;
3264 3638
3265 m_forceToApply = null; 3639 Vector3 force = m_forceToApply.Value;
3266 } 3640 m_updateflag = true;
3267 } 3641if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3642 Velocity = force;
3643//Console.WriteLine("UM1 {0}", Velocity);
3644 m_forceToApply = null;
3645 }
3646 else
3647 {
3648 if (m_isNudging)
3649 {
3650 Vector3 force = Vector3.Zero;
3651
3652 m_updateflag = true;
3653if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3654 Velocity = force;
3655//Console.WriteLine("UM2 {0}", Velocity);
3656 m_isNudging = false;
3657 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3658 }
3659 else // add for jumping
3660 { // add for jumping
3661 Vector3 force = Vector3.Zero; // add for jumping
3662if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
3663//Console.WriteLine("UM3 {0}", Velocity);
3664 Velocity = force; // add for jumping
3665 }
3666 }
3667 // } // end realign
3668 } // add for jumping
3669 } // add for jumping
3268 3670
3269 /// <summary> 3671 /// <summary>
3270 /// Adds a physical representation of the avatar to the Physics plugin 3672 /// Adds a physical representation of the avatar to the Physics plugin
@@ -3278,10 +3680,8 @@ namespace OpenSim.Region.Framework.Scenes
3278 3680
3279 Vector3 pVec = AbsolutePosition; 3681 Vector3 pVec = AbsolutePosition;
3280 3682
3281 // Old bug where the height was in centimeters instead of meters
3282 m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, 3683 m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec,
3283 new Vector3(0f, 0f, m_appearance.AvatarHeight), isFlying); 3684 new Vector3(0f, 0f, m_appearance.AvatarHeight), isFlying);
3284
3285 scene.AddPhysicsActorTaint(m_physicsActor); 3685 scene.AddPhysicsActorTaint(m_physicsActor);
3286 //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3686 //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3287 m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3687 m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
@@ -3305,18 +3705,29 @@ namespace OpenSim.Region.Framework.Scenes
3305 { 3705 {
3306 if (e == null) 3706 if (e == null)
3307 return; 3707 return;
3308 3708
3309 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3709 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3310 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3311 // as of this comment the interval is set in AddToPhysicalScene 3710 // as of this comment the interval is set in AddToPhysicalScene
3312 if (Animator!=null) 3711 if (Animator!=null)
3313 Animator.UpdateMovementAnimations(); 3712 {
3713 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3714 { // else its will lock out other animation changes, like ground sit.
3715 Animator.UpdateMovementAnimations();
3716 m_updateCount--;
3717 }
3718 }
3314 3719
3315 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3720 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3316 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3721 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3317 3722
3318 CollisionPlane = Vector4.UnitW; 3723 CollisionPlane = Vector4.UnitW;
3319 3724
3725 if (m_lastColCount != coldata.Count)
3726 {
3727 m_updateCount = UPDATE_COUNT;
3728 m_lastColCount = coldata.Count;
3729 }
3730
3320 if (coldata.Count != 0 && Animator != null) 3731 if (coldata.Count != 0 && Animator != null)
3321 { 3732 {
3322 switch (Animator.CurrentMovementAnimation) 3733 switch (Animator.CurrentMovementAnimation)
@@ -3346,6 +3757,148 @@ namespace OpenSim.Region.Framework.Scenes
3346 } 3757 }
3347 } 3758 }
3348 3759
3760 List<uint> thisHitColliders = new List<uint>();
3761 List<uint> endedColliders = new List<uint>();
3762 List<uint> startedColliders = new List<uint>();
3763
3764 foreach (uint localid in coldata.Keys)
3765 {
3766 thisHitColliders.Add(localid);
3767 if (!m_lastColliders.Contains(localid))
3768 {
3769 startedColliders.Add(localid);
3770 }
3771 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
3772 }
3773
3774 // calculate things that ended colliding
3775 foreach (uint localID in m_lastColliders)
3776 {
3777 if (!thisHitColliders.Contains(localID))
3778 {
3779 endedColliders.Add(localID);
3780 }
3781 }
3782 //add the items that started colliding this time to the last colliders list.
3783 foreach (uint localID in startedColliders)
3784 {
3785 m_lastColliders.Add(localID);
3786 }
3787 // remove things that ended colliding from the last colliders list
3788 foreach (uint localID in endedColliders)
3789 {
3790 m_lastColliders.Remove(localID);
3791 }
3792
3793 // do event notification
3794 if (startedColliders.Count > 0)
3795 {
3796 ColliderArgs StartCollidingMessage = new ColliderArgs();
3797 List<DetectedObject> colliding = new List<DetectedObject>();
3798 foreach (uint localId in startedColliders)
3799 {
3800 if (localId == 0)
3801 continue;
3802
3803 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3804 string data = "";
3805 if (obj != null)
3806 {
3807 DetectedObject detobj = new DetectedObject();
3808 detobj.keyUUID = obj.UUID;
3809 detobj.nameStr = obj.Name;
3810 detobj.ownerUUID = obj.OwnerID;
3811 detobj.posVector = obj.AbsolutePosition;
3812 detobj.rotQuat = obj.GetWorldRotation();
3813 detobj.velVector = obj.Velocity;
3814 detobj.colliderType = 0;
3815 detobj.groupUUID = obj.GroupID;
3816 colliding.Add(detobj);
3817 }
3818 }
3819
3820 if (colliding.Count > 0)
3821 {
3822 StartCollidingMessage.Colliders = colliding;
3823
3824 foreach (SceneObjectGroup att in Attachments)
3825 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
3826 }
3827 }
3828
3829 if (endedColliders.Count > 0)
3830 {
3831 ColliderArgs EndCollidingMessage = new ColliderArgs();
3832 List<DetectedObject> colliding = new List<DetectedObject>();
3833 foreach (uint localId in endedColliders)
3834 {
3835 if (localId == 0)
3836 continue;
3837
3838 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3839 string data = "";
3840 if (obj != null)
3841 {
3842 DetectedObject detobj = new DetectedObject();
3843 detobj.keyUUID = obj.UUID;
3844 detobj.nameStr = obj.Name;
3845 detobj.ownerUUID = obj.OwnerID;
3846 detobj.posVector = obj.AbsolutePosition;
3847 detobj.rotQuat = obj.GetWorldRotation();
3848 detobj.velVector = obj.Velocity;
3849 detobj.colliderType = 0;
3850 detobj.groupUUID = obj.GroupID;
3851 colliding.Add(detobj);
3852 }
3853 }
3854
3855 if (colliding.Count > 0)
3856 {
3857 EndCollidingMessage.Colliders = colliding;
3858
3859 foreach (SceneObjectGroup att in Attachments)
3860 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
3861 }
3862 }
3863
3864 if (thisHitColliders.Count > 0)
3865 {
3866 ColliderArgs CollidingMessage = new ColliderArgs();
3867 List<DetectedObject> colliding = new List<DetectedObject>();
3868 foreach (uint localId in thisHitColliders)
3869 {
3870 if (localId == 0)
3871 continue;
3872
3873 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3874 string data = "";
3875 if (obj != null)
3876 {
3877 DetectedObject detobj = new DetectedObject();
3878 detobj.keyUUID = obj.UUID;
3879 detobj.nameStr = obj.Name;
3880 detobj.ownerUUID = obj.OwnerID;
3881 detobj.posVector = obj.AbsolutePosition;
3882 detobj.rotQuat = obj.GetWorldRotation();
3883 detobj.velVector = obj.Velocity;
3884 detobj.colliderType = 0;
3885 detobj.groupUUID = obj.GroupID;
3886 colliding.Add(detobj);
3887 }
3888 }
3889
3890 if (colliding.Count > 0)
3891 {
3892 CollidingMessage.Colliders = colliding;
3893
3894 lock (m_attachments)
3895 {
3896 foreach (SceneObjectGroup att in m_attachments)
3897 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
3898 }
3899 }
3900 }
3901
3349 if (m_invulnerable) 3902 if (m_invulnerable)
3350 return; 3903 return;
3351 3904
@@ -3771,6 +4324,39 @@ namespace OpenSim.Region.Framework.Scenes
3771 return; 4324 return;
3772 } 4325 }
3773 4326
4327 XmlDocument doc = new XmlDocument();
4328 string stateData = String.Empty;
4329
4330 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
4331 if (attServ != null)
4332 {
4333 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
4334 stateData = attServ.Get(ControllingClient.AgentId.ToString());
4335 if (stateData != String.Empty)
4336 {
4337 try
4338 {
4339 doc.LoadXml(stateData);
4340 }
4341 catch { }
4342 }
4343 }
4344
4345 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
4346
4347 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
4348 if (nodes.Count > 0)
4349 {
4350 foreach (XmlNode n in nodes)
4351 {
4352 XmlElement elem = (XmlElement)n;
4353 string itemID = elem.GetAttribute("ItemID");
4354 string xml = elem.InnerXml;
4355
4356 itemData[new UUID(itemID)] = xml;
4357 }
4358 }
4359
3774 List<AvatarAttachment> attachments = m_appearance.GetAttachments(); 4360 List<AvatarAttachment> attachments = m_appearance.GetAttachments();
3775 foreach (AvatarAttachment attach in attachments) 4361 foreach (AvatarAttachment attach in attachments)
3776 { 4362 {
@@ -3791,7 +4377,30 @@ namespace OpenSim.Region.Framework.Scenes
3791 4377
3792 try 4378 try
3793 { 4379 {
3794 m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p); 4380 string xmlData;
4381 XmlDocument d = new XmlDocument();
4382 UUID asset;
4383 if (itemData.TryGetValue(itemID, out xmlData))
4384 {
4385 d.LoadXml(xmlData);
4386 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID);
4387
4388 // Rez from inventory
4389 asset
4390 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d);
4391
4392 }
4393 else
4394 {
4395 // Rez from inventory (with a null doc to let
4396 // CHANGED_OWNER happen)
4397 asset
4398 = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, null);
4399 }
4400
4401 m_log.InfoFormat(
4402 "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2}",
4403 p, itemID, asset);
3795 } 4404 }
3796 catch (Exception e) 4405 catch (Exception e)
3797 { 4406 {
@@ -3824,6 +4433,15 @@ namespace OpenSim.Region.Framework.Scenes
3824 m_reprioritization_called = false; 4433 m_reprioritization_called = false;
3825 } 4434 }
3826 } 4435 }
4436
4437 private Vector3 Quat2Euler(Quaternion rot){
4438 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4439 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4440 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4441 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4442 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4443 return(new Vector3(x,y,z));
4444 }
3827 4445
3828 public void SaveChangedAttachments() 4446 public void SaveChangedAttachments()
3829 { 4447 {
@@ -3847,5 +4465,30 @@ namespace OpenSim.Region.Framework.Scenes
3847 } 4465 }
3848 } 4466 }
3849 } 4467 }
4468
4469 private void CheckLandingPoint(ref Vector3 pos)
4470 {
4471 // Never constrain lures
4472 if ((TeleportFlags & TeleportFlags.ViaLure) != 0)
4473 return;
4474
4475 if (m_scene.RegionInfo.EstateSettings.AllowDirectTeleport)
4476 return;
4477
4478 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
4479
4480 if (land.LandData.LandingType == (byte)LandingType.LandingPoint &&
4481 land.LandData.UserLocation != Vector3.Zero &&
4482 land.LandData.OwnerID != m_uuid &&
4483 (!m_scene.Permissions.IsGod(m_uuid)) &&
4484 (!m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid)))
4485 {
4486 float curr = Vector3.Distance(AbsolutePosition, pos);
4487 if (Vector3.Distance(land.LandData.UserLocation, pos) < curr)
4488 pos = land.LandData.UserLocation;
4489 else
4490 ControllingClient.SendAlertMessage("Can't teleport closer to destination");
4491 }
4492 }
3850 } 4493 }
3851} 4494}