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.cs1072
1 files changed, 759 insertions, 313 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 0219540..1d6898b 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -63,6 +63,7 @@ namespace OpenSim.Region.Framework.Scenes
63 63
64 struct ScriptControllers 64 struct ScriptControllers
65 { 65 {
66 public UUID objectID;
66 public UUID itemID; 67 public UUID itemID;
67 public ScriptControlled ignoreControls; 68 public ScriptControlled ignoreControls;
68 public ScriptControlled eventControls; 69 public ScriptControlled eventControls;
@@ -99,7 +100,7 @@ namespace OpenSim.Region.Framework.Scenes
99 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 100 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
100 /// issue #1716 101 /// issue #1716
101 /// </summary> 102 /// </summary>
102 public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f); 103 public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.4f);
103 104
104 /// <summary> 105 /// <summary>
105 /// Movement updates for agents in neighboring regions are sent directly to clients. 106 /// Movement updates for agents in neighboring regions are sent directly to clients.
@@ -139,6 +140,8 @@ namespace OpenSim.Region.Framework.Scenes
139 private Vector3 m_lastPosition; 140 private Vector3 m_lastPosition;
140 private Quaternion m_lastRotation; 141 private Quaternion m_lastRotation;
141 private Vector3 m_lastVelocity; 142 private Vector3 m_lastVelocity;
143 private Vector3 m_lastSize = new Vector3(0.45f,0.6f,1.9f);
144
142 145
143 private Vector3? m_forceToApply; 146 private Vector3? m_forceToApply;
144 private int m_userFlags; 147 private int m_userFlags;
@@ -171,6 +174,7 @@ namespace OpenSim.Region.Framework.Scenes
171// private int m_lastColCount = -1; //KF: Look for Collision chnages 174// private int m_lastColCount = -1; //KF: Look for Collision chnages
172// private int m_updateCount = 0; //KF: Update Anims for a while 175// private int m_updateCount = 0; //KF: Update Anims for a while
173// private static readonly int UPDATE_COUNT = 10; // how many frames to update for 176// private static readonly int UPDATE_COUNT = 10; // how many frames to update for
177 private List<uint> m_lastColliders = new List<uint>();
174 178
175 private TeleportFlags m_teleportFlags; 179 private TeleportFlags m_teleportFlags;
176 public TeleportFlags TeleportFlags 180 public TeleportFlags TeleportFlags
@@ -221,8 +225,6 @@ namespace OpenSim.Region.Framework.Scenes
221 /// </summary> 225 /// </summary>
222 public bool LandAtTarget { get; private set; } 226 public bool LandAtTarget { get; private set; }
223 227
224 private bool m_followCamAuto;
225
226 private int m_movementUpdateCount; 228 private int m_movementUpdateCount;
227 private const int NumMovementsBetweenRayCast = 5; 229 private const int NumMovementsBetweenRayCast = 5;
228 230
@@ -230,6 +232,13 @@ namespace OpenSim.Region.Framework.Scenes
230 //private int m_moveToPositionStateStatus; 232 //private int m_moveToPositionStateStatus;
231 //***************************************************** 233 //*****************************************************
232 234
235 private bool m_collisionEventFlag = false;
236 private object m_collisionEventLock = new Object();
237
238 private int m_movementAnimationUpdateCounter = 0;
239
240 private Vector3 m_prevSitOffset;
241
233 protected AvatarAppearance m_appearance; 242 protected AvatarAppearance m_appearance;
234 243
235 public AvatarAppearance Appearance 244 public AvatarAppearance Appearance
@@ -344,6 +353,9 @@ namespace OpenSim.Region.Framework.Scenes
344 /// </summary> 353 /// </summary>
345 protected Vector3 m_lastCameraPosition; 354 protected Vector3 m_lastCameraPosition;
346 355
356 private Vector4 m_lastCameraCollisionPlane = new Vector4(0f, 0f, 0f, 1);
357 private bool m_doingCamRayCast = false;
358
347 public Vector3 CameraPosition { get; set; } 359 public Vector3 CameraPosition { get; set; }
348 360
349 public Quaternion CameraRotation 361 public Quaternion CameraRotation
@@ -424,7 +436,7 @@ namespace OpenSim.Region.Framework.Scenes
424 get { return (IClientCore)ControllingClient; } 436 get { return (IClientCore)ControllingClient; }
425 } 437 }
426 438
427 public Vector3 ParentPosition { get; set; } 439// public Vector3 ParentPosition { get; set; }
428 440
429 /// <summary> 441 /// <summary>
430 /// Position of this avatar relative to the region the avatar is in 442 /// Position of this avatar relative to the region the avatar is in
@@ -482,7 +494,7 @@ namespace OpenSim.Region.Framework.Scenes
482 if (ParentID == 0) 494 if (ParentID == 0)
483 { 495 {
484 m_pos = value; 496 m_pos = value;
485 ParentPosition = Vector3.Zero; 497// ParentPosition = Vector3.Zero;
486 } 498 }
487 499
488 //m_log.DebugFormat( 500 //m_log.DebugFormat(
@@ -551,7 +563,24 @@ namespace OpenSim.Region.Framework.Scenes
551// Scene.RegionInfo.RegionName, Name, m_velocity); 563// Scene.RegionInfo.RegionName, Name, m_velocity);
552 } 564 }
553 } 565 }
566/*
567 public override Vector3 AngularVelocity
568 {
569 get
570 {
571 if (PhysicsActor != null)
572 {
573 m_rotationalvelocity = PhysicsActor.RotationalVelocity;
574
575 // m_log.DebugFormat(
576 // "[SCENE PRESENCE]: Set velocity {0} for {1} in {2} via getting Velocity!",
577 // m_velocity, Name, Scene.RegionInfo.RegionName);
578 }
554 579
580 return m_rotationalvelocity;
581 }
582 }
583*/
555 private Quaternion m_bodyRot = Quaternion.Identity; 584 private Quaternion m_bodyRot = Quaternion.Identity;
556 585
557 public Quaternion Rotation 586 public Quaternion Rotation
@@ -562,19 +591,34 @@ namespace OpenSim.Region.Framework.Scenes
562 m_bodyRot = value; 591 m_bodyRot = value;
563 if (PhysicsActor != null) 592 if (PhysicsActor != null)
564 { 593 {
565 PhysicsActor.Orientation = m_bodyRot; 594 try
595 {
596 PhysicsActor.Orientation = m_bodyRot;
597 }
598 catch (Exception e)
599 {
600 m_log.Error("[SCENE PRESENCE]: Orientation " + e.Message);
601 }
566 } 602 }
567// m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot); 603// m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot);
568 } 604 }
569 } 605 }
570 606
571 public bool IsChildAgent { get; set; } 607 public bool IsChildAgent { get; set; }
608 public bool IsLoggingIn { get; set; }
572 609
573 /// <summary> 610 /// <summary>
574 /// If the avatar is sitting, the local ID of the prim that it's sitting on. If not sitting then zero. 611 /// If the avatar is sitting, the local ID of the prim that it's sitting on. If not sitting then zero.
575 /// </summary> 612 /// </summary>
576 public uint ParentID { get; set; } 613 public uint ParentID { get; set; }
577 614
615 public UUID ParentUUID
616 {
617 get { return m_parentUUID; }
618 set { m_parentUUID = value; }
619 }
620 private UUID m_parentUUID = UUID.Zero;
621
578 /// <summary> 622 /// <summary>
579 /// Are we sitting on an object? 623 /// Are we sitting on an object?
580 /// </summary> 624 /// </summary>
@@ -698,6 +742,7 @@ namespace OpenSim.Region.Framework.Scenes
698 AttachmentsSyncLock = new Object(); 742 AttachmentsSyncLock = new Object();
699 AllowMovement = true; 743 AllowMovement = true;
700 IsChildAgent = true; 744 IsChildAgent = true;
745 IsLoggingIn = false;
701 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault; 746 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault;
702 Animator = new ScenePresenceAnimator(this); 747 Animator = new ScenePresenceAnimator(this);
703 PresenceType = type; 748 PresenceType = type;
@@ -741,6 +786,33 @@ namespace OpenSim.Region.Framework.Scenes
741 Appearance = appearance; 786 Appearance = appearance;
742 } 787 }
743 788
789 private void RegionHeartbeatEnd(Scene scene)
790 {
791 if (IsChildAgent)
792 return;
793
794 m_movementAnimationUpdateCounter ++;
795 if (m_movementAnimationUpdateCounter >= 2)
796 {
797 m_movementAnimationUpdateCounter = 0;
798 if (Animator != null)
799 {
800 // If the parentID == 0 we are not sitting
801 // if !SitGournd then we are not sitting on the ground
802 // Fairly straightforward, now here comes the twist
803 // if ParentUUID is NOT UUID.Zero, we are looking to
804 // be sat on an object that isn't there yet. Should
805 // be treated as if sat.
806 if(ParentID == 0 && !SitGround && ParentUUID == UUID.Zero) // skip it if sitting
807 Animator.UpdateMovementAnimations();
808 }
809 else
810 {
811 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
812 }
813 }
814 }
815
744 public void RegisterToEvents() 816 public void RegisterToEvents()
745 { 817 {
746 ControllingClient.OnCompleteMovementToRegion += CompleteMovement; 818 ControllingClient.OnCompleteMovementToRegion += CompleteMovement;
@@ -750,8 +822,10 @@ namespace OpenSim.Region.Framework.Scenes
750 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; 822 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
751 ControllingClient.OnStartAnim += HandleStartAnim; 823 ControllingClient.OnStartAnim += HandleStartAnim;
752 ControllingClient.OnStopAnim += HandleStopAnim; 824 ControllingClient.OnStopAnim += HandleStopAnim;
825 ControllingClient.OnChangeAnim += avnHandleChangeAnim;
753 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls; 826 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls;
754 ControllingClient.OnAutoPilotGo += MoveToTarget; 827 ControllingClient.OnAutoPilotGo += MoveToTarget;
828 ControllingClient.OnUpdateThrottles += RaiseUpdateThrottles;
755 829
756 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); 830 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
757 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); 831 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
@@ -810,10 +884,40 @@ namespace OpenSim.Region.Framework.Scenes
810 "[SCENE]: Upgrading child to root agent for {0} in {1}", 884 "[SCENE]: Upgrading child to root agent for {0} in {1}",
811 Name, m_scene.RegionInfo.RegionName); 885 Name, m_scene.RegionInfo.RegionName);
812 886
813 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
814
815 bool wasChild = IsChildAgent; 887 bool wasChild = IsChildAgent;
816 IsChildAgent = false; 888
889 if (ParentUUID != UUID.Zero)
890 {
891 m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID);
892 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID);
893 if (part == null)
894 {
895 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
896 }
897 else
898 {
899 part.ParentGroup.AddAvatar(UUID);
900 if (part.SitTargetPosition != Vector3.Zero)
901 part.SitTargetAvatar = UUID;
902// ParentPosition = part.GetWorldPosition();
903 ParentID = part.LocalId;
904 ParentPart = part;
905 m_pos = m_prevSitOffset;
906// pos = ParentPosition;
907 pos = part.GetWorldPosition();
908 }
909 ParentUUID = UUID.Zero;
910
911 IsChildAgent = false;
912
913// Animator.TrySetMovementAnimation("SIT");
914 }
915 else
916 {
917 IsChildAgent = false;
918 IsLoggingIn = false;
919 }
920
817 921
818 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 922 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
819 if (gm != null) 923 if (gm != null)
@@ -823,62 +927,99 @@ namespace OpenSim.Region.Framework.Scenes
823 927
824 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 928 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
825 929
826 // Moved this from SendInitialData to ensure that Appearance is initialized 930 UUID groupUUID = UUID.Zero;
827 // before the inventory is processed in MakeRootAgent. This fixes a race condition 931 string GroupName = string.Empty;
828 // related to the handling of attachments 932 ulong groupPowers = 0;
829 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance); 933
830 if (m_scene.TestBorderCross(pos, Cardinals.E)) 934 // ----------------------------------
935 // Previous Agent Difference - AGNI sends an unsolicited AgentDataUpdate upon root agent status
936 try
831 { 937 {
832 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 938 if (gm != null)
833 pos.X = crossedBorder.BorderLine.Z - 1; 939 {
940 groupUUID = ControllingClient.ActiveGroupId;
941 GroupRecord record = gm.GetGroupRecord(groupUUID);
942 if (record != null)
943 GroupName = record.GroupName;
944 GroupMembershipData groupMembershipData = gm.GetMembershipData(groupUUID, m_uuid);
945 if (groupMembershipData != null)
946 groupPowers = groupMembershipData.GroupPowers;
947 }
948 ControllingClient.SendAgentDataUpdate(m_uuid, groupUUID, Firstname, Lastname, groupPowers, GroupName,
949 Grouptitle);
834 } 950 }
835 951 catch (Exception e)
836 if (m_scene.TestBorderCross(pos, Cardinals.N))
837 { 952 {
838 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 953 m_log.Debug("[AGENTUPDATE]: " + e.ToString());
839 pos.Y = crossedBorder.BorderLine.Z - 1;
840 } 954 }
955 // ------------------------------------
841 956
842 CheckAndAdjustLandingPoint(ref pos); 957 if (ParentID == 0)
843
844 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
845 { 958 {
846 m_log.WarnFormat( 959 // Moved this from SendInitialData to ensure that Appearance is initialized
847 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", 960 // before the inventory is processed in MakeRootAgent. This fixes a race condition
848 pos, Name, UUID); 961 // related to the handling of attachments
962 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
963 if (m_scene.TestBorderCross(pos, Cardinals.E))
964 {
965 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
966 pos.X = crossedBorder.BorderLine.Z - 1;
967 }
849 968
850 if (pos.X < 0f) pos.X = 0f; 969 if (m_scene.TestBorderCross(pos, Cardinals.N))
851 if (pos.Y < 0f) pos.Y = 0f; 970 {
852 if (pos.Z < 0f) pos.Z = 0f; 971 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
853 } 972 pos.Y = crossedBorder.BorderLine.Z - 1;
973 }
854 974
855 float localAVHeight = 1.56f; 975 CheckAndAdjustLandingPoint(ref pos);
856 if (Appearance.AvatarHeight > 0)
857 localAVHeight = Appearance.AvatarHeight;
858 976
859 float posZLimit = 0; 977 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
978 {
979 m_log.WarnFormat(
980 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
981 pos, Name, UUID);
860 982
861 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 983 if (pos.X < 0f) pos.X = 0f;
862 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 984 if (pos.Y < 0f) pos.Y = 0f;
863 985 if (pos.Z < 0f) pos.Z = 0f;
864 float newPosZ = posZLimit + localAVHeight / 2; 986 }
865 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
866 {
867 pos.Z = newPosZ;
868 }
869 AbsolutePosition = pos;
870 987
871 AddToPhysicalScene(isFlying); 988 float localAVHeight = 1.56f;
989 if (Appearance.AvatarHeight > 0)
990 localAVHeight = Appearance.AvatarHeight;
872 991
873 if (ForceFly) 992 float posZLimit = 0;
874 {
875 Flying = true;
876 }
877 else if (FlyDisabled)
878 {
879 Flying = false;
880 }
881 993
994 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
995 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
996
997 float newPosZ = posZLimit + localAVHeight / 2;
998 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
999 {
1000 pos.Z = newPosZ;
1001 }
1002 AbsolutePosition = pos;
1003
1004 if (m_teleportFlags == TeleportFlags.Default)
1005 {
1006 Vector3 vel = Velocity;
1007 AddToPhysicalScene(isFlying);
1008 if (PhysicsActor != null)
1009 PhysicsActor.SetMomentum(vel);
1010 }
1011 else
1012 AddToPhysicalScene(isFlying);
1013
1014 if (ForceFly)
1015 {
1016 Flying = true;
1017 }
1018 else if (FlyDisabled)
1019 {
1020 Flying = false;
1021 }
1022 }
882 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 1023 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
883 // avatar to return to the standing position in mid-air. On login it looks like this is being sent 1024 // avatar to return to the standing position in mid-air. On login it looks like this is being sent
884 // elsewhere anyway 1025 // elsewhere anyway
@@ -898,14 +1039,19 @@ namespace OpenSim.Region.Framework.Scenes
898 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name); 1039 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name);
899 1040
900 // Resume scripts 1041 // Resume scripts
901 foreach (SceneObjectGroup sog in m_attachments) 1042 Util.FireAndForget(delegate(object x) {
902 { 1043 foreach (SceneObjectGroup sog in m_attachments)
903 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); 1044 {
904 sog.ResumeScripts(); 1045 sog.ScheduleGroupForFullUpdate();
905 } 1046 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
1047 sog.ResumeScripts();
1048 }
1049 });
906 } 1050 }
907 } 1051 }
908 1052
1053 SendAvatarDataToAllAgents();
1054
909 // send the animations of the other presences to me 1055 // send the animations of the other presences to me
910 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) 1056 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence)
911 { 1057 {
@@ -916,9 +1062,12 @@ namespace OpenSim.Region.Framework.Scenes
916 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will 1062 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will
917 // stall on the border crossing since the existing child agent will still have the last movement 1063 // stall on the border crossing since the existing child agent will still have the last movement
918 // recorded, which stops the input from being processed. 1064 // recorded, which stops the input from being processed.
1065
919 MovementFlag = 0; 1066 MovementFlag = 0;
920 1067
921 m_scene.EventManager.TriggerOnMakeRootAgent(this); 1068 m_scene.EventManager.TriggerOnMakeRootAgent(this);
1069
1070 m_scene.EventManager.OnRegionHeartbeatEnd += RegionHeartbeatEnd;
922 } 1071 }
923 1072
924 public int GetStateSource() 1073 public int GetStateSource()
@@ -946,12 +1095,16 @@ namespace OpenSim.Region.Framework.Scenes
946 /// </remarks> 1095 /// </remarks>
947 public void MakeChildAgent() 1096 public void MakeChildAgent()
948 { 1097 {
1098 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
1099
949 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); 1100 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName);
950 1101
951 // Reset these so that teleporting in and walking out isn't seen 1102 // Reset these so that teleporting in and walking out isn't seen
952 // as teleporting back 1103 // as teleporting back
953 TeleportFlags = TeleportFlags.Default; 1104 TeleportFlags = TeleportFlags.Default;
954 1105
1106 MovementFlag = 0;
1107
955 // It looks like Animator is set to null somewhere, and MakeChild 1108 // It looks like Animator is set to null somewhere, and MakeChild
956 // is called after that. Probably in aborted teleports. 1109 // is called after that. Probably in aborted teleports.
957 if (Animator == null) 1110 if (Animator == null)
@@ -959,6 +1112,7 @@ namespace OpenSim.Region.Framework.Scenes
959 else 1112 else
960 Animator.ResetAnimations(); 1113 Animator.ResetAnimations();
961 1114
1115
962// m_log.DebugFormat( 1116// m_log.DebugFormat(
963// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", 1117// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
964// Name, UUID, m_scene.RegionInfo.RegionName); 1118// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -970,6 +1124,7 @@ namespace OpenSim.Region.Framework.Scenes
970 IsChildAgent = true; 1124 IsChildAgent = true;
971 m_scene.SwapRootAgentCount(true); 1125 m_scene.SwapRootAgentCount(true);
972 RemoveFromPhysicalScene(); 1126 RemoveFromPhysicalScene();
1127 ParentID = 0; // Child agents can't be sitting
973 1128
974 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into 1129 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into
975 1130
@@ -985,9 +1140,9 @@ namespace OpenSim.Region.Framework.Scenes
985 { 1140 {
986// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1141// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
987 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall; 1142 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall;
988 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
989 PhysicsActor.UnSubscribeEvents();
990 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1143 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
1144 PhysicsActor.UnSubscribeEvents();
1145 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
991 PhysicsActor = null; 1146 PhysicsActor = null;
992 } 1147 }
993// else 1148// else
@@ -1004,7 +1159,7 @@ namespace OpenSim.Region.Framework.Scenes
1004 /// <param name="pos"></param> 1159 /// <param name="pos"></param>
1005 public void Teleport(Vector3 pos) 1160 public void Teleport(Vector3 pos)
1006 { 1161 {
1007 TeleportWithMomentum(pos, null); 1162 TeleportWithMomentum(pos, Vector3.Zero);
1008 } 1163 }
1009 1164
1010 public void TeleportWithMomentum(Vector3 pos, Vector3? v) 1165 public void TeleportWithMomentum(Vector3 pos, Vector3? v)
@@ -1028,6 +1183,41 @@ namespace OpenSim.Region.Framework.Scenes
1028 SendTerseUpdateToAllClients(); 1183 SendTerseUpdateToAllClients();
1029 } 1184 }
1030 1185
1186 public void avnLocalTeleport(Vector3 newpos, Vector3? newvel, bool rotateToVelXY)
1187 {
1188 CheckLandingPoint(ref newpos);
1189 AbsolutePosition = newpos;
1190
1191 if (newvel.HasValue)
1192 {
1193 if ((Vector3)newvel == Vector3.Zero)
1194 {
1195 if (PhysicsActor != null)
1196 PhysicsActor.SetMomentum(Vector3.Zero);
1197 m_velocity = Vector3.Zero;
1198 }
1199 else
1200 {
1201 if (PhysicsActor != null)
1202 PhysicsActor.SetMomentum((Vector3)newvel);
1203 m_velocity = (Vector3)newvel;
1204
1205 if (rotateToVelXY)
1206 {
1207 Vector3 lookAt = (Vector3)newvel;
1208 lookAt.Z = 0;
1209 lookAt.Normalize();
1210 ControllingClient.SendLocalTeleport(newpos, lookAt, (uint)TeleportFlags.ViaLocation);
1211 return;
1212 }
1213 }
1214 }
1215
1216 SendTerseUpdateToAllClients();
1217 }
1218
1219
1220
1031 public void StopFlying() 1221 public void StopFlying()
1032 { 1222 {
1033 ControllingClient.StopFlying(this); 1223 ControllingClient.StopFlying(this);
@@ -1118,6 +1308,13 @@ namespace OpenSim.Region.Framework.Scenes
1118 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height); 1308 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height);
1119 } 1309 }
1120 1310
1311 public void SetSize(Vector3 size, float feetoffset)
1312 {
1313 if (PhysicsActor != null && !IsChildAgent)
1314 PhysicsActor.setAvatarSize(size, feetoffset);
1315
1316 }
1317
1121 /// <summary> 1318 /// <summary>
1122 /// Complete Avatar's movement into the region. 1319 /// Complete Avatar's movement into the region.
1123 /// </summary> 1320 /// </summary>
@@ -1137,7 +1334,8 @@ namespace OpenSim.Region.Framework.Scenes
1137 1334
1138 Vector3 look = Velocity; 1335 Vector3 look = Velocity;
1139 1336
1140 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) 1337 // if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
1338 if ((Math.Abs(look.X) < 0.1) && (Math.Abs(look.Y) < 0.1) && (Math.Abs(look.Z) < 0.1))
1141 { 1339 {
1142 look = new Vector3(0.99f, 0.042f, 0); 1340 look = new Vector3(0.99f, 0.042f, 0);
1143 } 1341 }
@@ -1187,13 +1385,15 @@ namespace OpenSim.Region.Framework.Scenes
1187 // Create child agents in neighbouring regions 1385 // Create child agents in neighbouring regions
1188 if (openChildAgents && !IsChildAgent) 1386 if (openChildAgents && !IsChildAgent)
1189 { 1387 {
1388
1190 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); 1389 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
1191 if (m_agentTransfer != null) 1390 if (m_agentTransfer != null)
1192 Util.FireAndForget(delegate { m_agentTransfer.EnableChildAgents(this); }); 1391 m_agentTransfer.EnableChildAgents(this);
1193 1392
1194 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); 1393 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
1195 if (friendsModule != null) 1394 if (friendsModule != null)
1196 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); 1395 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient);
1396
1197 } 1397 }
1198 1398
1199// m_log.DebugFormat( 1399// m_log.DebugFormat(
@@ -1209,35 +1409,43 @@ namespace OpenSim.Region.Framework.Scenes
1209 /// <param name="collisionPoint"></param> 1409 /// <param name="collisionPoint"></param>
1210 /// <param name="localid"></param> 1410 /// <param name="localid"></param>
1211 /// <param name="distance"></param> 1411 /// <param name="distance"></param>
1412 ///
1413
1414 private void UpdateCameraCollisionPlane(Vector4 plane)
1415 {
1416 if (m_lastCameraCollisionPlane != plane)
1417 {
1418 m_lastCameraCollisionPlane = plane;
1419 ControllingClient.SendCameraConstraint(plane);
1420 }
1421 }
1422
1212 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) 1423 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal)
1213 { 1424 {
1214 const float POSITION_TOLERANCE = 0.02f; 1425 const float POSITION_TOLERANCE = 0.02f;
1215 const float VELOCITY_TOLERANCE = 0.02f;
1216 const float ROTATION_TOLERANCE = 0.02f; 1426 const float ROTATION_TOLERANCE = 0.02f;
1217 1427
1218 if (m_followCamAuto) 1428 m_doingCamRayCast = false;
1429 if (hitYN && localid != LocalId)
1219 { 1430 {
1220 if (hitYN) 1431 CameraConstraintActive = true;
1221 { 1432 pNormal.X = (float)Math.Round(pNormal.X, 2);
1222 CameraConstraintActive = true; 1433 pNormal.Y = (float)Math.Round(pNormal.Y, 2);
1223 //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); 1434 pNormal.Z = (float)Math.Round(pNormal.Z, 2);
1224 1435 pNormal.Normalize();
1225 Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); 1436 collisionPoint.X = (float)Math.Round(collisionPoint.X, 1);
1226 ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); 1437 collisionPoint.Y = (float)Math.Round(collisionPoint.Y, 1);
1227 } 1438 collisionPoint.Z = (float)Math.Round(collisionPoint.Z, 1);
1228 else 1439
1229 { 1440 Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z, Vector3.Dot(collisionPoint, pNormal));
1230 if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || 1441 UpdateCameraCollisionPlane(plane);
1231 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || 1442 }
1232 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) 1443 else if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
1233 { 1444 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE))
1234 if (CameraConstraintActive) 1445 {
1235 { 1446 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -9000f); // not right...
1236 ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); 1447 UpdateCameraCollisionPlane(plane);
1237 CameraConstraintActive = false; 1448 CameraConstraintActive = false;
1238 }
1239 }
1240 }
1241 } 1449 }
1242 } 1450 }
1243 1451
@@ -1312,12 +1520,6 @@ namespace OpenSim.Region.Framework.Scenes
1312 // DrawDistance = agentData.Far; 1520 // DrawDistance = agentData.Far;
1313 DrawDistance = Scene.DefaultDrawDistance; 1521 DrawDistance = Scene.DefaultDrawDistance;
1314 1522
1315 // Check if Client has camera in 'follow cam' or 'build' mode.
1316 Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation);
1317
1318 m_followCamAuto = ((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.98f)
1319 && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false;
1320
1321 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; 1523 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0;
1322 m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; 1524 m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0;
1323 1525
@@ -1337,14 +1539,38 @@ namespace OpenSim.Region.Framework.Scenes
1337 StandUp(); 1539 StandUp();
1338 } 1540 }
1339 1541
1340 //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto);
1341 // Raycast from the avatar's head to the camera to see if there's anything blocking the view 1542 // Raycast from the avatar's head to the camera to see if there's anything blocking the view
1342 if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) 1543 // this exclude checks may not be complete
1544
1545 if (m_movementUpdateCount % NumMovementsBetweenRayCast == 0 && m_scene.PhysicsScene.SupportsRayCast())
1343 { 1546 {
1344 if (m_followCamAuto) 1547 if (!m_doingCamRayCast && !m_mouseLook && ParentID == 0)
1548 {
1549 Vector3 posAdjusted = AbsolutePosition;
1550// posAdjusted.Z += 0.5f * Appearance.AvatarSize.Z - 0.5f;
1551 posAdjusted.Z += 1.0f; // viewer current camera focus point
1552 Vector3 tocam = CameraPosition - posAdjusted;
1553 tocam.X = (float)Math.Round(tocam.X, 1);
1554 tocam.Y = (float)Math.Round(tocam.Y, 1);
1555 tocam.Z = (float)Math.Round(tocam.Z, 1);
1556
1557 float distTocamlen = tocam.Length();
1558 if (distTocamlen > 0.3f)
1559 {
1560 tocam *= (1.0f / distTocamlen);
1561 posAdjusted.X = (float)Math.Round(posAdjusted.X, 1);
1562 posAdjusted.Y = (float)Math.Round(posAdjusted.Y, 1);
1563 posAdjusted.Z = (float)Math.Round(posAdjusted.Z, 1);
1564
1565 m_doingCamRayCast = true;
1566 m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback);
1567 }
1568 }
1569 else if (CameraConstraintActive && (m_mouseLook || ParentID != 0))
1345 { 1570 {
1346 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; 1571 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right...
1347 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); 1572 UpdateCameraCollisionPlane(plane);
1573 CameraConstraintActive = false;
1348 } 1574 }
1349 } 1575 }
1350 1576
@@ -1782,7 +2008,8 @@ namespace OpenSim.Region.Framework.Scenes
1782// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name); 2008// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name);
1783 2009
1784 MovingToTarget = false; 2010 MovingToTarget = false;
1785 MoveToPositionTarget = Vector3.Zero; 2011// MoveToPositionTarget = Vector3.Zero;
2012 m_forceToApply = null; // cancel possible last action
1786 2013
1787 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct 2014 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct
1788 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag. 2015 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag.
@@ -1800,12 +2027,17 @@ namespace OpenSim.Region.Framework.Scenes
1800// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); 2027// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name);
1801 2028
1802 SitGround = false; 2029 SitGround = false;
2030
2031/* move this down so avatar gets physical in the new position and not where it is siting
1803 if (PhysicsActor == null) 2032 if (PhysicsActor == null)
1804 AddToPhysicalScene(false); 2033 AddToPhysicalScene(false);
2034 */
1805 2035
1806 if (ParentID != 0) 2036 if (ParentID != 0)
1807 { 2037 {
1808 SceneObjectPart part = ParentPart; 2038 SceneObjectPart part = ParentPart;
2039 UnRegisterSeatControls(part.ParentGroup.UUID);
2040
1809 TaskInventoryDictionary taskIDict = part.TaskInventory; 2041 TaskInventoryDictionary taskIDict = part.TaskInventory;
1810 if (taskIDict != null) 2042 if (taskIDict != null)
1811 { 2043 {
@@ -1821,14 +2053,22 @@ namespace OpenSim.Region.Framework.Scenes
1821 } 2053 }
1822 } 2054 }
1823 2055
1824 ParentPosition = part.GetWorldPosition(); 2056 part.ParentGroup.DeleteAvatar(UUID);
2057// ParentPosition = part.GetWorldPosition();
1825 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 2058 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1826 2059
1827 m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight); 2060// m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
1828 ParentPosition = Vector3.Zero; 2061// ParentPosition = Vector3.Zero;
2062 m_pos = part.AbsolutePosition + (m_pos * part.GetWorldRotation()) + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
2063 if (part.SitTargetAvatar == UUID)
2064 m_bodyRot = part.GetWorldRotation() * part.SitTargetOrientation;
1829 2065
1830 ParentID = 0; 2066 ParentID = 0;
1831 ParentPart = null; 2067 ParentPart = null;
2068
2069 if (PhysicsActor == null)
2070 AddToPhysicalScene(false);
2071
1832 SendAvatarDataToAllAgents(); 2072 SendAvatarDataToAllAgents();
1833 m_requestedSitTargetID = 0; 2073 m_requestedSitTargetID = 0;
1834 2074
@@ -1838,6 +2078,9 @@ namespace OpenSim.Region.Framework.Scenes
1838 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 2078 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
1839 } 2079 }
1840 2080
2081 else if (PhysicsActor == null)
2082 AddToPhysicalScene(false);
2083
1841 Animator.TrySetMovementAnimation("STAND"); 2084 Animator.TrySetMovementAnimation("STAND");
1842 } 2085 }
1843 2086
@@ -1885,11 +2128,8 @@ namespace OpenSim.Region.Framework.Scenes
1885 if (part == null) 2128 if (part == null)
1886 return; 2129 return;
1887 2130
1888 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1889 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1890
1891 if (PhysicsActor != null) 2131 if (PhysicsActor != null)
1892 m_sitAvatarHeight = PhysicsActor.Size.Z; 2132 m_sitAvatarHeight = PhysicsActor.Size.Z * 0.5f;
1893 2133
1894 bool canSit = false; 2134 bool canSit = false;
1895 Vector3 pos = part.AbsolutePosition + offset; 2135 Vector3 pos = part.AbsolutePosition + offset;
@@ -1906,31 +2146,31 @@ namespace OpenSim.Region.Framework.Scenes
1906 } 2146 }
1907 else 2147 else
1908 { 2148 {
2149 if (PhysicsSit(part,offset)) // physics engine
2150 return;
2151
1909 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10) 2152 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10)
1910 { 2153 {
1911// m_log.DebugFormat(
1912// "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is unset and within 10m",
1913// Name, part.Name, part.LocalId);
1914 2154
1915 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 2155 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
1916 canSit = true; 2156 canSit = true;
1917 } 2157 }
1918// else
1919// {
1920// m_log.DebugFormat(
1921// "[SCENE PRESENCE]: Ignoring sit request of {0} on {1} {2} because sit target is unset and outside 10m",
1922// Name, part.Name, part.LocalId);
1923// }
1924 } 2158 }
1925 2159
1926 if (canSit) 2160 if (canSit)
1927 { 2161 {
2162
1928 if (PhysicsActor != null) 2163 if (PhysicsActor != null)
1929 { 2164 {
1930 // We can remove the physicsActor until they stand up. 2165 // We can remove the physicsActor until they stand up.
1931 RemoveFromPhysicalScene(); 2166 RemoveFromPhysicalScene();
1932 } 2167 }
1933 2168
2169 if (MovingToTarget)
2170 ResetMoveToTarget();
2171
2172 Velocity = Vector3.Zero;
2173
1934 part.AddSittingAvatar(UUID); 2174 part.AddSittingAvatar(UUID);
1935 2175
1936 cameraAtOffset = part.GetCameraAtOffset(); 2176 cameraAtOffset = part.GetCameraAtOffset();
@@ -1938,7 +2178,7 @@ namespace OpenSim.Region.Framework.Scenes
1938 forceMouselook = part.GetForceMouselook(); 2178 forceMouselook = part.GetForceMouselook();
1939 2179
1940 ControllingClient.SendSitResponse( 2180 ControllingClient.SendSitResponse(
1941 targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 2181 part.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
1942 2182
1943 m_requestedSitTargetUUID = targetID; 2183 m_requestedSitTargetUUID = targetID;
1944 2184
@@ -1952,6 +2192,9 @@ namespace OpenSim.Region.Framework.Scenes
1952 2192
1953 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) 2193 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset)
1954 { 2194 {
2195 if (IsChildAgent)
2196 return;
2197
1955 if (ParentID != 0) 2198 if (ParentID != 0)
1956 { 2199 {
1957 StandUp(); 2200 StandUp();
@@ -1964,14 +2207,6 @@ namespace OpenSim.Region.Framework.Scenes
1964 m_requestedSitTargetID = part.LocalId; 2207 m_requestedSitTargetID = part.LocalId;
1965 m_requestedSitTargetUUID = targetID; 2208 m_requestedSitTargetUUID = targetID;
1966 2209
1967// m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset);
1968
1969 if (m_scene.PhysicsScene.SupportsRayCast())
1970 {
1971 //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback());
1972 //SitRayCastAvatarPosition(part);
1973 //return;
1974 }
1975 } 2210 }
1976 else 2211 else
1977 { 2212 {
@@ -1981,197 +2216,111 @@ namespace OpenSim.Region.Framework.Scenes
1981 SendSitResponse(targetID, offset, Quaternion.Identity); 2216 SendSitResponse(targetID, offset, Quaternion.Identity);
1982 } 2217 }
1983 2218
1984 /* 2219 // returns false if does not suport so older sit can be tried
1985 public void SitRayCastAvatarPosition(SceneObjectPart part) 2220 public bool PhysicsSit(SceneObjectPart part, Vector3 offset)
1986 { 2221 {
1987 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2222 if (part == null || part.ParentGroup.IsAttachment)
1988 Vector3 StartRayCastPosition = AbsolutePosition;
1989 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
1990 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
1991 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionResponse);
1992 }
1993
1994 public void SitRayCastAvatarPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal)
1995 {
1996 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
1997 if (part != null)
1998 {
1999 if (hitYN)
2000 {
2001 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2002 {
2003 SitRaycastFindEdge(collisionPoint, normal);
2004 m_log.DebugFormat("[SIT]: Raycast Avatar Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2005 }
2006 else
2007 {
2008 SitRayCastAvatarPositionCameraZ(part);
2009 }
2010 }
2011 else
2012 {
2013 SitRayCastAvatarPositionCameraZ(part);
2014 }
2015 }
2016 else
2017 { 2223 {
2018 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2224 return true;
2019 m_requestedSitTargetUUID = UUID.Zero;
2020 m_requestedSitTargetID = 0;
2021 m_requestedSitOffset = Vector3.Zero;
2022 } 2225 }
2023 2226
2024 } 2227 if ( m_scene.PhysicsScene == null)
2025 2228 return false;
2026 public void SitRayCastAvatarPositionCameraZ(SceneObjectPart part)
2027 {
2028 // Next, try to raycast from the camera Z position
2029 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2030 Vector3 StartRayCastPosition = AbsolutePosition; StartRayCastPosition.Z = CameraPosition.Z;
2031 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2032 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2033 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionCameraZResponse);
2034 }
2035 2229
2036 public void SitRayCastAvatarPositionCameraZResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2230 if (part.PhysActor == null)
2037 {
2038 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2039 if (part != null)
2040 { 2231 {
2041 if (hitYN) 2232 // none physcis shape
2042 { 2233 if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
2043 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) 2234 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2044 {
2045 SitRaycastFindEdge(collisionPoint, normal);
2046 m_log.DebugFormat("[SIT]: Raycast Avatar Position + CameraZ succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2047 }
2048 else
2049 {
2050 SitRayCastCameraPosition(part);
2051 }
2052 }
2053 else 2235 else
2054 { 2236 { // non physical phantom TODO
2055 SitRayCastCameraPosition(part); 2237 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2238 return false;
2056 } 2239 }
2057 } 2240 return true;
2058 else
2059 {
2060 ControllingClient.SendAlertMessage("Sit position no longer exists");
2061 m_requestedSitTargetUUID = UUID.Zero;
2062 m_requestedSitTargetID = 0;
2063 m_requestedSitOffset = Vector3.Zero;
2064 } 2241 }
2065 2242
2066 }
2067 2243
2068 public void SitRayCastCameraPosition(SceneObjectPart part) 2244 // not doing autopilot
2069 { 2245 m_requestedSitTargetID = 0;
2070 // Next, try to raycast from the camera position
2071 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2072 Vector3 StartRayCastPosition = CameraPosition;
2073 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2074 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2075 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastCameraPositionResponse);
2076 }
2077 2246
2078 public void SitRayCastCameraPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2247 if (m_scene.PhysicsScene.SitAvatar(part.PhysActor, AbsolutePosition, CameraPosition, offset, new Vector3(0.35f, 0, 0.65f), PhysicsSitResponse) != 0)
2079 { 2248 return true;
2080 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2081 if (part != null)
2082 {
2083 if (hitYN)
2084 {
2085 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2086 {
2087 SitRaycastFindEdge(collisionPoint, normal);
2088 m_log.DebugFormat("[SIT]: Raycast Camera Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2089 }
2090 else
2091 {
2092 SitRayHorizontal(part);
2093 }
2094 }
2095 else
2096 {
2097 SitRayHorizontal(part);
2098 }
2099 }
2100 else
2101 {
2102 ControllingClient.SendAlertMessage("Sit position no longer exists");
2103 m_requestedSitTargetUUID = UUID.Zero;
2104 m_requestedSitTargetID = 0;
2105 m_requestedSitOffset = Vector3.Zero;
2106 }
2107 2249
2250 return false;
2108 } 2251 }
2109 2252
2110 public void SitRayHorizontal(SceneObjectPart part) 2253
2254 private bool CanEnterLandPosition(Vector3 testPos)
2111 { 2255 {
2112 // Next, try to raycast from the avatar position to fwd 2256 ILandObject land = m_scene.LandChannel.GetLandObject(testPos.X, testPos.Y);
2113 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2257
2114 Vector3 StartRayCastPosition = CameraPosition; 2258 if (land == null || land.LandData.Name == "NO_LAND")
2115 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); 2259 return true;
2116 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); 2260
2117 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastHorizontalResponse); 2261 return land.CanBeOnThisLand(UUID,testPos.Z);
2118 } 2262 }
2119 2263
2120 public void SitRayCastHorizontalResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2264 // status
2265 // < 0 ignore
2266 // 0 bad sit spot
2267 public void PhysicsSitResponse(int status, uint partID, Vector3 offset, Quaternion Orientation)
2121 { 2268 {
2122 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); 2269 if (status < 0)
2123 if (part != null) 2270 return;
2271
2272 if (status == 0)
2124 { 2273 {
2125 if (hitYN) 2274 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2126 { 2275 return;
2127 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2128 {
2129 SitRaycastFindEdge(collisionPoint, normal);
2130 m_log.DebugFormat("[SIT]: Raycast Horizontal Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2131 // Next, try to raycast from the camera position
2132 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2133 Vector3 StartRayCastPosition = CameraPosition;
2134 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2135 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2136 //m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastResponseAvatarPosition);
2137 }
2138 else
2139 {
2140 ControllingClient.SendAlertMessage("Sit position not accessable.");
2141 m_requestedSitTargetUUID = UUID.Zero;
2142 m_requestedSitTargetID = 0;
2143 m_requestedSitOffset = Vector3.Zero;
2144 }
2145 }
2146 else
2147 {
2148 ControllingClient.SendAlertMessage("Sit position not accessable.");
2149 m_requestedSitTargetUUID = UUID.Zero;
2150 m_requestedSitTargetID = 0;
2151 m_requestedSitOffset = Vector3.Zero;
2152 }
2153 } 2276 }
2154 else 2277
2278 SceneObjectPart part = m_scene.GetSceneObjectPart(partID);
2279 if (part == null)
2280 return;
2281
2282 Vector3 targetPos = part.GetWorldPosition() + offset * part.GetWorldRotation();
2283 if(!CanEnterLandPosition(targetPos))
2155 { 2284 {
2156 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2285 ControllingClient.SendAlertMessage(" Sit position on restricted land, try another spot");
2157 m_requestedSitTargetUUID = UUID.Zero; 2286 return;
2158 m_requestedSitTargetID = 0;
2159 m_requestedSitOffset = Vector3.Zero;
2160 } 2287 }
2161 2288
2162 } 2289 RemoveFromPhysicalScene();
2163 2290
2164 private void SitRaycastFindEdge(Vector3 collisionPoint, Vector3 collisionNormal) 2291 if (MovingToTarget)
2165 { 2292 ResetMoveToTarget();
2166 int i = 0; 2293
2167 //throw new NotImplementedException(); 2294 Velocity = Vector3.Zero;
2168 //m_requestedSitTargetUUID = UUID.Zero; 2295
2169 //m_requestedSitTargetID = 0; 2296 part.AddSittingAvatar(UUID);
2170 //m_requestedSitOffset = Vector3.Zero;
2171 2297
2172 SendSitResponse(ControllingClient, m_requestedSitTargetUUID, collisionPoint - m_requestedSitOffset, Quaternion.Identity); 2298 Vector3 cameraAtOffset = part.GetCameraAtOffset();
2299 Vector3 cameraEyeOffset = part.GetCameraEyeOffset();
2300 bool forceMouselook = part.GetForceMouselook();
2301
2302 ControllingClient.SendSitResponse(
2303 part.UUID, offset, Orientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
2304
2305 // not using autopilot
2306
2307 Rotation = Orientation;
2308 m_pos = offset;
2309
2310 m_requestedSitTargetID = 0;
2311 part.ParentGroup.AddAvatar(UUID);
2312
2313 ParentPart = part;
2314 ParentID = part.LocalId;
2315 if(status == 3)
2316 Animator.TrySetMovementAnimation("SIT_GROUND");
2317 else
2318 Animator.TrySetMovementAnimation("SIT");
2319 SendAvatarDataToAllAgents();
2320
2321 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2173 } 2322 }
2174 */ 2323
2175 2324
2176 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) 2325 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID)
2177 { 2326 {
@@ -2188,6 +2337,7 @@ namespace OpenSim.Region.Framework.Scenes
2188 return; 2337 return;
2189 } 2338 }
2190 2339
2340
2191 if (part.SitTargetAvatar == UUID) 2341 if (part.SitTargetAvatar == UUID)
2192 { 2342 {
2193 Vector3 sitTargetPos = part.SitTargetPosition; 2343 Vector3 sitTargetPos = part.SitTargetPosition;
@@ -2202,14 +2352,39 @@ namespace OpenSim.Region.Framework.Scenes
2202 2352
2203 //Quaternion result = (sitTargetOrient * vq) * nq; 2353 //Quaternion result = (sitTargetOrient * vq) * nq;
2204 2354
2205 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2355 double x, y, z, m;
2356
2357 Quaternion r = sitTargetOrient;
2358 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2359
2360 if (Math.Abs(1.0 - m) > 0.000001)
2361 {
2362 m = 1.0 / Math.Sqrt(m);
2363 r.X *= (float)m;
2364 r.Y *= (float)m;
2365 r.Z *= (float)m;
2366 r.W *= (float)m;
2367 }
2368
2369 x = 2 * (r.X * r.Z + r.Y * r.W);
2370 y = 2 * (-r.X * r.W + r.Y * r.Z);
2371 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2372
2373 Vector3 up = new Vector3((float)x, (float)y, (float)z);
2374 Vector3 sitOffset = up * Appearance.AvatarHeight * 0.02638f;
2375
2376 m_pos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT;
2377
2378// m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT - sitOffset;
2206 Rotation = sitTargetOrient; 2379 Rotation = sitTargetOrient;
2207 ParentPosition = part.AbsolutePosition; 2380// ParentPosition = part.AbsolutePosition;
2381 part.ParentGroup.AddAvatar(UUID);
2208 } 2382 }
2209 else 2383 else
2210 { 2384 {
2211 m_pos -= part.AbsolutePosition; 2385 m_pos -= part.AbsolutePosition;
2212 ParentPosition = part.AbsolutePosition; 2386// ParentPosition = part.AbsolutePosition;
2387 part.ParentGroup.AddAvatar(UUID);
2213 2388
2214// m_log.DebugFormat( 2389// m_log.DebugFormat(
2215// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2390// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -2259,6 +2434,13 @@ namespace OpenSim.Region.Framework.Scenes
2259 Animator.RemoveAnimation(animID); 2434 Animator.RemoveAnimation(animID);
2260 } 2435 }
2261 2436
2437 public void avnHandleChangeAnim(UUID animID, bool addRemove,bool sendPack)
2438 {
2439 Animator.avnChangeAnim(animID, addRemove, sendPack);
2440 }
2441
2442
2443
2262 /// <summary> 2444 /// <summary>
2263 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector 2445 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
2264 /// </summary> 2446 /// </summary>
@@ -2312,14 +2494,15 @@ namespace OpenSim.Region.Framework.Scenes
2312 direc.Z *= 2.6f; 2494 direc.Z *= 2.6f;
2313 2495
2314 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2496 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
2315 Animator.TrySetMovementAnimation("PREJUMP"); 2497// Animator.TrySetMovementAnimation("PREJUMP");
2316 Animator.TrySetMovementAnimation("JUMP"); 2498// Animator.TrySetMovementAnimation("JUMP");
2317 } 2499 }
2318 } 2500 }
2319 } 2501 }
2320 2502
2321 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2503 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2322 m_forceToApply = direc; 2504 m_forceToApply = direc;
2505 Animator.UpdateMovementAnimations();
2323 } 2506 }
2324 2507
2325 #endregion 2508 #endregion
@@ -2337,16 +2520,12 @@ namespace OpenSim.Region.Framework.Scenes
2337 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to 2520 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to
2338 // grab the latest PhysicsActor velocity, whereas m_velocity is often 2521 // grab the latest PhysicsActor velocity, whereas m_velocity is often
2339 // storing a requested force instead of an actual traveling velocity 2522 // storing a requested force instead of an actual traveling velocity
2523 if (Appearance.AvatarSize != m_lastSize && !IsLoggingIn)
2524 SendAvatarDataToAllAgents();
2340 2525
2341 // Throw away duplicate or insignificant updates 2526 if (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||
2342 if ( 2527 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
2343 // If the velocity has become zero, send it no matter what. 2528 !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))
2344 (Velocity != m_lastVelocity && Velocity == Vector3.Zero)
2345 // otherwise, if things have changed reasonably, send the update
2346 || (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)
2347 || !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE)
2348 || !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)))
2349
2350 { 2529 {
2351 SendTerseUpdateToAllClients(); 2530 SendTerseUpdateToAllClients();
2352 2531
@@ -2535,6 +2714,8 @@ namespace OpenSim.Region.Framework.Scenes
2535 return; 2714 return;
2536 } 2715 }
2537 2716
2717 m_lastSize = Appearance.AvatarSize;
2718
2538 int count = 0; 2719 int count = 0;
2539 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) 2720 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
2540 { 2721 {
@@ -2642,6 +2823,8 @@ namespace OpenSim.Region.Framework.Scenes
2642 2823
2643 avatar.ControllingClient.SendAppearance( 2824 avatar.ControllingClient.SendAppearance(
2644 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes()); 2825 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes());
2826
2827
2645 } 2828 }
2646 2829
2647 #endregion 2830 #endregion
@@ -2716,8 +2899,9 @@ namespace OpenSim.Region.Framework.Scenes
2716 2899
2717 // If we don't have a PhysActor, we can't cross anyway 2900 // If we don't have a PhysActor, we can't cross anyway
2718 // Also don't do this while sat, sitting avatars cross with the 2901 // Also don't do this while sat, sitting avatars cross with the
2719 // object they sit on. 2902 // object they sit on. ParentUUID denoted a pending sit, don't
2720 if (ParentID != 0 || PhysicsActor == null) 2903 // interfere with it.
2904 if (ParentID != 0 || PhysicsActor == null || ParentUUID != UUID.Zero)
2721 return; 2905 return;
2722 2906
2723 if (!IsInTransit) 2907 if (!IsInTransit)
@@ -2978,6 +3162,10 @@ namespace OpenSim.Region.Framework.Scenes
2978 } 3162 }
2979 3163
2980 private static Vector3 marker = new Vector3(-1f, -1f, -1f); 3164 private static Vector3 marker = new Vector3(-1f, -1f, -1f);
3165 private void RaiseUpdateThrottles()
3166 {
3167 m_scene.EventManager.TriggerThrottleUpdate(this);
3168 }
2981 /// <summary> 3169 /// <summary>
2982 /// This updates important decision making data about a child agent 3170 /// This updates important decision making data about a child agent
2983 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region 3171 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region
@@ -3058,6 +3246,9 @@ namespace OpenSim.Region.Framework.Scenes
3058 cAgent.AlwaysRun = SetAlwaysRun; 3246 cAgent.AlwaysRun = SetAlwaysRun;
3059 3247
3060 cAgent.Appearance = new AvatarAppearance(Appearance); 3248 cAgent.Appearance = new AvatarAppearance(Appearance);
3249
3250 cAgent.ParentPart = ParentUUID;
3251 cAgent.SitOffset = m_pos;
3061 3252
3062 lock (scriptedcontrols) 3253 lock (scriptedcontrols)
3063 { 3254 {
@@ -3066,7 +3257,7 @@ namespace OpenSim.Region.Framework.Scenes
3066 3257
3067 foreach (ScriptControllers c in scriptedcontrols.Values) 3258 foreach (ScriptControllers c in scriptedcontrols.Values)
3068 { 3259 {
3069 controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); 3260 controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
3070 } 3261 }
3071 cAgent.Controllers = controls; 3262 cAgent.Controllers = controls;
3072 } 3263 }
@@ -3099,6 +3290,8 @@ namespace OpenSim.Region.Framework.Scenes
3099 CameraAtAxis = cAgent.AtAxis; 3290 CameraAtAxis = cAgent.AtAxis;
3100 CameraLeftAxis = cAgent.LeftAxis; 3291 CameraLeftAxis = cAgent.LeftAxis;
3101 CameraUpAxis = cAgent.UpAxis; 3292 CameraUpAxis = cAgent.UpAxis;
3293 ParentUUID = cAgent.ParentPart;
3294 m_prevSitOffset = cAgent.SitOffset;
3102 3295
3103 // When we get to the point of re-computing neighbors everytime this 3296 // When we get to the point of re-computing neighbors everytime this
3104 // changes, then start using the agent's drawdistance rather than the 3297 // changes, then start using the agent's drawdistance rather than the
@@ -3136,6 +3329,7 @@ namespace OpenSim.Region.Framework.Scenes
3136 foreach (ControllerData c in cAgent.Controllers) 3329 foreach (ControllerData c in cAgent.Controllers)
3137 { 3330 {
3138 ScriptControllers sc = new ScriptControllers(); 3331 ScriptControllers sc = new ScriptControllers();
3332 sc.objectID = c.ObjectID;
3139 sc.itemID = c.ItemID; 3333 sc.itemID = c.ItemID;
3140 sc.ignoreControls = (ScriptControlled)c.IgnoreControls; 3334 sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
3141 sc.eventControls = (ScriptControlled)c.EventControls; 3335 sc.eventControls = (ScriptControlled)c.EventControls;
@@ -3203,20 +3397,27 @@ namespace OpenSim.Region.Framework.Scenes
3203 } 3397 }
3204 3398
3205 if (Appearance.AvatarHeight == 0) 3399 if (Appearance.AvatarHeight == 0)
3206 Appearance.SetHeight(); 3400// Appearance.SetHeight();
3401 Appearance.SetSize(new Vector3(0.45f,0.6f,1.9f));
3207 3402
3208 PhysicsScene scene = m_scene.PhysicsScene; 3403 PhysicsScene scene = m_scene.PhysicsScene;
3209 3404
3210 Vector3 pVec = AbsolutePosition; 3405 Vector3 pVec = AbsolutePosition;
3211 3406
3407/*
3212 PhysicsActor = scene.AddAvatar( 3408 PhysicsActor = scene.AddAvatar(
3213 LocalId, Firstname + "." + Lastname, pVec, 3409 LocalId, Firstname + "." + Lastname, pVec,
3214 new Vector3(0f, 0f, Appearance.AvatarHeight), isFlying); 3410 new Vector3(0.45f, 0.6f, Appearance.AvatarHeight), isFlying);
3411*/
3412
3413 PhysicsActor = scene.AddAvatar(
3414 LocalId, Firstname + "." + Lastname, pVec,
3415 Appearance.AvatarBoxSize,Appearance.AvatarFeetOffset, isFlying);
3215 3416
3216 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3417 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3217 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3418 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
3218 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong 3419 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
3219 PhysicsActor.SubscribeEvents(500); 3420 PhysicsActor.SubscribeEvents(100);
3220 PhysicsActor.LocalID = LocalId; 3421 PhysicsActor.LocalID = LocalId;
3221 } 3422 }
3222 3423
@@ -3230,6 +3431,7 @@ namespace OpenSim.Region.Framework.Scenes
3230 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); 3431 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true);
3231 } 3432 }
3232 3433
3434
3233 /// <summary> 3435 /// <summary>
3234 /// Event called by the physics plugin to tell the avatar about a collision. 3436 /// Event called by the physics plugin to tell the avatar about a collision.
3235 /// </summary> 3437 /// </summary>
@@ -3243,7 +3445,7 @@ namespace OpenSim.Region.Framework.Scenes
3243 /// <param name="e"></param> 3445 /// <param name="e"></param>
3244 public void PhysicsCollisionUpdate(EventArgs e) 3446 public void PhysicsCollisionUpdate(EventArgs e)
3245 { 3447 {
3246 if (IsChildAgent) 3448 if (IsChildAgent || Animator == null)
3247 return; 3449 return;
3248 3450
3249 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3451 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
@@ -3259,7 +3461,6 @@ namespace OpenSim.Region.Framework.Scenes
3259 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3461 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3260 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3462 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3261 3463
3262 CollisionPlane = Vector4.UnitW;
3263 3464
3264// // No collisions at all means we may be flying. Update always 3465// // No collisions at all means we may be flying. Update always
3265// // to make falling work 3466// // to make falling work
@@ -3271,6 +3472,7 @@ namespace OpenSim.Region.Framework.Scenes
3271 3472
3272 if (coldata.Count != 0) 3473 if (coldata.Count != 0)
3273 { 3474 {
3475/*
3274 switch (Animator.CurrentMovementAnimation) 3476 switch (Animator.CurrentMovementAnimation)
3275 { 3477 {
3276 case "STAND": 3478 case "STAND":
@@ -3279,24 +3481,38 @@ namespace OpenSim.Region.Framework.Scenes
3279 case "CROUCH": 3481 case "CROUCH":
3280 case "CROUCHWALK": 3482 case "CROUCHWALK":
3281 { 3483 {
3484 */
3282 ContactPoint lowest; 3485 ContactPoint lowest;
3283 lowest.SurfaceNormal = Vector3.Zero; 3486 lowest.SurfaceNormal = Vector3.Zero;
3284 lowest.Position = Vector3.Zero; 3487 lowest.Position = Vector3.Zero;
3285 lowest.Position.Z = Single.NaN; 3488 lowest.Position.Z = float.MaxValue;
3286 3489
3287 foreach (ContactPoint contact in coldata.Values) 3490 foreach (ContactPoint contact in coldata.Values)
3288 { 3491 {
3289 if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z) 3492
3493 if (contact.CharacterFeet && contact.Position.Z < lowest.Position.Z)
3290 { 3494 {
3291 lowest = contact; 3495 lowest = contact;
3292 } 3496 }
3293 } 3497 }
3294 3498
3295 CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal)); 3499 if (lowest.Position.Z != float.MaxValue)
3500 {
3501 lowest.SurfaceNormal = -lowest.SurfaceNormal;
3502 CollisionPlane = new Vector4(lowest.SurfaceNormal, Vector3.Dot(lowest.Position, lowest.SurfaceNormal));
3503 }
3504 else
3505 CollisionPlane = Vector4.UnitW;
3506/*
3296 } 3507 }
3297 break; 3508 break;
3298 } 3509 }
3510*/
3299 } 3511 }
3512 else
3513 CollisionPlane = Vector4.UnitW;
3514
3515 RaiseCollisionScriptEvents(coldata);
3300 3516
3301 // Gods do not take damage and Invulnerable is set depending on parcel/region flags 3517 // Gods do not take damage and Invulnerable is set depending on parcel/region flags
3302 if (Invulnerable || GodLevel > 0) 3518 if (Invulnerable || GodLevel > 0)
@@ -3395,6 +3611,13 @@ namespace OpenSim.Region.Framework.Scenes
3395 // m_reprioritizationTimer.Dispose(); 3611 // m_reprioritizationTimer.Dispose();
3396 3612
3397 RemoveFromPhysicalScene(); 3613 RemoveFromPhysicalScene();
3614
3615 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
3616
3617// if (Animator != null)
3618// Animator.Close();
3619 Animator = null;
3620
3398 } 3621 }
3399 3622
3400 public void AddAttachment(SceneObjectGroup gobj) 3623 public void AddAttachment(SceneObjectGroup gobj)
@@ -3628,10 +3851,18 @@ namespace OpenSim.Region.Framework.Scenes
3628 3851
3629 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 3852 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
3630 { 3853 {
3854 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID);
3855 if (p == null)
3856 return;
3857
3858 ControllingClient.SendTakeControls(controls, false, false);
3859 ControllingClient.SendTakeControls(controls, true, false);
3860
3631 ScriptControllers obj = new ScriptControllers(); 3861 ScriptControllers obj = new ScriptControllers();
3632 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 3862 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
3633 obj.eventControls = ScriptControlled.CONTROL_ZERO; 3863 obj.eventControls = ScriptControlled.CONTROL_ZERO;
3634 3864
3865 obj.objectID = p.ParentGroup.UUID;
3635 obj.itemID = Script_item_UUID; 3866 obj.itemID = Script_item_UUID;
3636 if (pass_on == 0 && accept == 0) 3867 if (pass_on == 0 && accept == 0)
3637 { 3868 {
@@ -3680,6 +3911,21 @@ namespace OpenSim.Region.Framework.Scenes
3680 ControllingClient.SendTakeControls(int.MaxValue, false, false); 3911 ControllingClient.SendTakeControls(int.MaxValue, false, false);
3681 } 3912 }
3682 3913
3914 private void UnRegisterSeatControls(UUID obj)
3915 {
3916 List<UUID> takers = new List<UUID>();
3917
3918 foreach (ScriptControllers c in scriptedcontrols.Values)
3919 {
3920 if (c.objectID == obj)
3921 takers.Add(c.itemID);
3922 }
3923 foreach (UUID t in takers)
3924 {
3925 UnRegisterControlEventsToScript(0, t);
3926 }
3927 }
3928
3683 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 3929 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
3684 { 3930 {
3685 ScriptControllers takecontrols; 3931 ScriptControllers takecontrols;
@@ -3998,6 +4244,12 @@ namespace OpenSim.Region.Framework.Scenes
3998 4244
3999 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4245 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
4000 { 4246 {
4247 string reason;
4248
4249 // Honor bans
4250 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
4251 return;
4252
4001 SceneObjectGroup telehub = null; 4253 SceneObjectGroup telehub = null;
4002 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 4254 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
4003 { 4255 {
@@ -4037,11 +4289,206 @@ namespace OpenSim.Region.Framework.Scenes
4037 pos = land.LandData.UserLocation; 4289 pos = land.LandData.UserLocation;
4038 } 4290 }
4039 } 4291 }
4040 4292
4041 land.SendLandUpdateToClient(ControllingClient); 4293 land.SendLandUpdateToClient(ControllingClient);
4042 } 4294 }
4043 } 4295 }
4044 4296
4297 private DetectedObject CreateDetObject(SceneObjectPart obj)
4298 {
4299 DetectedObject detobj = new DetectedObject();
4300 detobj.keyUUID = obj.UUID;
4301 detobj.nameStr = obj.Name;
4302 detobj.ownerUUID = obj.OwnerID;
4303 detobj.posVector = obj.AbsolutePosition;
4304 detobj.rotQuat = obj.GetWorldRotation();
4305 detobj.velVector = obj.Velocity;
4306 detobj.colliderType = 0;
4307 detobj.groupUUID = obj.GroupID;
4308
4309 return detobj;
4310 }
4311
4312 private DetectedObject CreateDetObject(ScenePresence av)
4313 {
4314 DetectedObject detobj = new DetectedObject();
4315 detobj.keyUUID = av.UUID;
4316 detobj.nameStr = av.ControllingClient.Name;
4317 detobj.ownerUUID = av.UUID;
4318 detobj.posVector = av.AbsolutePosition;
4319 detobj.rotQuat = av.Rotation;
4320 detobj.velVector = av.Velocity;
4321 detobj.colliderType = 0;
4322 detobj.groupUUID = av.ControllingClient.ActiveGroupId;
4323
4324 return detobj;
4325 }
4326
4327 private DetectedObject CreateDetObjectForGround()
4328 {
4329 DetectedObject detobj = new DetectedObject();
4330 detobj.keyUUID = UUID.Zero;
4331 detobj.nameStr = "";
4332 detobj.ownerUUID = UUID.Zero;
4333 detobj.posVector = AbsolutePosition;
4334 detobj.rotQuat = Quaternion.Identity;
4335 detobj.velVector = Vector3.Zero;
4336 detobj.colliderType = 0;
4337 detobj.groupUUID = UUID.Zero;
4338
4339 return detobj;
4340 }
4341
4342 private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
4343 {
4344 ColliderArgs colliderArgs = new ColliderArgs();
4345 List<DetectedObject> colliding = new List<DetectedObject>();
4346 foreach (uint localId in colliders)
4347 {
4348 if (localId == 0)
4349 continue;
4350
4351 SceneObjectPart obj = m_scene.GetSceneObjectPart(localId);
4352 if (obj != null)
4353 {
4354 if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
4355 colliding.Add(CreateDetObject(obj));
4356 }
4357 else
4358 {
4359 ScenePresence av = m_scene.GetScenePresence(localId);
4360 if (av != null && (!av.IsChildAgent))
4361 {
4362 if (!dest.CollisionFilteredOut(av.UUID, av.Name))
4363 colliding.Add(CreateDetObject(av));
4364 }
4365 }
4366 }
4367
4368 colliderArgs.Colliders = colliding;
4369
4370 return colliderArgs;
4371 }
4372
4373 private delegate void ScriptCollidingNotification(uint localID, ColliderArgs message);
4374
4375 private void SendCollisionEvent(SceneObjectGroup dest, scriptEvents ev, List<uint> colliders, ScriptCollidingNotification notify)
4376 {
4377 ColliderArgs CollidingMessage;
4378
4379 if (colliders.Count > 0)
4380 {
4381 if ((dest.RootPart.ScriptEvents & ev) != 0)
4382 {
4383 CollidingMessage = CreateColliderArgs(dest.RootPart, colliders);
4384
4385 if (CollidingMessage.Colliders.Count > 0)
4386 notify(dest.RootPart.LocalId, CollidingMessage);
4387 }
4388 }
4389 }
4390
4391 private void SendLandCollisionEvent(SceneObjectGroup dest, scriptEvents ev, ScriptCollidingNotification notify)
4392 {
4393 if ((dest.RootPart.ScriptEvents & ev) != 0)
4394 {
4395 ColliderArgs LandCollidingMessage = new ColliderArgs();
4396 List<DetectedObject> colliding = new List<DetectedObject>();
4397
4398 colliding.Add(CreateDetObjectForGround());
4399 LandCollidingMessage.Colliders = colliding;
4400
4401 notify(dest.RootPart.LocalId, LandCollidingMessage);
4402 }
4403 }
4404
4405 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4406 {
4407 try
4408 {
4409 List<uint> thisHitColliders = new List<uint>();
4410 List<uint> endedColliders = new List<uint>();
4411 List<uint> startedColliders = new List<uint>();
4412 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
4413 CollisionForSoundInfo soundinfo;
4414 ContactPoint curcontact;
4415
4416 if (coldata.Count == 0)
4417 {
4418 if (m_lastColliders.Count == 0)
4419 return; // nothing to do
4420
4421 foreach (uint localID in m_lastColliders)
4422 {
4423 endedColliders.Add(localID);
4424 }
4425 m_lastColliders.Clear();
4426 }
4427
4428 else
4429 {
4430 foreach (uint id in coldata.Keys)
4431 {
4432 thisHitColliders.Add(id);
4433 if (!m_lastColliders.Contains(id))
4434 {
4435 startedColliders.Add(id);
4436 curcontact = coldata[id];
4437 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
4438 {
4439 soundinfo = new CollisionForSoundInfo();
4440 soundinfo.colliderID = id;
4441 soundinfo.position = curcontact.Position;
4442 soundinfo.relativeVel = curcontact.RelativeSpeed;
4443 soundinfolist.Add(soundinfo);
4444 }
4445 }
4446 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4447 }
4448
4449 // calculate things that ended colliding
4450 foreach (uint localID in m_lastColliders)
4451 {
4452 if (!thisHitColliders.Contains(localID))
4453 {
4454 endedColliders.Add(localID);
4455 }
4456 }
4457 //add the items that started colliding this time to the last colliders list.
4458 foreach (uint localID in startedColliders)
4459 {
4460 m_lastColliders.Add(localID);
4461 }
4462 // remove things that ended colliding from the last colliders list
4463 foreach (uint localID in endedColliders)
4464 {
4465 m_lastColliders.Remove(localID);
4466 }
4467
4468 if (soundinfolist.Count > 0)
4469 CollisionSounds.AvatarCollisionSound(this, soundinfolist);
4470 }
4471
4472 foreach (SceneObjectGroup att in GetAttachments())
4473 {
4474 SendCollisionEvent(att, scriptEvents.collision_start, startedColliders, m_scene.EventManager.TriggerScriptCollidingStart);
4475 SendCollisionEvent(att, scriptEvents.collision , m_lastColliders , m_scene.EventManager.TriggerScriptColliding);
4476 SendCollisionEvent(att, scriptEvents.collision_end , endedColliders , m_scene.EventManager.TriggerScriptCollidingEnd);
4477
4478 if (startedColliders.Contains(0))
4479 SendLandCollisionEvent(att, scriptEvents.land_collision_start, m_scene.EventManager.TriggerScriptLandCollidingStart);
4480 if (m_lastColliders.Contains(0))
4481 SendLandCollisionEvent(att, scriptEvents.land_collision, m_scene.EventManager.TriggerScriptLandColliding);
4482 if (endedColliders.Contains(0))
4483 SendLandCollisionEvent(att, scriptEvents.land_collision_end, m_scene.EventManager.TriggerScriptLandCollidingEnd);
4484 }
4485 }
4486 finally
4487 {
4488 m_collisionEventFlag = false;
4489 }
4490 }
4491
4045 private void TeleportFlagsDebug() { 4492 private void TeleportFlagsDebug() {
4046 4493
4047 // Some temporary debugging help to show all the TeleportFlags we have... 4494 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -4066,6 +4513,5 @@ namespace OpenSim.Region.Framework.Scenes
4066 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4513 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
4067 4514
4068 } 4515 }
4069
4070 } 4516 }
4071} 4517}