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.cs1074
1 files changed, 761 insertions, 313 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 39a885c..f2aa0c5 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
@@ -226,8 +230,6 @@ namespace OpenSim.Region.Framework.Scenes
226 /// </summary> 230 /// </summary>
227 public bool LandAtTarget { get; private set; } 231 public bool LandAtTarget { get; private set; }
228 232
229 private bool m_followCamAuto;
230
231 private int m_movementUpdateCount; 233 private int m_movementUpdateCount;
232 private const int NumMovementsBetweenRayCast = 5; 234 private const int NumMovementsBetweenRayCast = 5;
233 235
@@ -235,6 +237,13 @@ namespace OpenSim.Region.Framework.Scenes
235 //private int m_moveToPositionStateStatus; 237 //private int m_moveToPositionStateStatus;
236 //***************************************************** 238 //*****************************************************
237 239
240 private bool m_collisionEventFlag = false;
241 private object m_collisionEventLock = new Object();
242
243 private int m_movementAnimationUpdateCounter = 0;
244
245 private Vector3 m_prevSitOffset;
246
238 protected AvatarAppearance m_appearance; 247 protected AvatarAppearance m_appearance;
239 248
240 public AvatarAppearance Appearance 249 public AvatarAppearance Appearance
@@ -349,6 +358,9 @@ namespace OpenSim.Region.Framework.Scenes
349 /// </summary> 358 /// </summary>
350 protected Vector3 m_lastCameraPosition; 359 protected Vector3 m_lastCameraPosition;
351 360
361 private Vector4 m_lastCameraCollisionPlane = new Vector4(0f, 0f, 0f, 1);
362 private bool m_doingCamRayCast = false;
363
352 public Vector3 CameraPosition { get; set; } 364 public Vector3 CameraPosition { get; set; }
353 365
354 public Quaternion CameraRotation 366 public Quaternion CameraRotation
@@ -429,7 +441,9 @@ namespace OpenSim.Region.Framework.Scenes
429 get { return (IClientCore)ControllingClient; } 441 get { return (IClientCore)ControllingClient; }
430 } 442 }
431 443
432 public Vector3 ParentPosition { get; set; } 444 public UUID COF { get; set; }
445
446// public Vector3 ParentPosition { get; set; }
433 447
434 /// <summary> 448 /// <summary>
435 /// Position of this avatar relative to the region the avatar is in 449 /// Position of this avatar relative to the region the avatar is in
@@ -487,7 +501,7 @@ namespace OpenSim.Region.Framework.Scenes
487 if (ParentID == 0) 501 if (ParentID == 0)
488 { 502 {
489 m_pos = value; 503 m_pos = value;
490 ParentPosition = Vector3.Zero; 504// ParentPosition = Vector3.Zero;
491 } 505 }
492 506
493 //m_log.DebugFormat( 507 //m_log.DebugFormat(
@@ -556,7 +570,24 @@ namespace OpenSim.Region.Framework.Scenes
556// Scene.RegionInfo.RegionName, Name, m_velocity); 570// Scene.RegionInfo.RegionName, Name, m_velocity);
557 } 571 }
558 } 572 }
573/*
574 public override Vector3 AngularVelocity
575 {
576 get
577 {
578 if (PhysicsActor != null)
579 {
580 m_rotationalvelocity = PhysicsActor.RotationalVelocity;
559 581
582 // m_log.DebugFormat(
583 // "[SCENE PRESENCE]: Set velocity {0} for {1} in {2} via getting Velocity!",
584 // m_velocity, Name, Scene.RegionInfo.RegionName);
585 }
586
587 return m_rotationalvelocity;
588 }
589 }
590*/
560 private Quaternion m_bodyRot = Quaternion.Identity; 591 private Quaternion m_bodyRot = Quaternion.Identity;
561 592
562 public Quaternion Rotation 593 public Quaternion Rotation
@@ -567,7 +598,14 @@ namespace OpenSim.Region.Framework.Scenes
567 m_bodyRot = value; 598 m_bodyRot = value;
568 if (PhysicsActor != null) 599 if (PhysicsActor != null)
569 { 600 {
570 PhysicsActor.Orientation = m_bodyRot; 601 try
602 {
603 PhysicsActor.Orientation = m_bodyRot;
604 }
605 catch (Exception e)
606 {
607 m_log.Error("[SCENE PRESENCE]: Orientation " + e.Message);
608 }
571 } 609 }
572// m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot); 610// m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot);
573 } 611 }
@@ -582,12 +620,20 @@ namespace OpenSim.Region.Framework.Scenes
582 } 620 }
583 621
584 public bool IsChildAgent { get; set; } 622 public bool IsChildAgent { get; set; }
623 public bool IsLoggingIn { get; set; }
585 624
586 /// <summary> 625 /// <summary>
587 /// If the avatar is sitting, the local ID of the prim that it's sitting on. If not sitting then zero. 626 /// If the avatar is sitting, the local ID of the prim that it's sitting on. If not sitting then zero.
588 /// </summary> 627 /// </summary>
589 public uint ParentID { get; set; } 628 public uint ParentID { get; set; }
590 629
630 public UUID ParentUUID
631 {
632 get { return m_parentUUID; }
633 set { m_parentUUID = value; }
634 }
635 private UUID m_parentUUID = UUID.Zero;
636
591 /// <summary> 637 /// <summary>
592 /// Are we sitting on an object? 638 /// Are we sitting on an object?
593 /// </summary> 639 /// </summary>
@@ -719,6 +765,7 @@ namespace OpenSim.Region.Framework.Scenes
719 AttachmentsSyncLock = new Object(); 765 AttachmentsSyncLock = new Object();
720 AllowMovement = true; 766 AllowMovement = true;
721 IsChildAgent = true; 767 IsChildAgent = true;
768 IsLoggingIn = false;
722 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault; 769 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault;
723 Animator = new ScenePresenceAnimator(this); 770 Animator = new ScenePresenceAnimator(this);
724 PresenceType = type; 771 PresenceType = type;
@@ -762,6 +809,33 @@ namespace OpenSim.Region.Framework.Scenes
762 Appearance = appearance; 809 Appearance = appearance;
763 } 810 }
764 811
812 private void RegionHeartbeatEnd(Scene scene)
813 {
814 if (IsChildAgent)
815 return;
816
817 m_movementAnimationUpdateCounter ++;
818 if (m_movementAnimationUpdateCounter >= 2)
819 {
820 m_movementAnimationUpdateCounter = 0;
821 if (Animator != null)
822 {
823 // If the parentID == 0 we are not sitting
824 // if !SitGournd then we are not sitting on the ground
825 // Fairly straightforward, now here comes the twist
826 // if ParentUUID is NOT UUID.Zero, we are looking to
827 // be sat on an object that isn't there yet. Should
828 // be treated as if sat.
829 if(ParentID == 0 && !SitGround && ParentUUID == UUID.Zero) // skip it if sitting
830 Animator.UpdateMovementAnimations();
831 }
832 else
833 {
834 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
835 }
836 }
837 }
838
765 public void RegisterToEvents() 839 public void RegisterToEvents()
766 { 840 {
767 ControllingClient.OnCompleteMovementToRegion += CompleteMovement; 841 ControllingClient.OnCompleteMovementToRegion += CompleteMovement;
@@ -771,8 +845,10 @@ namespace OpenSim.Region.Framework.Scenes
771 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; 845 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
772 ControllingClient.OnStartAnim += HandleStartAnim; 846 ControllingClient.OnStartAnim += HandleStartAnim;
773 ControllingClient.OnStopAnim += HandleStopAnim; 847 ControllingClient.OnStopAnim += HandleStopAnim;
848 ControllingClient.OnChangeAnim += avnHandleChangeAnim;
774 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls; 849 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls;
775 ControllingClient.OnAutoPilotGo += MoveToTarget; 850 ControllingClient.OnAutoPilotGo += MoveToTarget;
851 ControllingClient.OnUpdateThrottles += RaiseUpdateThrottles;
776 852
777 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); 853 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
778 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); 854 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
@@ -831,10 +907,40 @@ namespace OpenSim.Region.Framework.Scenes
831 "[SCENE]: Upgrading child to root agent for {0} in {1}", 907 "[SCENE]: Upgrading child to root agent for {0} in {1}",
832 Name, m_scene.RegionInfo.RegionName); 908 Name, m_scene.RegionInfo.RegionName);
833 909
834 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
835
836 bool wasChild = IsChildAgent; 910 bool wasChild = IsChildAgent;
837 IsChildAgent = false; 911
912 if (ParentUUID != UUID.Zero)
913 {
914 m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID);
915 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID);
916 if (part == null)
917 {
918 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
919 }
920 else
921 {
922 part.ParentGroup.AddAvatar(UUID);
923 if (part.SitTargetPosition != Vector3.Zero)
924 part.SitTargetAvatar = UUID;
925// ParentPosition = part.GetWorldPosition();
926 ParentID = part.LocalId;
927 ParentPart = part;
928 m_pos = m_prevSitOffset;
929// pos = ParentPosition;
930 pos = part.GetWorldPosition();
931 }
932 ParentUUID = UUID.Zero;
933
934 IsChildAgent = false;
935
936// Animator.TrySetMovementAnimation("SIT");
937 }
938 else
939 {
940 IsChildAgent = false;
941 IsLoggingIn = false;
942 }
943
838 944
839 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 945 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
840 if (gm != null) 946 if (gm != null)
@@ -844,62 +950,99 @@ namespace OpenSim.Region.Framework.Scenes
844 950
845 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 951 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
846 952
847 // Moved this from SendInitialData to ensure that Appearance is initialized 953 UUID groupUUID = UUID.Zero;
848 // before the inventory is processed in MakeRootAgent. This fixes a race condition 954 string GroupName = string.Empty;
849 // related to the handling of attachments 955 ulong groupPowers = 0;
850 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance); 956
851 if (m_scene.TestBorderCross(pos, Cardinals.E)) 957 // ----------------------------------
958 // Previous Agent Difference - AGNI sends an unsolicited AgentDataUpdate upon root agent status
959 try
852 { 960 {
853 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 961 if (gm != null)
854 pos.X = crossedBorder.BorderLine.Z - 1; 962 {
963 groupUUID = ControllingClient.ActiveGroupId;
964 GroupRecord record = gm.GetGroupRecord(groupUUID);
965 if (record != null)
966 GroupName = record.GroupName;
967 GroupMembershipData groupMembershipData = gm.GetMembershipData(groupUUID, m_uuid);
968 if (groupMembershipData != null)
969 groupPowers = groupMembershipData.GroupPowers;
970 }
971 ControllingClient.SendAgentDataUpdate(m_uuid, groupUUID, Firstname, Lastname, groupPowers, GroupName,
972 Grouptitle);
855 } 973 }
856 974 catch (Exception e)
857 if (m_scene.TestBorderCross(pos, Cardinals.N))
858 { 975 {
859 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 976 m_log.Debug("[AGENTUPDATE]: " + e.ToString());
860 pos.Y = crossedBorder.BorderLine.Z - 1;
861 } 977 }
978 // ------------------------------------
862 979
863 CheckAndAdjustLandingPoint(ref pos); 980 if (ParentID == 0)
864
865 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
866 { 981 {
867 m_log.WarnFormat( 982 // Moved this from SendInitialData to ensure that Appearance is initialized
868 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", 983 // before the inventory is processed in MakeRootAgent. This fixes a race condition
869 pos, Name, UUID); 984 // related to the handling of attachments
985 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
986 if (m_scene.TestBorderCross(pos, Cardinals.E))
987 {
988 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
989 pos.X = crossedBorder.BorderLine.Z - 1;
990 }
870 991
871 if (pos.X < 0f) pos.X = 0f; 992 if (m_scene.TestBorderCross(pos, Cardinals.N))
872 if (pos.Y < 0f) pos.Y = 0f; 993 {
873 if (pos.Z < 0f) pos.Z = 0f; 994 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
874 } 995 pos.Y = crossedBorder.BorderLine.Z - 1;
996 }
875 997
876 float localAVHeight = 1.56f; 998 CheckAndAdjustLandingPoint(ref pos);
877 if (Appearance.AvatarHeight > 0)
878 localAVHeight = Appearance.AvatarHeight;
879 999
880 float posZLimit = 0; 1000 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
1001 {
1002 m_log.WarnFormat(
1003 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
1004 pos, Name, UUID);
881 1005
882 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 1006 if (pos.X < 0f) pos.X = 0f;
883 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 1007 if (pos.Y < 0f) pos.Y = 0f;
884 1008 if (pos.Z < 0f) pos.Z = 0f;
885 float newPosZ = posZLimit + localAVHeight / 2; 1009 }
886 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
887 {
888 pos.Z = newPosZ;
889 }
890 AbsolutePosition = pos;
891 1010
892 AddToPhysicalScene(isFlying); 1011 float localAVHeight = 1.56f;
1012 if (Appearance.AvatarHeight > 0)
1013 localAVHeight = Appearance.AvatarHeight;
893 1014
894 if (ForceFly) 1015 float posZLimit = 0;
895 {
896 Flying = true;
897 }
898 else if (FlyDisabled)
899 {
900 Flying = false;
901 }
902 1016
1017 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
1018 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
1019
1020 float newPosZ = posZLimit + localAVHeight / 2;
1021 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
1022 {
1023 pos.Z = newPosZ;
1024 }
1025 AbsolutePosition = pos;
1026
1027 if (m_teleportFlags == TeleportFlags.Default)
1028 {
1029 Vector3 vel = Velocity;
1030 AddToPhysicalScene(isFlying);
1031 if (PhysicsActor != null)
1032 PhysicsActor.SetMomentum(vel);
1033 }
1034 else
1035 AddToPhysicalScene(isFlying);
1036
1037 if (ForceFly)
1038 {
1039 Flying = true;
1040 }
1041 else if (FlyDisabled)
1042 {
1043 Flying = false;
1044 }
1045 }
903 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 1046 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
904 // avatar to return to the standing position in mid-air. On login it looks like this is being sent 1047 // avatar to return to the standing position in mid-air. On login it looks like this is being sent
905 // elsewhere anyway 1048 // elsewhere anyway
@@ -919,14 +1062,19 @@ namespace OpenSim.Region.Framework.Scenes
919 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name); 1062 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name);
920 1063
921 // Resume scripts 1064 // Resume scripts
922 foreach (SceneObjectGroup sog in m_attachments) 1065 Util.FireAndForget(delegate(object x) {
923 { 1066 foreach (SceneObjectGroup sog in m_attachments)
924 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); 1067 {
925 sog.ResumeScripts(); 1068 sog.ScheduleGroupForFullUpdate();
926 } 1069 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
1070 sog.ResumeScripts();
1071 }
1072 });
927 } 1073 }
928 } 1074 }
929 1075
1076 SendAvatarDataToAllAgents();
1077
930 // send the animations of the other presences to me 1078 // send the animations of the other presences to me
931 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) 1079 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence)
932 { 1080 {
@@ -937,9 +1085,12 @@ namespace OpenSim.Region.Framework.Scenes
937 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will 1085 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will
938 // stall on the border crossing since the existing child agent will still have the last movement 1086 // stall on the border crossing since the existing child agent will still have the last movement
939 // recorded, which stops the input from being processed. 1087 // recorded, which stops the input from being processed.
1088
940 MovementFlag = 0; 1089 MovementFlag = 0;
941 1090
942 m_scene.EventManager.TriggerOnMakeRootAgent(this); 1091 m_scene.EventManager.TriggerOnMakeRootAgent(this);
1092
1093 m_scene.EventManager.OnRegionHeartbeatEnd += RegionHeartbeatEnd;
943 } 1094 }
944 1095
945 public int GetStateSource() 1096 public int GetStateSource()
@@ -967,12 +1118,16 @@ namespace OpenSim.Region.Framework.Scenes
967 /// </remarks> 1118 /// </remarks>
968 public void MakeChildAgent() 1119 public void MakeChildAgent()
969 { 1120 {
1121 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
1122
970 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); 1123 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName);
971 1124
972 // Reset these so that teleporting in and walking out isn't seen 1125 // Reset these so that teleporting in and walking out isn't seen
973 // as teleporting back 1126 // as teleporting back
974 TeleportFlags = TeleportFlags.Default; 1127 TeleportFlags = TeleportFlags.Default;
975 1128
1129 MovementFlag = 0;
1130
976 // It looks like Animator is set to null somewhere, and MakeChild 1131 // It looks like Animator is set to null somewhere, and MakeChild
977 // is called after that. Probably in aborted teleports. 1132 // is called after that. Probably in aborted teleports.
978 if (Animator == null) 1133 if (Animator == null)
@@ -980,6 +1135,7 @@ namespace OpenSim.Region.Framework.Scenes
980 else 1135 else
981 Animator.ResetAnimations(); 1136 Animator.ResetAnimations();
982 1137
1138
983// m_log.DebugFormat( 1139// m_log.DebugFormat(
984// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", 1140// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
985// Name, UUID, m_scene.RegionInfo.RegionName); 1141// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -991,6 +1147,7 @@ namespace OpenSim.Region.Framework.Scenes
991 IsChildAgent = true; 1147 IsChildAgent = true;
992 m_scene.SwapRootAgentCount(true); 1148 m_scene.SwapRootAgentCount(true);
993 RemoveFromPhysicalScene(); 1149 RemoveFromPhysicalScene();
1150 ParentID = 0; // Child agents can't be sitting
994 1151
995 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into 1152 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into
996 1153
@@ -1006,9 +1163,9 @@ namespace OpenSim.Region.Framework.Scenes
1006 { 1163 {
1007// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1164// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
1008 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall; 1165 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall;
1009 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1010 PhysicsActor.UnSubscribeEvents();
1011 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1166 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
1167 PhysicsActor.UnSubscribeEvents();
1168 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1012 PhysicsActor = null; 1169 PhysicsActor = null;
1013 } 1170 }
1014// else 1171// else
@@ -1025,7 +1182,7 @@ namespace OpenSim.Region.Framework.Scenes
1025 /// <param name="pos"></param> 1182 /// <param name="pos"></param>
1026 public void Teleport(Vector3 pos) 1183 public void Teleport(Vector3 pos)
1027 { 1184 {
1028 TeleportWithMomentum(pos, null); 1185 TeleportWithMomentum(pos, Vector3.Zero);
1029 } 1186 }
1030 1187
1031 public void TeleportWithMomentum(Vector3 pos, Vector3? v) 1188 public void TeleportWithMomentum(Vector3 pos, Vector3? v)
@@ -1049,6 +1206,41 @@ namespace OpenSim.Region.Framework.Scenes
1049 SendTerseUpdateToAllClients(); 1206 SendTerseUpdateToAllClients();
1050 } 1207 }
1051 1208
1209 public void avnLocalTeleport(Vector3 newpos, Vector3? newvel, bool rotateToVelXY)
1210 {
1211 CheckLandingPoint(ref newpos);
1212 AbsolutePosition = newpos;
1213
1214 if (newvel.HasValue)
1215 {
1216 if ((Vector3)newvel == Vector3.Zero)
1217 {
1218 if (PhysicsActor != null)
1219 PhysicsActor.SetMomentum(Vector3.Zero);
1220 m_velocity = Vector3.Zero;
1221 }
1222 else
1223 {
1224 if (PhysicsActor != null)
1225 PhysicsActor.SetMomentum((Vector3)newvel);
1226 m_velocity = (Vector3)newvel;
1227
1228 if (rotateToVelXY)
1229 {
1230 Vector3 lookAt = (Vector3)newvel;
1231 lookAt.Z = 0;
1232 lookAt.Normalize();
1233 ControllingClient.SendLocalTeleport(newpos, lookAt, (uint)TeleportFlags.ViaLocation);
1234 return;
1235 }
1236 }
1237 }
1238
1239 SendTerseUpdateToAllClients();
1240 }
1241
1242
1243
1052 public void StopFlying() 1244 public void StopFlying()
1053 { 1245 {
1054 ControllingClient.StopFlying(this); 1246 ControllingClient.StopFlying(this);
@@ -1218,6 +1410,13 @@ namespace OpenSim.Region.Framework.Scenes
1218 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height); 1410 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height);
1219 } 1411 }
1220 1412
1413 public void SetSize(Vector3 size, float feetoffset)
1414 {
1415 if (PhysicsActor != null && !IsChildAgent)
1416 PhysicsActor.setAvatarSize(size, feetoffset);
1417
1418 }
1419
1221 /// <summary> 1420 /// <summary>
1222 /// Complete Avatar's movement into the region. 1421 /// Complete Avatar's movement into the region.
1223 /// </summary> 1422 /// </summary>
@@ -1237,7 +1436,8 @@ namespace OpenSim.Region.Framework.Scenes
1237 1436
1238 Vector3 look = Velocity; 1437 Vector3 look = Velocity;
1239 1438
1240 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) 1439 // if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
1440 if ((Math.Abs(look.X) < 0.1) && (Math.Abs(look.Y) < 0.1) && (Math.Abs(look.Z) < 0.1))
1241 { 1441 {
1242 look = new Vector3(0.99f, 0.042f, 0); 1442 look = new Vector3(0.99f, 0.042f, 0);
1243 } 1443 }
@@ -1287,13 +1487,15 @@ namespace OpenSim.Region.Framework.Scenes
1287 // Create child agents in neighbouring regions 1487 // Create child agents in neighbouring regions
1288 if (openChildAgents && !IsChildAgent) 1488 if (openChildAgents && !IsChildAgent)
1289 { 1489 {
1490
1290 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); 1491 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
1291 if (m_agentTransfer != null) 1492 if (m_agentTransfer != null)
1292 Util.FireAndForget(delegate { m_agentTransfer.EnableChildAgents(this); }); 1493 m_agentTransfer.EnableChildAgents(this);
1293 1494
1294 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); 1495 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
1295 if (friendsModule != null) 1496 if (friendsModule != null)
1296 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); 1497 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient);
1498
1297 } 1499 }
1298 1500
1299// m_log.DebugFormat( 1501// m_log.DebugFormat(
@@ -1309,35 +1511,43 @@ namespace OpenSim.Region.Framework.Scenes
1309 /// <param name="collisionPoint"></param> 1511 /// <param name="collisionPoint"></param>
1310 /// <param name="localid"></param> 1512 /// <param name="localid"></param>
1311 /// <param name="distance"></param> 1513 /// <param name="distance"></param>
1514 ///
1515
1516 private void UpdateCameraCollisionPlane(Vector4 plane)
1517 {
1518 if (m_lastCameraCollisionPlane != plane)
1519 {
1520 m_lastCameraCollisionPlane = plane;
1521 ControllingClient.SendCameraConstraint(plane);
1522 }
1523 }
1524
1312 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) 1525 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal)
1313 { 1526 {
1314 const float POSITION_TOLERANCE = 0.02f; 1527 const float POSITION_TOLERANCE = 0.02f;
1315 const float VELOCITY_TOLERANCE = 0.02f;
1316 const float ROTATION_TOLERANCE = 0.02f; 1528 const float ROTATION_TOLERANCE = 0.02f;
1317 1529
1318 if (m_followCamAuto) 1530 m_doingCamRayCast = false;
1531 if (hitYN && localid != LocalId)
1319 { 1532 {
1320 if (hitYN) 1533 CameraConstraintActive = true;
1321 { 1534 pNormal.X = (float)Math.Round(pNormal.X, 2);
1322 CameraConstraintActive = true; 1535 pNormal.Y = (float)Math.Round(pNormal.Y, 2);
1323 //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); 1536 pNormal.Z = (float)Math.Round(pNormal.Z, 2);
1324 1537 pNormal.Normalize();
1325 Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); 1538 collisionPoint.X = (float)Math.Round(collisionPoint.X, 1);
1326 ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); 1539 collisionPoint.Y = (float)Math.Round(collisionPoint.Y, 1);
1327 } 1540 collisionPoint.Z = (float)Math.Round(collisionPoint.Z, 1);
1328 else 1541
1329 { 1542 Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z, Vector3.Dot(collisionPoint, pNormal));
1330 if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || 1543 UpdateCameraCollisionPlane(plane);
1331 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || 1544 }
1332 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) 1545 else if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
1333 { 1546 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE))
1334 if (CameraConstraintActive) 1547 {
1335 { 1548 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -9000f); // not right...
1336 ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); 1549 UpdateCameraCollisionPlane(plane);
1337 CameraConstraintActive = false; 1550 CameraConstraintActive = false;
1338 }
1339 }
1340 }
1341 } 1551 }
1342 } 1552 }
1343 1553
@@ -1412,12 +1622,6 @@ namespace OpenSim.Region.Framework.Scenes
1412 // DrawDistance = agentData.Far; 1622 // DrawDistance = agentData.Far;
1413 DrawDistance = Scene.DefaultDrawDistance; 1623 DrawDistance = Scene.DefaultDrawDistance;
1414 1624
1415 // Check if Client has camera in 'follow cam' or 'build' mode.
1416 Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation);
1417
1418 m_followCamAuto = ((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.98f)
1419 && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false;
1420
1421 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; 1625 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0;
1422 m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; 1626 m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0;
1423 1627
@@ -1437,14 +1641,38 @@ namespace OpenSim.Region.Framework.Scenes
1437 StandUp(); 1641 StandUp();
1438 } 1642 }
1439 1643
1440 //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto);
1441 // Raycast from the avatar's head to the camera to see if there's anything blocking the view 1644 // Raycast from the avatar's head to the camera to see if there's anything blocking the view
1442 if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) 1645 // this exclude checks may not be complete
1646
1647 if (m_movementUpdateCount % NumMovementsBetweenRayCast == 0 && m_scene.PhysicsScene.SupportsRayCast())
1443 { 1648 {
1444 if (m_followCamAuto) 1649 if (!m_doingCamRayCast && !m_mouseLook && ParentID == 0)
1650 {
1651 Vector3 posAdjusted = AbsolutePosition;
1652// posAdjusted.Z += 0.5f * Appearance.AvatarSize.Z - 0.5f;
1653 posAdjusted.Z += 1.0f; // viewer current camera focus point
1654 Vector3 tocam = CameraPosition - posAdjusted;
1655 tocam.X = (float)Math.Round(tocam.X, 1);
1656 tocam.Y = (float)Math.Round(tocam.Y, 1);
1657 tocam.Z = (float)Math.Round(tocam.Z, 1);
1658
1659 float distTocamlen = tocam.Length();
1660 if (distTocamlen > 0.3f)
1661 {
1662 tocam *= (1.0f / distTocamlen);
1663 posAdjusted.X = (float)Math.Round(posAdjusted.X, 1);
1664 posAdjusted.Y = (float)Math.Round(posAdjusted.Y, 1);
1665 posAdjusted.Z = (float)Math.Round(posAdjusted.Z, 1);
1666
1667 m_doingCamRayCast = true;
1668 m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback);
1669 }
1670 }
1671 else if (CameraConstraintActive && (m_mouseLook || ParentID != 0))
1445 { 1672 {
1446 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; 1673 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right...
1447 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); 1674 UpdateCameraCollisionPlane(plane);
1675 CameraConstraintActive = false;
1448 } 1676 }
1449 } 1677 }
1450 1678
@@ -1913,7 +2141,8 @@ namespace OpenSim.Region.Framework.Scenes
1913// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name); 2141// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name);
1914 2142
1915 MovingToTarget = false; 2143 MovingToTarget = false;
1916 MoveToPositionTarget = Vector3.Zero; 2144// MoveToPositionTarget = Vector3.Zero;
2145 m_forceToApply = null; // cancel possible last action
1917 2146
1918 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct 2147 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct
1919 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag. 2148 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag.
@@ -1931,12 +2160,17 @@ namespace OpenSim.Region.Framework.Scenes
1931// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); 2160// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name);
1932 2161
1933 SitGround = false; 2162 SitGround = false;
2163
2164/* move this down so avatar gets physical in the new position and not where it is siting
1934 if (PhysicsActor == null) 2165 if (PhysicsActor == null)
1935 AddToPhysicalScene(false); 2166 AddToPhysicalScene(false);
2167 */
1936 2168
1937 if (ParentID != 0) 2169 if (ParentID != 0)
1938 { 2170 {
1939 SceneObjectPart part = ParentPart; 2171 SceneObjectPart part = ParentPart;
2172 UnRegisterSeatControls(part.ParentGroup.UUID);
2173
1940 TaskInventoryDictionary taskIDict = part.TaskInventory; 2174 TaskInventoryDictionary taskIDict = part.TaskInventory;
1941 if (taskIDict != null) 2175 if (taskIDict != null)
1942 { 2176 {
@@ -1952,14 +2186,22 @@ namespace OpenSim.Region.Framework.Scenes
1952 } 2186 }
1953 } 2187 }
1954 2188
1955 ParentPosition = part.GetWorldPosition(); 2189 part.ParentGroup.DeleteAvatar(UUID);
2190// ParentPosition = part.GetWorldPosition();
1956 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 2191 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1957 2192
1958 m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight); 2193// m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
1959 ParentPosition = Vector3.Zero; 2194// ParentPosition = Vector3.Zero;
2195 m_pos = part.AbsolutePosition + (m_pos * part.GetWorldRotation()) + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
2196 if (part.SitTargetAvatar == UUID)
2197 m_bodyRot = part.GetWorldRotation() * part.SitTargetOrientation;
1960 2198
1961 ParentID = 0; 2199 ParentID = 0;
1962 ParentPart = null; 2200 ParentPart = null;
2201
2202 if (PhysicsActor == null)
2203 AddToPhysicalScene(false);
2204
1963 SendAvatarDataToAllAgents(); 2205 SendAvatarDataToAllAgents();
1964 m_requestedSitTargetID = 0; 2206 m_requestedSitTargetID = 0;
1965 2207
@@ -1969,6 +2211,9 @@ namespace OpenSim.Region.Framework.Scenes
1969 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 2211 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
1970 } 2212 }
1971 2213
2214 else if (PhysicsActor == null)
2215 AddToPhysicalScene(false);
2216
1972 Animator.TrySetMovementAnimation("STAND"); 2217 Animator.TrySetMovementAnimation("STAND");
1973 } 2218 }
1974 2219
@@ -2016,11 +2261,8 @@ namespace OpenSim.Region.Framework.Scenes
2016 if (part == null) 2261 if (part == null)
2017 return; 2262 return;
2018 2263
2019 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
2020 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
2021
2022 if (PhysicsActor != null) 2264 if (PhysicsActor != null)
2023 m_sitAvatarHeight = PhysicsActor.Size.Z; 2265 m_sitAvatarHeight = PhysicsActor.Size.Z * 0.5f;
2024 2266
2025 bool canSit = false; 2267 bool canSit = false;
2026 Vector3 pos = part.AbsolutePosition + offset; 2268 Vector3 pos = part.AbsolutePosition + offset;
@@ -2037,31 +2279,31 @@ namespace OpenSim.Region.Framework.Scenes
2037 } 2279 }
2038 else 2280 else
2039 { 2281 {
2282 if (PhysicsSit(part,offset)) // physics engine
2283 return;
2284
2040 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10) 2285 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10)
2041 { 2286 {
2042// m_log.DebugFormat(
2043// "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is unset and within 10m",
2044// Name, part.Name, part.LocalId);
2045 2287
2046 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 2288 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
2047 canSit = true; 2289 canSit = true;
2048 } 2290 }
2049// else
2050// {
2051// m_log.DebugFormat(
2052// "[SCENE PRESENCE]: Ignoring sit request of {0} on {1} {2} because sit target is unset and outside 10m",
2053// Name, part.Name, part.LocalId);
2054// }
2055 } 2291 }
2056 2292
2057 if (canSit) 2293 if (canSit)
2058 { 2294 {
2295
2059 if (PhysicsActor != null) 2296 if (PhysicsActor != null)
2060 { 2297 {
2061 // We can remove the physicsActor until they stand up. 2298 // We can remove the physicsActor until they stand up.
2062 RemoveFromPhysicalScene(); 2299 RemoveFromPhysicalScene();
2063 } 2300 }
2064 2301
2302 if (MovingToTarget)
2303 ResetMoveToTarget();
2304
2305 Velocity = Vector3.Zero;
2306
2065 part.AddSittingAvatar(UUID); 2307 part.AddSittingAvatar(UUID);
2066 2308
2067 cameraAtOffset = part.GetCameraAtOffset(); 2309 cameraAtOffset = part.GetCameraAtOffset();
@@ -2069,7 +2311,7 @@ namespace OpenSim.Region.Framework.Scenes
2069 forceMouselook = part.GetForceMouselook(); 2311 forceMouselook = part.GetForceMouselook();
2070 2312
2071 ControllingClient.SendSitResponse( 2313 ControllingClient.SendSitResponse(
2072 targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 2314 part.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
2073 2315
2074 m_requestedSitTargetUUID = targetID; 2316 m_requestedSitTargetUUID = targetID;
2075 2317
@@ -2083,6 +2325,9 @@ namespace OpenSim.Region.Framework.Scenes
2083 2325
2084 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) 2326 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset)
2085 { 2327 {
2328 if (IsChildAgent)
2329 return;
2330
2086 if (ParentID != 0) 2331 if (ParentID != 0)
2087 { 2332 {
2088 if (ParentPart.UUID == targetID) 2333 if (ParentPart.UUID == targetID)
@@ -2098,14 +2343,6 @@ namespace OpenSim.Region.Framework.Scenes
2098 m_requestedSitTargetID = part.LocalId; 2343 m_requestedSitTargetID = part.LocalId;
2099 m_requestedSitTargetUUID = targetID; 2344 m_requestedSitTargetUUID = targetID;
2100 2345
2101// m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset);
2102
2103 if (m_scene.PhysicsScene.SupportsRayCast())
2104 {
2105 //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback());
2106 //SitRayCastAvatarPosition(part);
2107 //return;
2108 }
2109 } 2346 }
2110 else 2347 else
2111 { 2348 {
@@ -2115,197 +2352,111 @@ namespace OpenSim.Region.Framework.Scenes
2115 SendSitResponse(targetID, offset, Quaternion.Identity); 2352 SendSitResponse(targetID, offset, Quaternion.Identity);
2116 } 2353 }
2117 2354
2118 /* 2355 // returns false if does not suport so older sit can be tried
2119 public void SitRayCastAvatarPosition(SceneObjectPart part) 2356 public bool PhysicsSit(SceneObjectPart part, Vector3 offset)
2120 { 2357 {
2121 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2358 if (part == null || part.ParentGroup.IsAttachment)
2122 Vector3 StartRayCastPosition = AbsolutePosition;
2123 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2124 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2125 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionResponse);
2126 }
2127
2128 public void SitRayCastAvatarPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal)
2129 {
2130 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2131 if (part != null)
2132 {
2133 if (hitYN)
2134 {
2135 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2136 {
2137 SitRaycastFindEdge(collisionPoint, normal);
2138 m_log.DebugFormat("[SIT]: Raycast Avatar Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2139 }
2140 else
2141 {
2142 SitRayCastAvatarPositionCameraZ(part);
2143 }
2144 }
2145 else
2146 {
2147 SitRayCastAvatarPositionCameraZ(part);
2148 }
2149 }
2150 else
2151 { 2359 {
2152 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2360 return true;
2153 m_requestedSitTargetUUID = UUID.Zero;
2154 m_requestedSitTargetID = 0;
2155 m_requestedSitOffset = Vector3.Zero;
2156 } 2361 }
2157 2362
2158 } 2363 if ( m_scene.PhysicsScene == null)
2364 return false;
2159 2365
2160 public void SitRayCastAvatarPositionCameraZ(SceneObjectPart part) 2366 if (part.PhysActor == null)
2161 {
2162 // Next, try to raycast from the camera Z position
2163 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2164 Vector3 StartRayCastPosition = AbsolutePosition; StartRayCastPosition.Z = CameraPosition.Z;
2165 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2166 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2167 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionCameraZResponse);
2168 }
2169
2170 public void SitRayCastAvatarPositionCameraZResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal)
2171 {
2172 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2173 if (part != null)
2174 { 2367 {
2175 if (hitYN) 2368 // none physcis shape
2176 { 2369 if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
2177 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) 2370 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2178 {
2179 SitRaycastFindEdge(collisionPoint, normal);
2180 m_log.DebugFormat("[SIT]: Raycast Avatar Position + CameraZ succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2181 }
2182 else
2183 {
2184 SitRayCastCameraPosition(part);
2185 }
2186 }
2187 else 2371 else
2188 { 2372 { // non physical phantom TODO
2189 SitRayCastCameraPosition(part); 2373 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2374 return false;
2190 } 2375 }
2191 } 2376 return true;
2192 else
2193 {
2194 ControllingClient.SendAlertMessage("Sit position no longer exists");
2195 m_requestedSitTargetUUID = UUID.Zero;
2196 m_requestedSitTargetID = 0;
2197 m_requestedSitOffset = Vector3.Zero;
2198 } 2377 }
2199 2378
2200 }
2201 2379
2202 public void SitRayCastCameraPosition(SceneObjectPart part) 2380 // not doing autopilot
2203 { 2381 m_requestedSitTargetID = 0;
2204 // Next, try to raycast from the camera position
2205 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2206 Vector3 StartRayCastPosition = CameraPosition;
2207 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2208 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2209 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastCameraPositionResponse);
2210 }
2211 2382
2212 public void SitRayCastCameraPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2383 if (m_scene.PhysicsScene.SitAvatar(part.PhysActor, AbsolutePosition, CameraPosition, offset, new Vector3(0.35f, 0, 0.65f), PhysicsSitResponse) != 0)
2213 { 2384 return true;
2214 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2215 if (part != null)
2216 {
2217 if (hitYN)
2218 {
2219 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2220 {
2221 SitRaycastFindEdge(collisionPoint, normal);
2222 m_log.DebugFormat("[SIT]: Raycast Camera Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2223 }
2224 else
2225 {
2226 SitRayHorizontal(part);
2227 }
2228 }
2229 else
2230 {
2231 SitRayHorizontal(part);
2232 }
2233 }
2234 else
2235 {
2236 ControllingClient.SendAlertMessage("Sit position no longer exists");
2237 m_requestedSitTargetUUID = UUID.Zero;
2238 m_requestedSitTargetID = 0;
2239 m_requestedSitOffset = Vector3.Zero;
2240 }
2241 2385
2386 return false;
2242 } 2387 }
2243 2388
2244 public void SitRayHorizontal(SceneObjectPart part) 2389
2390 private bool CanEnterLandPosition(Vector3 testPos)
2245 { 2391 {
2246 // Next, try to raycast from the avatar position to fwd 2392 ILandObject land = m_scene.LandChannel.GetLandObject(testPos.X, testPos.Y);
2247 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2393
2248 Vector3 StartRayCastPosition = CameraPosition; 2394 if (land == null || land.LandData.Name == "NO_LAND")
2249 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); 2395 return true;
2250 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); 2396
2251 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastHorizontalResponse); 2397 return land.CanBeOnThisLand(UUID,testPos.Z);
2252 } 2398 }
2253 2399
2254 public void SitRayCastHorizontalResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2400 // status
2401 // < 0 ignore
2402 // 0 bad sit spot
2403 public void PhysicsSitResponse(int status, uint partID, Vector3 offset, Quaternion Orientation)
2255 { 2404 {
2256 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); 2405 if (status < 0)
2257 if (part != null) 2406 return;
2407
2408 if (status == 0)
2258 { 2409 {
2259 if (hitYN) 2410 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2260 { 2411 return;
2261 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2262 {
2263 SitRaycastFindEdge(collisionPoint, normal);
2264 m_log.DebugFormat("[SIT]: Raycast Horizontal Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2265 // Next, try to raycast from the camera position
2266 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2267 Vector3 StartRayCastPosition = CameraPosition;
2268 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2269 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2270 //m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastResponseAvatarPosition);
2271 }
2272 else
2273 {
2274 ControllingClient.SendAlertMessage("Sit position not accessable.");
2275 m_requestedSitTargetUUID = UUID.Zero;
2276 m_requestedSitTargetID = 0;
2277 m_requestedSitOffset = Vector3.Zero;
2278 }
2279 }
2280 else
2281 {
2282 ControllingClient.SendAlertMessage("Sit position not accessable.");
2283 m_requestedSitTargetUUID = UUID.Zero;
2284 m_requestedSitTargetID = 0;
2285 m_requestedSitOffset = Vector3.Zero;
2286 }
2287 } 2412 }
2288 else 2413
2414 SceneObjectPart part = m_scene.GetSceneObjectPart(partID);
2415 if (part == null)
2416 return;
2417
2418 Vector3 targetPos = part.GetWorldPosition() + offset * part.GetWorldRotation();
2419 if(!CanEnterLandPosition(targetPos))
2289 { 2420 {
2290 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2421 ControllingClient.SendAlertMessage(" Sit position on restricted land, try another spot");
2291 m_requestedSitTargetUUID = UUID.Zero; 2422 return;
2292 m_requestedSitTargetID = 0;
2293 m_requestedSitOffset = Vector3.Zero;
2294 } 2423 }
2295 2424
2296 } 2425 RemoveFromPhysicalScene();
2297 2426
2298 private void SitRaycastFindEdge(Vector3 collisionPoint, Vector3 collisionNormal) 2427 if (MovingToTarget)
2299 { 2428 ResetMoveToTarget();
2300 int i = 0; 2429
2301 //throw new NotImplementedException(); 2430 Velocity = Vector3.Zero;
2302 //m_requestedSitTargetUUID = UUID.Zero; 2431
2303 //m_requestedSitTargetID = 0; 2432 part.AddSittingAvatar(UUID);
2304 //m_requestedSitOffset = Vector3.Zero;
2305 2433
2306 SendSitResponse(ControllingClient, m_requestedSitTargetUUID, collisionPoint - m_requestedSitOffset, Quaternion.Identity); 2434 Vector3 cameraAtOffset = part.GetCameraAtOffset();
2435 Vector3 cameraEyeOffset = part.GetCameraEyeOffset();
2436 bool forceMouselook = part.GetForceMouselook();
2437
2438 ControllingClient.SendSitResponse(
2439 part.UUID, offset, Orientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
2440
2441 // not using autopilot
2442
2443 Rotation = Orientation;
2444 m_pos = offset;
2445
2446 m_requestedSitTargetID = 0;
2447 part.ParentGroup.AddAvatar(UUID);
2448
2449 ParentPart = part;
2450 ParentID = part.LocalId;
2451 if(status == 3)
2452 Animator.TrySetMovementAnimation("SIT_GROUND");
2453 else
2454 Animator.TrySetMovementAnimation("SIT");
2455 SendAvatarDataToAllAgents();
2456
2457 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2307 } 2458 }
2308 */ 2459
2309 2460
2310 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) 2461 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID)
2311 { 2462 {
@@ -2322,6 +2473,7 @@ namespace OpenSim.Region.Framework.Scenes
2322 return; 2473 return;
2323 } 2474 }
2324 2475
2476
2325 if (part.SitTargetAvatar == UUID) 2477 if (part.SitTargetAvatar == UUID)
2326 { 2478 {
2327 Vector3 sitTargetPos = part.SitTargetPosition; 2479 Vector3 sitTargetPos = part.SitTargetPosition;
@@ -2336,14 +2488,39 @@ namespace OpenSim.Region.Framework.Scenes
2336 2488
2337 //Quaternion result = (sitTargetOrient * vq) * nq; 2489 //Quaternion result = (sitTargetOrient * vq) * nq;
2338 2490
2339 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2491 double x, y, z, m;
2492
2493 Quaternion r = sitTargetOrient;
2494 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2495
2496 if (Math.Abs(1.0 - m) > 0.000001)
2497 {
2498 m = 1.0 / Math.Sqrt(m);
2499 r.X *= (float)m;
2500 r.Y *= (float)m;
2501 r.Z *= (float)m;
2502 r.W *= (float)m;
2503 }
2504
2505 x = 2 * (r.X * r.Z + r.Y * r.W);
2506 y = 2 * (-r.X * r.W + r.Y * r.Z);
2507 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2508
2509 Vector3 up = new Vector3((float)x, (float)y, (float)z);
2510 Vector3 sitOffset = up * Appearance.AvatarHeight * 0.02638f;
2511
2512 m_pos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT;
2513
2514// m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT - sitOffset;
2340 Rotation = sitTargetOrient; 2515 Rotation = sitTargetOrient;
2341 ParentPosition = part.AbsolutePosition; 2516// ParentPosition = part.AbsolutePosition;
2517 part.ParentGroup.AddAvatar(UUID);
2342 } 2518 }
2343 else 2519 else
2344 { 2520 {
2345 m_pos -= part.AbsolutePosition; 2521 m_pos -= part.AbsolutePosition;
2346 ParentPosition = part.AbsolutePosition; 2522// ParentPosition = part.AbsolutePosition;
2523 part.ParentGroup.AddAvatar(UUID);
2347 2524
2348// m_log.DebugFormat( 2525// m_log.DebugFormat(
2349// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2526// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -2394,6 +2571,13 @@ namespace OpenSim.Region.Framework.Scenes
2394 Animator.RemoveAnimation(animID, false); 2571 Animator.RemoveAnimation(animID, false);
2395 } 2572 }
2396 2573
2574 public void avnHandleChangeAnim(UUID animID, bool addRemove,bool sendPack)
2575 {
2576 Animator.avnChangeAnim(animID, addRemove, sendPack);
2577 }
2578
2579
2580
2397 /// <summary> 2581 /// <summary>
2398 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector 2582 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
2399 /// </summary> 2583 /// </summary>
@@ -2447,14 +2631,15 @@ namespace OpenSim.Region.Framework.Scenes
2447 direc.Z *= 2.6f; 2631 direc.Z *= 2.6f;
2448 2632
2449 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2633 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
2450 Animator.TrySetMovementAnimation("PREJUMP"); 2634// Animator.TrySetMovementAnimation("PREJUMP");
2451 Animator.TrySetMovementAnimation("JUMP"); 2635// Animator.TrySetMovementAnimation("JUMP");
2452 } 2636 }
2453 } 2637 }
2454 } 2638 }
2455 2639
2456 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2640 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2457 m_forceToApply = direc; 2641 m_forceToApply = direc;
2642 Animator.UpdateMovementAnimations();
2458 } 2643 }
2459 2644
2460 #endregion 2645 #endregion
@@ -2472,16 +2657,12 @@ namespace OpenSim.Region.Framework.Scenes
2472 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to 2657 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to
2473 // grab the latest PhysicsActor velocity, whereas m_velocity is often 2658 // grab the latest PhysicsActor velocity, whereas m_velocity is often
2474 // storing a requested force instead of an actual traveling velocity 2659 // storing a requested force instead of an actual traveling velocity
2660 if (Appearance.AvatarSize != m_lastSize && !IsLoggingIn)
2661 SendAvatarDataToAllAgents();
2475 2662
2476 // Throw away duplicate or insignificant updates 2663 if (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||
2477 if ( 2664 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
2478 // If the velocity has become zero, send it no matter what. 2665 !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))
2479 (Velocity != m_lastVelocity && Velocity == Vector3.Zero)
2480 // otherwise, if things have changed reasonably, send the update
2481 || (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)
2482 || !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE)
2483 || !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)))
2484
2485 { 2666 {
2486 SendTerseUpdateToAllClients(); 2667 SendTerseUpdateToAllClients();
2487 2668
@@ -2670,6 +2851,8 @@ namespace OpenSim.Region.Framework.Scenes
2670 return; 2851 return;
2671 } 2852 }
2672 2853
2854 m_lastSize = Appearance.AvatarSize;
2855
2673 int count = 0; 2856 int count = 0;
2674 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) 2857 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
2675 { 2858 {
@@ -2777,6 +2960,8 @@ namespace OpenSim.Region.Framework.Scenes
2777 2960
2778 avatar.ControllingClient.SendAppearance( 2961 avatar.ControllingClient.SendAppearance(
2779 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes()); 2962 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes());
2963
2964
2780 } 2965 }
2781 2966
2782 #endregion 2967 #endregion
@@ -2851,8 +3036,9 @@ namespace OpenSim.Region.Framework.Scenes
2851 3036
2852 // If we don't have a PhysActor, we can't cross anyway 3037 // If we don't have a PhysActor, we can't cross anyway
2853 // Also don't do this while sat, sitting avatars cross with the 3038 // Also don't do this while sat, sitting avatars cross with the
2854 // object they sit on. 3039 // object they sit on. ParentUUID denoted a pending sit, don't
2855 if (ParentID != 0 || PhysicsActor == null) 3040 // interfere with it.
3041 if (ParentID != 0 || PhysicsActor == null || ParentUUID != UUID.Zero)
2856 return; 3042 return;
2857 3043
2858 if (!IsInTransit) 3044 if (!IsInTransit)
@@ -3113,6 +3299,10 @@ namespace OpenSim.Region.Framework.Scenes
3113 } 3299 }
3114 3300
3115 private static Vector3 marker = new Vector3(-1f, -1f, -1f); 3301 private static Vector3 marker = new Vector3(-1f, -1f, -1f);
3302 private void RaiseUpdateThrottles()
3303 {
3304 m_scene.EventManager.TriggerThrottleUpdate(this);
3305 }
3116 /// <summary> 3306 /// <summary>
3117 /// This updates important decision making data about a child agent 3307 /// This updates important decision making data about a child agent
3118 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region 3308 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region
@@ -3193,6 +3383,9 @@ namespace OpenSim.Region.Framework.Scenes
3193 cAgent.AlwaysRun = SetAlwaysRun; 3383 cAgent.AlwaysRun = SetAlwaysRun;
3194 3384
3195 cAgent.Appearance = new AvatarAppearance(Appearance); 3385 cAgent.Appearance = new AvatarAppearance(Appearance);
3386
3387 cAgent.ParentPart = ParentUUID;
3388 cAgent.SitOffset = m_pos;
3196 3389
3197 lock (scriptedcontrols) 3390 lock (scriptedcontrols)
3198 { 3391 {
@@ -3201,7 +3394,7 @@ namespace OpenSim.Region.Framework.Scenes
3201 3394
3202 foreach (ScriptControllers c in scriptedcontrols.Values) 3395 foreach (ScriptControllers c in scriptedcontrols.Values)
3203 { 3396 {
3204 controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); 3397 controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
3205 } 3398 }
3206 cAgent.Controllers = controls; 3399 cAgent.Controllers = controls;
3207 } 3400 }
@@ -3234,6 +3427,8 @@ namespace OpenSim.Region.Framework.Scenes
3234 CameraAtAxis = cAgent.AtAxis; 3427 CameraAtAxis = cAgent.AtAxis;
3235 CameraLeftAxis = cAgent.LeftAxis; 3428 CameraLeftAxis = cAgent.LeftAxis;
3236 CameraUpAxis = cAgent.UpAxis; 3429 CameraUpAxis = cAgent.UpAxis;
3430 ParentUUID = cAgent.ParentPart;
3431 m_prevSitOffset = cAgent.SitOffset;
3237 3432
3238 // When we get to the point of re-computing neighbors everytime this 3433 // When we get to the point of re-computing neighbors everytime this
3239 // changes, then start using the agent's drawdistance rather than the 3434 // changes, then start using the agent's drawdistance rather than the
@@ -3271,6 +3466,7 @@ namespace OpenSim.Region.Framework.Scenes
3271 foreach (ControllerData c in cAgent.Controllers) 3466 foreach (ControllerData c in cAgent.Controllers)
3272 { 3467 {
3273 ScriptControllers sc = new ScriptControllers(); 3468 ScriptControllers sc = new ScriptControllers();
3469 sc.objectID = c.ObjectID;
3274 sc.itemID = c.ItemID; 3470 sc.itemID = c.ItemID;
3275 sc.ignoreControls = (ScriptControlled)c.IgnoreControls; 3471 sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
3276 sc.eventControls = (ScriptControlled)c.EventControls; 3472 sc.eventControls = (ScriptControlled)c.EventControls;
@@ -3338,20 +3534,27 @@ namespace OpenSim.Region.Framework.Scenes
3338 } 3534 }
3339 3535
3340 if (Appearance.AvatarHeight == 0) 3536 if (Appearance.AvatarHeight == 0)
3341 Appearance.SetHeight(); 3537// Appearance.SetHeight();
3538 Appearance.SetSize(new Vector3(0.45f,0.6f,1.9f));
3342 3539
3343 PhysicsScene scene = m_scene.PhysicsScene; 3540 PhysicsScene scene = m_scene.PhysicsScene;
3344 3541
3345 Vector3 pVec = AbsolutePosition; 3542 Vector3 pVec = AbsolutePosition;
3346 3543
3544/*
3347 PhysicsActor = scene.AddAvatar( 3545 PhysicsActor = scene.AddAvatar(
3348 LocalId, Firstname + "." + Lastname, pVec, 3546 LocalId, Firstname + "." + Lastname, pVec,
3349 new Vector3(0f, 0f, Appearance.AvatarHeight), isFlying); 3547 new Vector3(0.45f, 0.6f, Appearance.AvatarHeight), isFlying);
3548*/
3549
3550 PhysicsActor = scene.AddAvatar(
3551 LocalId, Firstname + "." + Lastname, pVec,
3552 Appearance.AvatarBoxSize,Appearance.AvatarFeetOffset, isFlying);
3350 3553
3351 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3554 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3352 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3555 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
3353 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong 3556 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
3354 PhysicsActor.SubscribeEvents(500); 3557 PhysicsActor.SubscribeEvents(100);
3355 PhysicsActor.LocalID = LocalId; 3558 PhysicsActor.LocalID = LocalId;
3356 } 3559 }
3357 3560
@@ -3365,6 +3568,7 @@ namespace OpenSim.Region.Framework.Scenes
3365 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); 3568 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true);
3366 } 3569 }
3367 3570
3571
3368 /// <summary> 3572 /// <summary>
3369 /// Event called by the physics plugin to tell the avatar about a collision. 3573 /// Event called by the physics plugin to tell the avatar about a collision.
3370 /// </summary> 3574 /// </summary>
@@ -3378,7 +3582,7 @@ namespace OpenSim.Region.Framework.Scenes
3378 /// <param name="e"></param> 3582 /// <param name="e"></param>
3379 public void PhysicsCollisionUpdate(EventArgs e) 3583 public void PhysicsCollisionUpdate(EventArgs e)
3380 { 3584 {
3381 if (IsChildAgent) 3585 if (IsChildAgent || Animator == null)
3382 return; 3586 return;
3383 3587
3384 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3588 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
@@ -3394,7 +3598,6 @@ namespace OpenSim.Region.Framework.Scenes
3394 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3598 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3395 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3599 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3396 3600
3397 CollisionPlane = Vector4.UnitW;
3398 3601
3399// // No collisions at all means we may be flying. Update always 3602// // No collisions at all means we may be flying. Update always
3400// // to make falling work 3603// // to make falling work
@@ -3406,6 +3609,7 @@ namespace OpenSim.Region.Framework.Scenes
3406 3609
3407 if (coldata.Count != 0) 3610 if (coldata.Count != 0)
3408 { 3611 {
3612/*
3409 switch (Animator.CurrentMovementAnimation) 3613 switch (Animator.CurrentMovementAnimation)
3410 { 3614 {
3411 case "STAND": 3615 case "STAND":
@@ -3414,24 +3618,38 @@ namespace OpenSim.Region.Framework.Scenes
3414 case "CROUCH": 3618 case "CROUCH":
3415 case "CROUCHWALK": 3619 case "CROUCHWALK":
3416 { 3620 {
3621 */
3417 ContactPoint lowest; 3622 ContactPoint lowest;
3418 lowest.SurfaceNormal = Vector3.Zero; 3623 lowest.SurfaceNormal = Vector3.Zero;
3419 lowest.Position = Vector3.Zero; 3624 lowest.Position = Vector3.Zero;
3420 lowest.Position.Z = Single.NaN; 3625 lowest.Position.Z = float.MaxValue;
3421 3626
3422 foreach (ContactPoint contact in coldata.Values) 3627 foreach (ContactPoint contact in coldata.Values)
3423 { 3628 {
3424 if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z) 3629
3630 if (contact.CharacterFeet && contact.Position.Z < lowest.Position.Z)
3425 { 3631 {
3426 lowest = contact; 3632 lowest = contact;
3427 } 3633 }
3428 } 3634 }
3429 3635
3430 CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal)); 3636 if (lowest.Position.Z != float.MaxValue)
3637 {
3638 lowest.SurfaceNormal = -lowest.SurfaceNormal;
3639 CollisionPlane = new Vector4(lowest.SurfaceNormal, Vector3.Dot(lowest.Position, lowest.SurfaceNormal));
3640 }
3641 else
3642 CollisionPlane = Vector4.UnitW;
3643/*
3431 } 3644 }
3432 break; 3645 break;
3433 } 3646 }
3647*/
3434 } 3648 }
3649 else
3650 CollisionPlane = Vector4.UnitW;
3651
3652 RaiseCollisionScriptEvents(coldata);
3435 3653
3436 // Gods do not take damage and Invulnerable is set depending on parcel/region flags 3654 // Gods do not take damage and Invulnerable is set depending on parcel/region flags
3437 if (Invulnerable || GodLevel > 0) 3655 if (Invulnerable || GodLevel > 0)
@@ -3530,6 +3748,13 @@ namespace OpenSim.Region.Framework.Scenes
3530 // m_reprioritizationTimer.Dispose(); 3748 // m_reprioritizationTimer.Dispose();
3531 3749
3532 RemoveFromPhysicalScene(); 3750 RemoveFromPhysicalScene();
3751
3752 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
3753
3754// if (Animator != null)
3755// Animator.Close();
3756 Animator = null;
3757
3533 } 3758 }
3534 3759
3535 public void AddAttachment(SceneObjectGroup gobj) 3760 public void AddAttachment(SceneObjectGroup gobj)
@@ -3763,10 +3988,18 @@ namespace OpenSim.Region.Framework.Scenes
3763 3988
3764 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 3989 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
3765 { 3990 {
3991 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID);
3992 if (p == null)
3993 return;
3994
3995 ControllingClient.SendTakeControls(controls, false, false);
3996 ControllingClient.SendTakeControls(controls, true, false);
3997
3766 ScriptControllers obj = new ScriptControllers(); 3998 ScriptControllers obj = new ScriptControllers();
3767 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 3999 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
3768 obj.eventControls = ScriptControlled.CONTROL_ZERO; 4000 obj.eventControls = ScriptControlled.CONTROL_ZERO;
3769 4001
4002 obj.objectID = p.ParentGroup.UUID;
3770 obj.itemID = Script_item_UUID; 4003 obj.itemID = Script_item_UUID;
3771 if (pass_on == 0 && accept == 0) 4004 if (pass_on == 0 && accept == 0)
3772 { 4005 {
@@ -3815,6 +4048,21 @@ namespace OpenSim.Region.Framework.Scenes
3815 ControllingClient.SendTakeControls(int.MaxValue, false, false); 4048 ControllingClient.SendTakeControls(int.MaxValue, false, false);
3816 } 4049 }
3817 4050
4051 private void UnRegisterSeatControls(UUID obj)
4052 {
4053 List<UUID> takers = new List<UUID>();
4054
4055 foreach (ScriptControllers c in scriptedcontrols.Values)
4056 {
4057 if (c.objectID == obj)
4058 takers.Add(c.itemID);
4059 }
4060 foreach (UUID t in takers)
4061 {
4062 UnRegisterControlEventsToScript(0, t);
4063 }
4064 }
4065
3818 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 4066 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
3819 { 4067 {
3820 ScriptControllers takecontrols; 4068 ScriptControllers takecontrols;
@@ -4144,6 +4392,12 @@ namespace OpenSim.Region.Framework.Scenes
4144 4392
4145 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4393 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
4146 { 4394 {
4395 string reason;
4396
4397 // Honor bans
4398 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
4399 return;
4400
4147 SceneObjectGroup telehub = null; 4401 SceneObjectGroup telehub = null;
4148 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 4402 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
4149 { 4403 {
@@ -4183,11 +4437,206 @@ namespace OpenSim.Region.Framework.Scenes
4183 pos = land.LandData.UserLocation; 4437 pos = land.LandData.UserLocation;
4184 } 4438 }
4185 } 4439 }
4186 4440
4187 land.SendLandUpdateToClient(ControllingClient); 4441 land.SendLandUpdateToClient(ControllingClient);
4188 } 4442 }
4189 } 4443 }
4190 4444
4445 private DetectedObject CreateDetObject(SceneObjectPart obj)
4446 {
4447 DetectedObject detobj = new DetectedObject();
4448 detobj.keyUUID = obj.UUID;
4449 detobj.nameStr = obj.Name;
4450 detobj.ownerUUID = obj.OwnerID;
4451 detobj.posVector = obj.AbsolutePosition;
4452 detobj.rotQuat = obj.GetWorldRotation();
4453 detobj.velVector = obj.Velocity;
4454 detobj.colliderType = 0;
4455 detobj.groupUUID = obj.GroupID;
4456
4457 return detobj;
4458 }
4459
4460 private DetectedObject CreateDetObject(ScenePresence av)
4461 {
4462 DetectedObject detobj = new DetectedObject();
4463 detobj.keyUUID = av.UUID;
4464 detobj.nameStr = av.ControllingClient.Name;
4465 detobj.ownerUUID = av.UUID;
4466 detobj.posVector = av.AbsolutePosition;
4467 detobj.rotQuat = av.Rotation;
4468 detobj.velVector = av.Velocity;
4469 detobj.colliderType = 0;
4470 detobj.groupUUID = av.ControllingClient.ActiveGroupId;
4471
4472 return detobj;
4473 }
4474
4475 private DetectedObject CreateDetObjectForGround()
4476 {
4477 DetectedObject detobj = new DetectedObject();
4478 detobj.keyUUID = UUID.Zero;
4479 detobj.nameStr = "";
4480 detobj.ownerUUID = UUID.Zero;
4481 detobj.posVector = AbsolutePosition;
4482 detobj.rotQuat = Quaternion.Identity;
4483 detobj.velVector = Vector3.Zero;
4484 detobj.colliderType = 0;
4485 detobj.groupUUID = UUID.Zero;
4486
4487 return detobj;
4488 }
4489
4490 private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
4491 {
4492 ColliderArgs colliderArgs = new ColliderArgs();
4493 List<DetectedObject> colliding = new List<DetectedObject>();
4494 foreach (uint localId in colliders)
4495 {
4496 if (localId == 0)
4497 continue;
4498
4499 SceneObjectPart obj = m_scene.GetSceneObjectPart(localId);
4500 if (obj != null)
4501 {
4502 if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
4503 colliding.Add(CreateDetObject(obj));
4504 }
4505 else
4506 {
4507 ScenePresence av = m_scene.GetScenePresence(localId);
4508 if (av != null && (!av.IsChildAgent))
4509 {
4510 if (!dest.CollisionFilteredOut(av.UUID, av.Name))
4511 colliding.Add(CreateDetObject(av));
4512 }
4513 }
4514 }
4515
4516 colliderArgs.Colliders = colliding;
4517
4518 return colliderArgs;
4519 }
4520
4521 private delegate void ScriptCollidingNotification(uint localID, ColliderArgs message);
4522
4523 private void SendCollisionEvent(SceneObjectGroup dest, scriptEvents ev, List<uint> colliders, ScriptCollidingNotification notify)
4524 {
4525 ColliderArgs CollidingMessage;
4526
4527 if (colliders.Count > 0)
4528 {
4529 if ((dest.RootPart.ScriptEvents & ev) != 0)
4530 {
4531 CollidingMessage = CreateColliderArgs(dest.RootPart, colliders);
4532
4533 if (CollidingMessage.Colliders.Count > 0)
4534 notify(dest.RootPart.LocalId, CollidingMessage);
4535 }
4536 }
4537 }
4538
4539 private void SendLandCollisionEvent(SceneObjectGroup dest, scriptEvents ev, ScriptCollidingNotification notify)
4540 {
4541 if ((dest.RootPart.ScriptEvents & ev) != 0)
4542 {
4543 ColliderArgs LandCollidingMessage = new ColliderArgs();
4544 List<DetectedObject> colliding = new List<DetectedObject>();
4545
4546 colliding.Add(CreateDetObjectForGround());
4547 LandCollidingMessage.Colliders = colliding;
4548
4549 notify(dest.RootPart.LocalId, LandCollidingMessage);
4550 }
4551 }
4552
4553 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4554 {
4555 try
4556 {
4557 List<uint> thisHitColliders = new List<uint>();
4558 List<uint> endedColliders = new List<uint>();
4559 List<uint> startedColliders = new List<uint>();
4560 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
4561 CollisionForSoundInfo soundinfo;
4562 ContactPoint curcontact;
4563
4564 if (coldata.Count == 0)
4565 {
4566 if (m_lastColliders.Count == 0)
4567 return; // nothing to do
4568
4569 foreach (uint localID in m_lastColliders)
4570 {
4571 endedColliders.Add(localID);
4572 }
4573 m_lastColliders.Clear();
4574 }
4575
4576 else
4577 {
4578 foreach (uint id in coldata.Keys)
4579 {
4580 thisHitColliders.Add(id);
4581 if (!m_lastColliders.Contains(id))
4582 {
4583 startedColliders.Add(id);
4584 curcontact = coldata[id];
4585 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
4586 {
4587 soundinfo = new CollisionForSoundInfo();
4588 soundinfo.colliderID = id;
4589 soundinfo.position = curcontact.Position;
4590 soundinfo.relativeVel = curcontact.RelativeSpeed;
4591 soundinfolist.Add(soundinfo);
4592 }
4593 }
4594 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4595 }
4596
4597 // calculate things that ended colliding
4598 foreach (uint localID in m_lastColliders)
4599 {
4600 if (!thisHitColliders.Contains(localID))
4601 {
4602 endedColliders.Add(localID);
4603 }
4604 }
4605 //add the items that started colliding this time to the last colliders list.
4606 foreach (uint localID in startedColliders)
4607 {
4608 m_lastColliders.Add(localID);
4609 }
4610 // remove things that ended colliding from the last colliders list
4611 foreach (uint localID in endedColliders)
4612 {
4613 m_lastColliders.Remove(localID);
4614 }
4615
4616 if (soundinfolist.Count > 0)
4617 CollisionSounds.AvatarCollisionSound(this, soundinfolist);
4618 }
4619
4620 foreach (SceneObjectGroup att in GetAttachments())
4621 {
4622 SendCollisionEvent(att, scriptEvents.collision_start, startedColliders, m_scene.EventManager.TriggerScriptCollidingStart);
4623 SendCollisionEvent(att, scriptEvents.collision , m_lastColliders , m_scene.EventManager.TriggerScriptColliding);
4624 SendCollisionEvent(att, scriptEvents.collision_end , endedColliders , m_scene.EventManager.TriggerScriptCollidingEnd);
4625
4626 if (startedColliders.Contains(0))
4627 SendLandCollisionEvent(att, scriptEvents.land_collision_start, m_scene.EventManager.TriggerScriptLandCollidingStart);
4628 if (m_lastColliders.Contains(0))
4629 SendLandCollisionEvent(att, scriptEvents.land_collision, m_scene.EventManager.TriggerScriptLandColliding);
4630 if (endedColliders.Contains(0))
4631 SendLandCollisionEvent(att, scriptEvents.land_collision_end, m_scene.EventManager.TriggerScriptLandCollidingEnd);
4632 }
4633 }
4634 finally
4635 {
4636 m_collisionEventFlag = false;
4637 }
4638 }
4639
4191 private void TeleportFlagsDebug() { 4640 private void TeleportFlagsDebug() {
4192 4641
4193 // Some temporary debugging help to show all the TeleportFlags we have... 4642 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -4212,6 +4661,5 @@ namespace OpenSim.Region.Framework.Scenes
4212 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4661 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
4213 4662
4214 } 4663 }
4215
4216 } 4664 }
4217} 4665}