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 70e3952..a57e0d1 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>
@@ -713,6 +759,7 @@ namespace OpenSim.Region.Framework.Scenes
713 AttachmentsSyncLock = new Object(); 759 AttachmentsSyncLock = new Object();
714 AllowMovement = true; 760 AllowMovement = true;
715 IsChildAgent = true; 761 IsChildAgent = true;
762 IsLoggingIn = false;
716 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault; 763 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault;
717 Animator = new ScenePresenceAnimator(this); 764 Animator = new ScenePresenceAnimator(this);
718 PresenceType = type; 765 PresenceType = type;
@@ -756,6 +803,33 @@ namespace OpenSim.Region.Framework.Scenes
756 Appearance = appearance; 803 Appearance = appearance;
757 } 804 }
758 805
806 private void RegionHeartbeatEnd(Scene scene)
807 {
808 if (IsChildAgent)
809 return;
810
811 m_movementAnimationUpdateCounter ++;
812 if (m_movementAnimationUpdateCounter >= 2)
813 {
814 m_movementAnimationUpdateCounter = 0;
815 if (Animator != null)
816 {
817 // If the parentID == 0 we are not sitting
818 // if !SitGournd then we are not sitting on the ground
819 // Fairly straightforward, now here comes the twist
820 // if ParentUUID is NOT UUID.Zero, we are looking to
821 // be sat on an object that isn't there yet. Should
822 // be treated as if sat.
823 if(ParentID == 0 && !SitGround && ParentUUID == UUID.Zero) // skip it if sitting
824 Animator.UpdateMovementAnimations();
825 }
826 else
827 {
828 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
829 }
830 }
831 }
832
759 public void RegisterToEvents() 833 public void RegisterToEvents()
760 { 834 {
761 ControllingClient.OnCompleteMovementToRegion += CompleteMovement; 835 ControllingClient.OnCompleteMovementToRegion += CompleteMovement;
@@ -765,8 +839,10 @@ namespace OpenSim.Region.Framework.Scenes
765 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; 839 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
766 ControllingClient.OnStartAnim += HandleStartAnim; 840 ControllingClient.OnStartAnim += HandleStartAnim;
767 ControllingClient.OnStopAnim += HandleStopAnim; 841 ControllingClient.OnStopAnim += HandleStopAnim;
842 ControllingClient.OnChangeAnim += avnHandleChangeAnim;
768 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls; 843 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls;
769 ControllingClient.OnAutoPilotGo += MoveToTarget; 844 ControllingClient.OnAutoPilotGo += MoveToTarget;
845 ControllingClient.OnUpdateThrottles += RaiseUpdateThrottles;
770 846
771 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); 847 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
772 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); 848 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
@@ -825,10 +901,40 @@ namespace OpenSim.Region.Framework.Scenes
825 "[SCENE]: Upgrading child to root agent for {0} in {1}", 901 "[SCENE]: Upgrading child to root agent for {0} in {1}",
826 Name, m_scene.RegionInfo.RegionName); 902 Name, m_scene.RegionInfo.RegionName);
827 903
828 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
829
830 bool wasChild = IsChildAgent; 904 bool wasChild = IsChildAgent;
831 IsChildAgent = false; 905
906 if (ParentUUID != UUID.Zero)
907 {
908 m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID);
909 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID);
910 if (part == null)
911 {
912 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
913 }
914 else
915 {
916 part.ParentGroup.AddAvatar(UUID);
917 if (part.SitTargetPosition != Vector3.Zero)
918 part.SitTargetAvatar = UUID;
919// ParentPosition = part.GetWorldPosition();
920 ParentID = part.LocalId;
921 ParentPart = part;
922 m_pos = m_prevSitOffset;
923// pos = ParentPosition;
924 pos = part.GetWorldPosition();
925 }
926 ParentUUID = UUID.Zero;
927
928 IsChildAgent = false;
929
930// Animator.TrySetMovementAnimation("SIT");
931 }
932 else
933 {
934 IsChildAgent = false;
935 IsLoggingIn = false;
936 }
937
832 938
833 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 939 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
834 if (gm != null) 940 if (gm != null)
@@ -838,62 +944,99 @@ namespace OpenSim.Region.Framework.Scenes
838 944
839 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 945 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
840 946
841 // Moved this from SendInitialData to ensure that Appearance is initialized 947 UUID groupUUID = UUID.Zero;
842 // before the inventory is processed in MakeRootAgent. This fixes a race condition 948 string GroupName = string.Empty;
843 // related to the handling of attachments 949 ulong groupPowers = 0;
844 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance); 950
845 if (m_scene.TestBorderCross(pos, Cardinals.E)) 951 // ----------------------------------
952 // Previous Agent Difference - AGNI sends an unsolicited AgentDataUpdate upon root agent status
953 try
846 { 954 {
847 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 955 if (gm != null)
848 pos.X = crossedBorder.BorderLine.Z - 1; 956 {
957 groupUUID = ControllingClient.ActiveGroupId;
958 GroupRecord record = gm.GetGroupRecord(groupUUID);
959 if (record != null)
960 GroupName = record.GroupName;
961 GroupMembershipData groupMembershipData = gm.GetMembershipData(groupUUID, m_uuid);
962 if (groupMembershipData != null)
963 groupPowers = groupMembershipData.GroupPowers;
964 }
965 ControllingClient.SendAgentDataUpdate(m_uuid, groupUUID, Firstname, Lastname, groupPowers, GroupName,
966 Grouptitle);
849 } 967 }
850 968 catch (Exception e)
851 if (m_scene.TestBorderCross(pos, Cardinals.N))
852 { 969 {
853 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 970 m_log.Debug("[AGENTUPDATE]: " + e.ToString());
854 pos.Y = crossedBorder.BorderLine.Z - 1;
855 } 971 }
972 // ------------------------------------
856 973
857 CheckAndAdjustLandingPoint(ref pos); 974 if (ParentID == 0)
858
859 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
860 { 975 {
861 m_log.WarnFormat( 976 // Moved this from SendInitialData to ensure that Appearance is initialized
862 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", 977 // before the inventory is processed in MakeRootAgent. This fixes a race condition
863 pos, Name, UUID); 978 // related to the handling of attachments
979 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
980 if (m_scene.TestBorderCross(pos, Cardinals.E))
981 {
982 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
983 pos.X = crossedBorder.BorderLine.Z - 1;
984 }
864 985
865 if (pos.X < 0f) pos.X = 0f; 986 if (m_scene.TestBorderCross(pos, Cardinals.N))
866 if (pos.Y < 0f) pos.Y = 0f; 987 {
867 if (pos.Z < 0f) pos.Z = 0f; 988 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
868 } 989 pos.Y = crossedBorder.BorderLine.Z - 1;
990 }
869 991
870 float localAVHeight = 1.56f; 992 CheckAndAdjustLandingPoint(ref pos);
871 if (Appearance.AvatarHeight > 0)
872 localAVHeight = Appearance.AvatarHeight;
873 993
874 float posZLimit = 0; 994 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
995 {
996 m_log.WarnFormat(
997 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
998 pos, Name, UUID);
875 999
876 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 1000 if (pos.X < 0f) pos.X = 0f;
877 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 1001 if (pos.Y < 0f) pos.Y = 0f;
878 1002 if (pos.Z < 0f) pos.Z = 0f;
879 float newPosZ = posZLimit + localAVHeight / 2; 1003 }
880 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
881 {
882 pos.Z = newPosZ;
883 }
884 AbsolutePosition = pos;
885 1004
886 AddToPhysicalScene(isFlying); 1005 float localAVHeight = 1.56f;
1006 if (Appearance.AvatarHeight > 0)
1007 localAVHeight = Appearance.AvatarHeight;
887 1008
888 if (ForceFly) 1009 float posZLimit = 0;
889 {
890 Flying = true;
891 }
892 else if (FlyDisabled)
893 {
894 Flying = false;
895 }
896 1010
1011 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
1012 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
1013
1014 float newPosZ = posZLimit + localAVHeight / 2;
1015 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
1016 {
1017 pos.Z = newPosZ;
1018 }
1019 AbsolutePosition = pos;
1020
1021 if (m_teleportFlags == TeleportFlags.Default)
1022 {
1023 Vector3 vel = Velocity;
1024 AddToPhysicalScene(isFlying);
1025 if (PhysicsActor != null)
1026 PhysicsActor.SetMomentum(vel);
1027 }
1028 else
1029 AddToPhysicalScene(isFlying);
1030
1031 if (ForceFly)
1032 {
1033 Flying = true;
1034 }
1035 else if (FlyDisabled)
1036 {
1037 Flying = false;
1038 }
1039 }
897 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 1040 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
898 // avatar to return to the standing position in mid-air. On login it looks like this is being sent 1041 // avatar to return to the standing position in mid-air. On login it looks like this is being sent
899 // elsewhere anyway 1042 // elsewhere anyway
@@ -913,14 +1056,19 @@ namespace OpenSim.Region.Framework.Scenes
913 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name); 1056 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name);
914 1057
915 // Resume scripts 1058 // Resume scripts
916 foreach (SceneObjectGroup sog in m_attachments) 1059 Util.FireAndForget(delegate(object x) {
917 { 1060 foreach (SceneObjectGroup sog in m_attachments)
918 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); 1061 {
919 sog.ResumeScripts(); 1062 sog.ScheduleGroupForFullUpdate();
920 } 1063 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
1064 sog.ResumeScripts();
1065 }
1066 });
921 } 1067 }
922 } 1068 }
923 1069
1070 SendAvatarDataToAllAgents();
1071
924 // send the animations of the other presences to me 1072 // send the animations of the other presences to me
925 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) 1073 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence)
926 { 1074 {
@@ -931,9 +1079,12 @@ namespace OpenSim.Region.Framework.Scenes
931 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will 1079 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will
932 // stall on the border crossing since the existing child agent will still have the last movement 1080 // stall on the border crossing since the existing child agent will still have the last movement
933 // recorded, which stops the input from being processed. 1081 // recorded, which stops the input from being processed.
1082
934 MovementFlag = 0; 1083 MovementFlag = 0;
935 1084
936 m_scene.EventManager.TriggerOnMakeRootAgent(this); 1085 m_scene.EventManager.TriggerOnMakeRootAgent(this);
1086
1087 m_scene.EventManager.OnRegionHeartbeatEnd += RegionHeartbeatEnd;
937 } 1088 }
938 1089
939 public int GetStateSource() 1090 public int GetStateSource()
@@ -961,12 +1112,16 @@ namespace OpenSim.Region.Framework.Scenes
961 /// </remarks> 1112 /// </remarks>
962 public void MakeChildAgent() 1113 public void MakeChildAgent()
963 { 1114 {
1115 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
1116
964 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); 1117 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName);
965 1118
966 // Reset these so that teleporting in and walking out isn't seen 1119 // Reset these so that teleporting in and walking out isn't seen
967 // as teleporting back 1120 // as teleporting back
968 TeleportFlags = TeleportFlags.Default; 1121 TeleportFlags = TeleportFlags.Default;
969 1122
1123 MovementFlag = 0;
1124
970 // It looks like Animator is set to null somewhere, and MakeChild 1125 // It looks like Animator is set to null somewhere, and MakeChild
971 // is called after that. Probably in aborted teleports. 1126 // is called after that. Probably in aborted teleports.
972 if (Animator == null) 1127 if (Animator == null)
@@ -974,6 +1129,7 @@ namespace OpenSim.Region.Framework.Scenes
974 else 1129 else
975 Animator.ResetAnimations(); 1130 Animator.ResetAnimations();
976 1131
1132
977// m_log.DebugFormat( 1133// m_log.DebugFormat(
978// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", 1134// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
979// Name, UUID, m_scene.RegionInfo.RegionName); 1135// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -985,6 +1141,7 @@ namespace OpenSim.Region.Framework.Scenes
985 IsChildAgent = true; 1141 IsChildAgent = true;
986 m_scene.SwapRootAgentCount(true); 1142 m_scene.SwapRootAgentCount(true);
987 RemoveFromPhysicalScene(); 1143 RemoveFromPhysicalScene();
1144 ParentID = 0; // Child agents can't be sitting
988 1145
989 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into 1146 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into
990 1147
@@ -1000,9 +1157,9 @@ namespace OpenSim.Region.Framework.Scenes
1000 { 1157 {
1001// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1158// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
1002 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall; 1159 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall;
1003 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1004 PhysicsActor.UnSubscribeEvents();
1005 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1160 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
1161 PhysicsActor.UnSubscribeEvents();
1162 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1006 PhysicsActor = null; 1163 PhysicsActor = null;
1007 } 1164 }
1008// else 1165// else
@@ -1019,7 +1176,7 @@ namespace OpenSim.Region.Framework.Scenes
1019 /// <param name="pos"></param> 1176 /// <param name="pos"></param>
1020 public void Teleport(Vector3 pos) 1177 public void Teleport(Vector3 pos)
1021 { 1178 {
1022 TeleportWithMomentum(pos, null); 1179 TeleportWithMomentum(pos, Vector3.Zero);
1023 } 1180 }
1024 1181
1025 public void TeleportWithMomentum(Vector3 pos, Vector3? v) 1182 public void TeleportWithMomentum(Vector3 pos, Vector3? v)
@@ -1043,6 +1200,41 @@ namespace OpenSim.Region.Framework.Scenes
1043 SendTerseUpdateToAllClients(); 1200 SendTerseUpdateToAllClients();
1044 } 1201 }
1045 1202
1203 public void avnLocalTeleport(Vector3 newpos, Vector3? newvel, bool rotateToVelXY)
1204 {
1205 CheckLandingPoint(ref newpos);
1206 AbsolutePosition = newpos;
1207
1208 if (newvel.HasValue)
1209 {
1210 if ((Vector3)newvel == Vector3.Zero)
1211 {
1212 if (PhysicsActor != null)
1213 PhysicsActor.SetMomentum(Vector3.Zero);
1214 m_velocity = Vector3.Zero;
1215 }
1216 else
1217 {
1218 if (PhysicsActor != null)
1219 PhysicsActor.SetMomentum((Vector3)newvel);
1220 m_velocity = (Vector3)newvel;
1221
1222 if (rotateToVelXY)
1223 {
1224 Vector3 lookAt = (Vector3)newvel;
1225 lookAt.Z = 0;
1226 lookAt.Normalize();
1227 ControllingClient.SendLocalTeleport(newpos, lookAt, (uint)TeleportFlags.ViaLocation);
1228 return;
1229 }
1230 }
1231 }
1232
1233 SendTerseUpdateToAllClients();
1234 }
1235
1236
1237
1046 public void StopFlying() 1238 public void StopFlying()
1047 { 1239 {
1048 ControllingClient.StopFlying(this); 1240 ControllingClient.StopFlying(this);
@@ -1212,6 +1404,13 @@ namespace OpenSim.Region.Framework.Scenes
1212 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height); 1404 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height);
1213 } 1405 }
1214 1406
1407 public void SetSize(Vector3 size, float feetoffset)
1408 {
1409 if (PhysicsActor != null && !IsChildAgent)
1410 PhysicsActor.setAvatarSize(size, feetoffset);
1411
1412 }
1413
1215 /// <summary> 1414 /// <summary>
1216 /// Complete Avatar's movement into the region. 1415 /// Complete Avatar's movement into the region.
1217 /// </summary> 1416 /// </summary>
@@ -1231,7 +1430,8 @@ namespace OpenSim.Region.Framework.Scenes
1231 1430
1232 Vector3 look = Velocity; 1431 Vector3 look = Velocity;
1233 1432
1234 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) 1433 // if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
1434 if ((Math.Abs(look.X) < 0.1) && (Math.Abs(look.Y) < 0.1) && (Math.Abs(look.Z) < 0.1))
1235 { 1435 {
1236 look = new Vector3(0.99f, 0.042f, 0); 1436 look = new Vector3(0.99f, 0.042f, 0);
1237 } 1437 }
@@ -1281,13 +1481,15 @@ namespace OpenSim.Region.Framework.Scenes
1281 // Create child agents in neighbouring regions 1481 // Create child agents in neighbouring regions
1282 if (openChildAgents && !IsChildAgent) 1482 if (openChildAgents && !IsChildAgent)
1283 { 1483 {
1484
1284 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); 1485 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
1285 if (m_agentTransfer != null) 1486 if (m_agentTransfer != null)
1286 Util.FireAndForget(delegate { m_agentTransfer.EnableChildAgents(this); }); 1487 m_agentTransfer.EnableChildAgents(this);
1287 1488
1288 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); 1489 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
1289 if (friendsModule != null) 1490 if (friendsModule != null)
1290 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); 1491 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient);
1492
1291 } 1493 }
1292 1494
1293// m_log.DebugFormat( 1495// m_log.DebugFormat(
@@ -1303,35 +1505,43 @@ namespace OpenSim.Region.Framework.Scenes
1303 /// <param name="collisionPoint"></param> 1505 /// <param name="collisionPoint"></param>
1304 /// <param name="localid"></param> 1506 /// <param name="localid"></param>
1305 /// <param name="distance"></param> 1507 /// <param name="distance"></param>
1508 ///
1509
1510 private void UpdateCameraCollisionPlane(Vector4 plane)
1511 {
1512 if (m_lastCameraCollisionPlane != plane)
1513 {
1514 m_lastCameraCollisionPlane = plane;
1515 ControllingClient.SendCameraConstraint(plane);
1516 }
1517 }
1518
1306 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) 1519 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal)
1307 { 1520 {
1308 const float POSITION_TOLERANCE = 0.02f; 1521 const float POSITION_TOLERANCE = 0.02f;
1309 const float VELOCITY_TOLERANCE = 0.02f;
1310 const float ROTATION_TOLERANCE = 0.02f; 1522 const float ROTATION_TOLERANCE = 0.02f;
1311 1523
1312 if (m_followCamAuto) 1524 m_doingCamRayCast = false;
1525 if (hitYN && localid != LocalId)
1313 { 1526 {
1314 if (hitYN) 1527 CameraConstraintActive = true;
1315 { 1528 pNormal.X = (float)Math.Round(pNormal.X, 2);
1316 CameraConstraintActive = true; 1529 pNormal.Y = (float)Math.Round(pNormal.Y, 2);
1317 //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); 1530 pNormal.Z = (float)Math.Round(pNormal.Z, 2);
1318 1531 pNormal.Normalize();
1319 Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); 1532 collisionPoint.X = (float)Math.Round(collisionPoint.X, 1);
1320 ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); 1533 collisionPoint.Y = (float)Math.Round(collisionPoint.Y, 1);
1321 } 1534 collisionPoint.Z = (float)Math.Round(collisionPoint.Z, 1);
1322 else 1535
1323 { 1536 Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z, Vector3.Dot(collisionPoint, pNormal));
1324 if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || 1537 UpdateCameraCollisionPlane(plane);
1325 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || 1538 }
1326 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) 1539 else if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
1327 { 1540 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE))
1328 if (CameraConstraintActive) 1541 {
1329 { 1542 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -9000f); // not right...
1330 ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); 1543 UpdateCameraCollisionPlane(plane);
1331 CameraConstraintActive = false; 1544 CameraConstraintActive = false;
1332 }
1333 }
1334 }
1335 } 1545 }
1336 } 1546 }
1337 1547
@@ -1406,12 +1616,6 @@ namespace OpenSim.Region.Framework.Scenes
1406 // DrawDistance = agentData.Far; 1616 // DrawDistance = agentData.Far;
1407 DrawDistance = Scene.DefaultDrawDistance; 1617 DrawDistance = Scene.DefaultDrawDistance;
1408 1618
1409 // Check if Client has camera in 'follow cam' or 'build' mode.
1410 Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation);
1411
1412 m_followCamAuto = ((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.98f)
1413 && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false;
1414
1415 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; 1619 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0;
1416 m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; 1620 m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0;
1417 1621
@@ -1431,14 +1635,38 @@ namespace OpenSim.Region.Framework.Scenes
1431 StandUp(); 1635 StandUp();
1432 } 1636 }
1433 1637
1434 //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto);
1435 // Raycast from the avatar's head to the camera to see if there's anything blocking the view 1638 // Raycast from the avatar's head to the camera to see if there's anything blocking the view
1436 if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) 1639 // this exclude checks may not be complete
1640
1641 if (m_movementUpdateCount % NumMovementsBetweenRayCast == 0 && m_scene.PhysicsScene.SupportsRayCast())
1437 { 1642 {
1438 if (m_followCamAuto) 1643 if (!m_doingCamRayCast && !m_mouseLook && ParentID == 0)
1644 {
1645 Vector3 posAdjusted = AbsolutePosition;
1646// posAdjusted.Z += 0.5f * Appearance.AvatarSize.Z - 0.5f;
1647 posAdjusted.Z += 1.0f; // viewer current camera focus point
1648 Vector3 tocam = CameraPosition - posAdjusted;
1649 tocam.X = (float)Math.Round(tocam.X, 1);
1650 tocam.Y = (float)Math.Round(tocam.Y, 1);
1651 tocam.Z = (float)Math.Round(tocam.Z, 1);
1652
1653 float distTocamlen = tocam.Length();
1654 if (distTocamlen > 0.3f)
1655 {
1656 tocam *= (1.0f / distTocamlen);
1657 posAdjusted.X = (float)Math.Round(posAdjusted.X, 1);
1658 posAdjusted.Y = (float)Math.Round(posAdjusted.Y, 1);
1659 posAdjusted.Z = (float)Math.Round(posAdjusted.Z, 1);
1660
1661 m_doingCamRayCast = true;
1662 m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback);
1663 }
1664 }
1665 else if (CameraConstraintActive && (m_mouseLook || ParentID != 0))
1439 { 1666 {
1440 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; 1667 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right...
1441 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); 1668 UpdateCameraCollisionPlane(plane);
1669 CameraConstraintActive = false;
1442 } 1670 }
1443 } 1671 }
1444 1672
@@ -1903,7 +2131,8 @@ namespace OpenSim.Region.Framework.Scenes
1903// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name); 2131// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name);
1904 2132
1905 MovingToTarget = false; 2133 MovingToTarget = false;
1906 MoveToPositionTarget = Vector3.Zero; 2134// MoveToPositionTarget = Vector3.Zero;
2135 m_forceToApply = null; // cancel possible last action
1907 2136
1908 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct 2137 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct
1909 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag. 2138 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag.
@@ -1921,12 +2150,17 @@ namespace OpenSim.Region.Framework.Scenes
1921// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); 2150// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name);
1922 2151
1923 SitGround = false; 2152 SitGround = false;
2153
2154/* move this down so avatar gets physical in the new position and not where it is siting
1924 if (PhysicsActor == null) 2155 if (PhysicsActor == null)
1925 AddToPhysicalScene(false); 2156 AddToPhysicalScene(false);
2157 */
1926 2158
1927 if (ParentID != 0) 2159 if (ParentID != 0)
1928 { 2160 {
1929 SceneObjectPart part = ParentPart; 2161 SceneObjectPart part = ParentPart;
2162 UnRegisterSeatControls(part.ParentGroup.UUID);
2163
1930 TaskInventoryDictionary taskIDict = part.TaskInventory; 2164 TaskInventoryDictionary taskIDict = part.TaskInventory;
1931 if (taskIDict != null) 2165 if (taskIDict != null)
1932 { 2166 {
@@ -1942,14 +2176,22 @@ namespace OpenSim.Region.Framework.Scenes
1942 } 2176 }
1943 } 2177 }
1944 2178
1945 ParentPosition = part.GetWorldPosition(); 2179 part.ParentGroup.DeleteAvatar(UUID);
2180// ParentPosition = part.GetWorldPosition();
1946 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 2181 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1947 2182
1948 m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight); 2183// m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
1949 ParentPosition = Vector3.Zero; 2184// ParentPosition = Vector3.Zero;
2185 m_pos = part.AbsolutePosition + (m_pos * part.GetWorldRotation()) + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
2186 if (part.SitTargetAvatar == UUID)
2187 m_bodyRot = part.GetWorldRotation() * part.SitTargetOrientation;
1950 2188
1951 ParentID = 0; 2189 ParentID = 0;
1952 ParentPart = null; 2190 ParentPart = null;
2191
2192 if (PhysicsActor == null)
2193 AddToPhysicalScene(false);
2194
1953 SendAvatarDataToAllAgents(); 2195 SendAvatarDataToAllAgents();
1954 m_requestedSitTargetID = 0; 2196 m_requestedSitTargetID = 0;
1955 2197
@@ -1959,6 +2201,9 @@ namespace OpenSim.Region.Framework.Scenes
1959 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 2201 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
1960 } 2202 }
1961 2203
2204 else if (PhysicsActor == null)
2205 AddToPhysicalScene(false);
2206
1962 Animator.TrySetMovementAnimation("STAND"); 2207 Animator.TrySetMovementAnimation("STAND");
1963 } 2208 }
1964 2209
@@ -2006,11 +2251,8 @@ namespace OpenSim.Region.Framework.Scenes
2006 if (part == null) 2251 if (part == null)
2007 return; 2252 return;
2008 2253
2009 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
2010 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
2011
2012 if (PhysicsActor != null) 2254 if (PhysicsActor != null)
2013 m_sitAvatarHeight = PhysicsActor.Size.Z; 2255 m_sitAvatarHeight = PhysicsActor.Size.Z * 0.5f;
2014 2256
2015 bool canSit = false; 2257 bool canSit = false;
2016 Vector3 pos = part.AbsolutePosition + offset; 2258 Vector3 pos = part.AbsolutePosition + offset;
@@ -2027,31 +2269,31 @@ namespace OpenSim.Region.Framework.Scenes
2027 } 2269 }
2028 else 2270 else
2029 { 2271 {
2272 if (PhysicsSit(part,offset)) // physics engine
2273 return;
2274
2030 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10) 2275 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10)
2031 { 2276 {
2032// m_log.DebugFormat(
2033// "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is unset and within 10m",
2034// Name, part.Name, part.LocalId);
2035 2277
2036 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 2278 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
2037 canSit = true; 2279 canSit = true;
2038 } 2280 }
2039// else
2040// {
2041// m_log.DebugFormat(
2042// "[SCENE PRESENCE]: Ignoring sit request of {0} on {1} {2} because sit target is unset and outside 10m",
2043// Name, part.Name, part.LocalId);
2044// }
2045 } 2281 }
2046 2282
2047 if (canSit) 2283 if (canSit)
2048 { 2284 {
2285
2049 if (PhysicsActor != null) 2286 if (PhysicsActor != null)
2050 { 2287 {
2051 // We can remove the physicsActor until they stand up. 2288 // We can remove the physicsActor until they stand up.
2052 RemoveFromPhysicalScene(); 2289 RemoveFromPhysicalScene();
2053 } 2290 }
2054 2291
2292 if (MovingToTarget)
2293 ResetMoveToTarget();
2294
2295 Velocity = Vector3.Zero;
2296
2055 part.AddSittingAvatar(UUID); 2297 part.AddSittingAvatar(UUID);
2056 2298
2057 cameraAtOffset = part.GetCameraAtOffset(); 2299 cameraAtOffset = part.GetCameraAtOffset();
@@ -2059,7 +2301,7 @@ namespace OpenSim.Region.Framework.Scenes
2059 forceMouselook = part.GetForceMouselook(); 2301 forceMouselook = part.GetForceMouselook();
2060 2302
2061 ControllingClient.SendSitResponse( 2303 ControllingClient.SendSitResponse(
2062 targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 2304 part.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
2063 2305
2064 m_requestedSitTargetUUID = targetID; 2306 m_requestedSitTargetUUID = targetID;
2065 2307
@@ -2073,6 +2315,9 @@ namespace OpenSim.Region.Framework.Scenes
2073 2315
2074 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) 2316 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset)
2075 { 2317 {
2318 if (IsChildAgent)
2319 return;
2320
2076 if (ParentID != 0) 2321 if (ParentID != 0)
2077 { 2322 {
2078 if (ParentPart.UUID == targetID) 2323 if (ParentPart.UUID == targetID)
@@ -2088,14 +2333,6 @@ namespace OpenSim.Region.Framework.Scenes
2088 m_requestedSitTargetID = part.LocalId; 2333 m_requestedSitTargetID = part.LocalId;
2089 m_requestedSitTargetUUID = targetID; 2334 m_requestedSitTargetUUID = targetID;
2090 2335
2091// m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset);
2092
2093 if (m_scene.PhysicsScene.SupportsRayCast())
2094 {
2095 //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback());
2096 //SitRayCastAvatarPosition(part);
2097 //return;
2098 }
2099 } 2336 }
2100 else 2337 else
2101 { 2338 {
@@ -2105,197 +2342,111 @@ namespace OpenSim.Region.Framework.Scenes
2105 SendSitResponse(targetID, offset, Quaternion.Identity); 2342 SendSitResponse(targetID, offset, Quaternion.Identity);
2106 } 2343 }
2107 2344
2108 /* 2345 // returns false if does not suport so older sit can be tried
2109 public void SitRayCastAvatarPosition(SceneObjectPart part) 2346 public bool PhysicsSit(SceneObjectPart part, Vector3 offset)
2110 { 2347 {
2111 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2348 if (part == null || part.ParentGroup.IsAttachment)
2112 Vector3 StartRayCastPosition = AbsolutePosition;
2113 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2114 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2115 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionResponse);
2116 }
2117
2118 public void SitRayCastAvatarPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal)
2119 {
2120 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2121 if (part != null)
2122 {
2123 if (hitYN)
2124 {
2125 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2126 {
2127 SitRaycastFindEdge(collisionPoint, normal);
2128 m_log.DebugFormat("[SIT]: Raycast Avatar Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2129 }
2130 else
2131 {
2132 SitRayCastAvatarPositionCameraZ(part);
2133 }
2134 }
2135 else
2136 {
2137 SitRayCastAvatarPositionCameraZ(part);
2138 }
2139 }
2140 else
2141 { 2349 {
2142 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2350 return true;
2143 m_requestedSitTargetUUID = UUID.Zero;
2144 m_requestedSitTargetID = 0;
2145 m_requestedSitOffset = Vector3.Zero;
2146 } 2351 }
2147 2352
2148 } 2353 if ( m_scene.PhysicsScene == null)
2354 return false;
2149 2355
2150 public void SitRayCastAvatarPositionCameraZ(SceneObjectPart part) 2356 if (part.PhysActor == null)
2151 {
2152 // Next, try to raycast from the camera Z position
2153 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2154 Vector3 StartRayCastPosition = AbsolutePosition; StartRayCastPosition.Z = CameraPosition.Z;
2155 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2156 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2157 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionCameraZResponse);
2158 }
2159
2160 public void SitRayCastAvatarPositionCameraZResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal)
2161 {
2162 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2163 if (part != null)
2164 { 2357 {
2165 if (hitYN) 2358 // none physcis shape
2166 { 2359 if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
2167 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) 2360 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2168 {
2169 SitRaycastFindEdge(collisionPoint, normal);
2170 m_log.DebugFormat("[SIT]: Raycast Avatar Position + CameraZ succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2171 }
2172 else
2173 {
2174 SitRayCastCameraPosition(part);
2175 }
2176 }
2177 else 2361 else
2178 { 2362 { // non physical phantom TODO
2179 SitRayCastCameraPosition(part); 2363 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2364 return false;
2180 } 2365 }
2181 } 2366 return true;
2182 else
2183 {
2184 ControllingClient.SendAlertMessage("Sit position no longer exists");
2185 m_requestedSitTargetUUID = UUID.Zero;
2186 m_requestedSitTargetID = 0;
2187 m_requestedSitOffset = Vector3.Zero;
2188 } 2367 }
2189 2368
2190 }
2191 2369
2192 public void SitRayCastCameraPosition(SceneObjectPart part) 2370 // not doing autopilot
2193 { 2371 m_requestedSitTargetID = 0;
2194 // Next, try to raycast from the camera position
2195 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2196 Vector3 StartRayCastPosition = CameraPosition;
2197 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2198 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2199 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastCameraPositionResponse);
2200 }
2201 2372
2202 public void SitRayCastCameraPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2373 if (m_scene.PhysicsScene.SitAvatar(part.PhysActor, AbsolutePosition, CameraPosition, offset, new Vector3(0.35f, 0, 0.65f), PhysicsSitResponse) != 0)
2203 { 2374 return true;
2204 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2205 if (part != null)
2206 {
2207 if (hitYN)
2208 {
2209 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2210 {
2211 SitRaycastFindEdge(collisionPoint, normal);
2212 m_log.DebugFormat("[SIT]: Raycast Camera Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2213 }
2214 else
2215 {
2216 SitRayHorizontal(part);
2217 }
2218 }
2219 else
2220 {
2221 SitRayHorizontal(part);
2222 }
2223 }
2224 else
2225 {
2226 ControllingClient.SendAlertMessage("Sit position no longer exists");
2227 m_requestedSitTargetUUID = UUID.Zero;
2228 m_requestedSitTargetID = 0;
2229 m_requestedSitOffset = Vector3.Zero;
2230 }
2231 2375
2376 return false;
2232 } 2377 }
2233 2378
2234 public void SitRayHorizontal(SceneObjectPart part) 2379
2380 private bool CanEnterLandPosition(Vector3 testPos)
2235 { 2381 {
2236 // Next, try to raycast from the avatar position to fwd 2382 ILandObject land = m_scene.LandChannel.GetLandObject(testPos.X, testPos.Y);
2237 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2383
2238 Vector3 StartRayCastPosition = CameraPosition; 2384 if (land == null || land.LandData.Name == "NO_LAND")
2239 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); 2385 return true;
2240 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); 2386
2241 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastHorizontalResponse); 2387 return land.CanBeOnThisLand(UUID,testPos.Z);
2242 } 2388 }
2243 2389
2244 public void SitRayCastHorizontalResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2390 // status
2391 // < 0 ignore
2392 // 0 bad sit spot
2393 public void PhysicsSitResponse(int status, uint partID, Vector3 offset, Quaternion Orientation)
2245 { 2394 {
2246 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); 2395 if (status < 0)
2247 if (part != null) 2396 return;
2397
2398 if (status == 0)
2248 { 2399 {
2249 if (hitYN) 2400 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2250 { 2401 return;
2251 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2252 {
2253 SitRaycastFindEdge(collisionPoint, normal);
2254 m_log.DebugFormat("[SIT]: Raycast Horizontal Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2255 // Next, try to raycast from the camera position
2256 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2257 Vector3 StartRayCastPosition = CameraPosition;
2258 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2259 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2260 //m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastResponseAvatarPosition);
2261 }
2262 else
2263 {
2264 ControllingClient.SendAlertMessage("Sit position not accessable.");
2265 m_requestedSitTargetUUID = UUID.Zero;
2266 m_requestedSitTargetID = 0;
2267 m_requestedSitOffset = Vector3.Zero;
2268 }
2269 }
2270 else
2271 {
2272 ControllingClient.SendAlertMessage("Sit position not accessable.");
2273 m_requestedSitTargetUUID = UUID.Zero;
2274 m_requestedSitTargetID = 0;
2275 m_requestedSitOffset = Vector3.Zero;
2276 }
2277 } 2402 }
2278 else 2403
2404 SceneObjectPart part = m_scene.GetSceneObjectPart(partID);
2405 if (part == null)
2406 return;
2407
2408 Vector3 targetPos = part.GetWorldPosition() + offset * part.GetWorldRotation();
2409 if(!CanEnterLandPosition(targetPos))
2279 { 2410 {
2280 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2411 ControllingClient.SendAlertMessage(" Sit position on restricted land, try another spot");
2281 m_requestedSitTargetUUID = UUID.Zero; 2412 return;
2282 m_requestedSitTargetID = 0;
2283 m_requestedSitOffset = Vector3.Zero;
2284 } 2413 }
2285 2414
2286 } 2415 RemoveFromPhysicalScene();
2287 2416
2288 private void SitRaycastFindEdge(Vector3 collisionPoint, Vector3 collisionNormal) 2417 if (MovingToTarget)
2289 { 2418 ResetMoveToTarget();
2290 int i = 0; 2419
2291 //throw new NotImplementedException(); 2420 Velocity = Vector3.Zero;
2292 //m_requestedSitTargetUUID = UUID.Zero; 2421
2293 //m_requestedSitTargetID = 0; 2422 part.AddSittingAvatar(UUID);
2294 //m_requestedSitOffset = Vector3.Zero;
2295 2423
2296 SendSitResponse(ControllingClient, m_requestedSitTargetUUID, collisionPoint - m_requestedSitOffset, Quaternion.Identity); 2424 Vector3 cameraAtOffset = part.GetCameraAtOffset();
2425 Vector3 cameraEyeOffset = part.GetCameraEyeOffset();
2426 bool forceMouselook = part.GetForceMouselook();
2427
2428 ControllingClient.SendSitResponse(
2429 part.UUID, offset, Orientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
2430
2431 // not using autopilot
2432
2433 Rotation = Orientation;
2434 m_pos = offset;
2435
2436 m_requestedSitTargetID = 0;
2437 part.ParentGroup.AddAvatar(UUID);
2438
2439 ParentPart = part;
2440 ParentID = part.LocalId;
2441 if(status == 3)
2442 Animator.TrySetMovementAnimation("SIT_GROUND");
2443 else
2444 Animator.TrySetMovementAnimation("SIT");
2445 SendAvatarDataToAllAgents();
2446
2447 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2297 } 2448 }
2298 */ 2449
2299 2450
2300 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) 2451 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID)
2301 { 2452 {
@@ -2312,6 +2463,7 @@ namespace OpenSim.Region.Framework.Scenes
2312 return; 2463 return;
2313 } 2464 }
2314 2465
2466
2315 if (part.SitTargetAvatar == UUID) 2467 if (part.SitTargetAvatar == UUID)
2316 { 2468 {
2317 Vector3 sitTargetPos = part.SitTargetPosition; 2469 Vector3 sitTargetPos = part.SitTargetPosition;
@@ -2326,14 +2478,39 @@ namespace OpenSim.Region.Framework.Scenes
2326 2478
2327 //Quaternion result = (sitTargetOrient * vq) * nq; 2479 //Quaternion result = (sitTargetOrient * vq) * nq;
2328 2480
2329 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2481 double x, y, z, m;
2482
2483 Quaternion r = sitTargetOrient;
2484 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2485
2486 if (Math.Abs(1.0 - m) > 0.000001)
2487 {
2488 m = 1.0 / Math.Sqrt(m);
2489 r.X *= (float)m;
2490 r.Y *= (float)m;
2491 r.Z *= (float)m;
2492 r.W *= (float)m;
2493 }
2494
2495 x = 2 * (r.X * r.Z + r.Y * r.W);
2496 y = 2 * (-r.X * r.W + r.Y * r.Z);
2497 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2498
2499 Vector3 up = new Vector3((float)x, (float)y, (float)z);
2500 Vector3 sitOffset = up * Appearance.AvatarHeight * 0.02638f;
2501
2502 m_pos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT;
2503
2504// m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT - sitOffset;
2330 Rotation = sitTargetOrient; 2505 Rotation = sitTargetOrient;
2331 ParentPosition = part.AbsolutePosition; 2506// ParentPosition = part.AbsolutePosition;
2507 part.ParentGroup.AddAvatar(UUID);
2332 } 2508 }
2333 else 2509 else
2334 { 2510 {
2335 m_pos -= part.AbsolutePosition; 2511 m_pos -= part.AbsolutePosition;
2336 ParentPosition = part.AbsolutePosition; 2512// ParentPosition = part.AbsolutePosition;
2513 part.ParentGroup.AddAvatar(UUID);
2337 2514
2338// m_log.DebugFormat( 2515// m_log.DebugFormat(
2339// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2516// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -2384,6 +2561,13 @@ namespace OpenSim.Region.Framework.Scenes
2384 Animator.RemoveAnimation(animID, false); 2561 Animator.RemoveAnimation(animID, false);
2385 } 2562 }
2386 2563
2564 public void avnHandleChangeAnim(UUID animID, bool addRemove,bool sendPack)
2565 {
2566 Animator.avnChangeAnim(animID, addRemove, sendPack);
2567 }
2568
2569
2570
2387 /// <summary> 2571 /// <summary>
2388 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector 2572 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
2389 /// </summary> 2573 /// </summary>
@@ -2437,14 +2621,15 @@ namespace OpenSim.Region.Framework.Scenes
2437 direc.Z *= 2.6f; 2621 direc.Z *= 2.6f;
2438 2622
2439 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2623 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
2440 Animator.TrySetMovementAnimation("PREJUMP"); 2624// Animator.TrySetMovementAnimation("PREJUMP");
2441 Animator.TrySetMovementAnimation("JUMP"); 2625// Animator.TrySetMovementAnimation("JUMP");
2442 } 2626 }
2443 } 2627 }
2444 } 2628 }
2445 2629
2446 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2630 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2447 m_forceToApply = direc; 2631 m_forceToApply = direc;
2632 Animator.UpdateMovementAnimations();
2448 } 2633 }
2449 2634
2450 #endregion 2635 #endregion
@@ -2462,16 +2647,12 @@ namespace OpenSim.Region.Framework.Scenes
2462 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to 2647 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to
2463 // grab the latest PhysicsActor velocity, whereas m_velocity is often 2648 // grab the latest PhysicsActor velocity, whereas m_velocity is often
2464 // storing a requested force instead of an actual traveling velocity 2649 // storing a requested force instead of an actual traveling velocity
2650 if (Appearance.AvatarSize != m_lastSize && !IsLoggingIn)
2651 SendAvatarDataToAllAgents();
2465 2652
2466 // Throw away duplicate or insignificant updates 2653 if (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||
2467 if ( 2654 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
2468 // If the velocity has become zero, send it no matter what. 2655 !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))
2469 (Velocity != m_lastVelocity && Velocity == Vector3.Zero)
2470 // otherwise, if things have changed reasonably, send the update
2471 || (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)
2472 || !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE)
2473 || !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)))
2474
2475 { 2656 {
2476 SendTerseUpdateToAllClients(); 2657 SendTerseUpdateToAllClients();
2477 2658
@@ -2660,6 +2841,8 @@ namespace OpenSim.Region.Framework.Scenes
2660 return; 2841 return;
2661 } 2842 }
2662 2843
2844 m_lastSize = Appearance.AvatarSize;
2845
2663 int count = 0; 2846 int count = 0;
2664 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) 2847 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
2665 { 2848 {
@@ -2767,6 +2950,8 @@ namespace OpenSim.Region.Framework.Scenes
2767 2950
2768 avatar.ControllingClient.SendAppearance( 2951 avatar.ControllingClient.SendAppearance(
2769 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes()); 2952 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes());
2953
2954
2770 } 2955 }
2771 2956
2772 #endregion 2957 #endregion
@@ -2841,8 +3026,9 @@ namespace OpenSim.Region.Framework.Scenes
2841 3026
2842 // If we don't have a PhysActor, we can't cross anyway 3027 // If we don't have a PhysActor, we can't cross anyway
2843 // Also don't do this while sat, sitting avatars cross with the 3028 // Also don't do this while sat, sitting avatars cross with the
2844 // object they sit on. 3029 // object they sit on. ParentUUID denoted a pending sit, don't
2845 if (ParentID != 0 || PhysicsActor == null) 3030 // interfere with it.
3031 if (ParentID != 0 || PhysicsActor == null || ParentUUID != UUID.Zero)
2846 return; 3032 return;
2847 3033
2848 if (!IsInTransit) 3034 if (!IsInTransit)
@@ -3103,6 +3289,10 @@ namespace OpenSim.Region.Framework.Scenes
3103 } 3289 }
3104 3290
3105 private static Vector3 marker = new Vector3(-1f, -1f, -1f); 3291 private static Vector3 marker = new Vector3(-1f, -1f, -1f);
3292 private void RaiseUpdateThrottles()
3293 {
3294 m_scene.EventManager.TriggerThrottleUpdate(this);
3295 }
3106 /// <summary> 3296 /// <summary>
3107 /// This updates important decision making data about a child agent 3297 /// This updates important decision making data about a child agent
3108 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region 3298 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region
@@ -3183,6 +3373,9 @@ namespace OpenSim.Region.Framework.Scenes
3183 cAgent.AlwaysRun = SetAlwaysRun; 3373 cAgent.AlwaysRun = SetAlwaysRun;
3184 3374
3185 cAgent.Appearance = new AvatarAppearance(Appearance); 3375 cAgent.Appearance = new AvatarAppearance(Appearance);
3376
3377 cAgent.ParentPart = ParentUUID;
3378 cAgent.SitOffset = m_pos;
3186 3379
3187 lock (scriptedcontrols) 3380 lock (scriptedcontrols)
3188 { 3381 {
@@ -3191,7 +3384,7 @@ namespace OpenSim.Region.Framework.Scenes
3191 3384
3192 foreach (ScriptControllers c in scriptedcontrols.Values) 3385 foreach (ScriptControllers c in scriptedcontrols.Values)
3193 { 3386 {
3194 controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); 3387 controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
3195 } 3388 }
3196 cAgent.Controllers = controls; 3389 cAgent.Controllers = controls;
3197 } 3390 }
@@ -3224,6 +3417,8 @@ namespace OpenSim.Region.Framework.Scenes
3224 CameraAtAxis = cAgent.AtAxis; 3417 CameraAtAxis = cAgent.AtAxis;
3225 CameraLeftAxis = cAgent.LeftAxis; 3418 CameraLeftAxis = cAgent.LeftAxis;
3226 CameraUpAxis = cAgent.UpAxis; 3419 CameraUpAxis = cAgent.UpAxis;
3420 ParentUUID = cAgent.ParentPart;
3421 m_prevSitOffset = cAgent.SitOffset;
3227 3422
3228 // When we get to the point of re-computing neighbors everytime this 3423 // When we get to the point of re-computing neighbors everytime this
3229 // changes, then start using the agent's drawdistance rather than the 3424 // changes, then start using the agent's drawdistance rather than the
@@ -3261,6 +3456,7 @@ namespace OpenSim.Region.Framework.Scenes
3261 foreach (ControllerData c in cAgent.Controllers) 3456 foreach (ControllerData c in cAgent.Controllers)
3262 { 3457 {
3263 ScriptControllers sc = new ScriptControllers(); 3458 ScriptControllers sc = new ScriptControllers();
3459 sc.objectID = c.ObjectID;
3264 sc.itemID = c.ItemID; 3460 sc.itemID = c.ItemID;
3265 sc.ignoreControls = (ScriptControlled)c.IgnoreControls; 3461 sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
3266 sc.eventControls = (ScriptControlled)c.EventControls; 3462 sc.eventControls = (ScriptControlled)c.EventControls;
@@ -3328,20 +3524,27 @@ namespace OpenSim.Region.Framework.Scenes
3328 } 3524 }
3329 3525
3330 if (Appearance.AvatarHeight == 0) 3526 if (Appearance.AvatarHeight == 0)
3331 Appearance.SetHeight(); 3527// Appearance.SetHeight();
3528 Appearance.SetSize(new Vector3(0.45f,0.6f,1.9f));
3332 3529
3333 PhysicsScene scene = m_scene.PhysicsScene; 3530 PhysicsScene scene = m_scene.PhysicsScene;
3334 3531
3335 Vector3 pVec = AbsolutePosition; 3532 Vector3 pVec = AbsolutePosition;
3336 3533
3534/*
3337 PhysicsActor = scene.AddAvatar( 3535 PhysicsActor = scene.AddAvatar(
3338 LocalId, Firstname + "." + Lastname, pVec, 3536 LocalId, Firstname + "." + Lastname, pVec,
3339 new Vector3(0f, 0f, Appearance.AvatarHeight), isFlying); 3537 new Vector3(0.45f, 0.6f, Appearance.AvatarHeight), isFlying);
3538*/
3539
3540 PhysicsActor = scene.AddAvatar(
3541 LocalId, Firstname + "." + Lastname, pVec,
3542 Appearance.AvatarBoxSize,Appearance.AvatarFeetOffset, isFlying);
3340 3543
3341 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3544 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3342 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3545 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
3343 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong 3546 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
3344 PhysicsActor.SubscribeEvents(500); 3547 PhysicsActor.SubscribeEvents(100);
3345 PhysicsActor.LocalID = LocalId; 3548 PhysicsActor.LocalID = LocalId;
3346 } 3549 }
3347 3550
@@ -3355,6 +3558,7 @@ namespace OpenSim.Region.Framework.Scenes
3355 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); 3558 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true);
3356 } 3559 }
3357 3560
3561
3358 /// <summary> 3562 /// <summary>
3359 /// Event called by the physics plugin to tell the avatar about a collision. 3563 /// Event called by the physics plugin to tell the avatar about a collision.
3360 /// </summary> 3564 /// </summary>
@@ -3368,7 +3572,7 @@ namespace OpenSim.Region.Framework.Scenes
3368 /// <param name="e"></param> 3572 /// <param name="e"></param>
3369 public void PhysicsCollisionUpdate(EventArgs e) 3573 public void PhysicsCollisionUpdate(EventArgs e)
3370 { 3574 {
3371 if (IsChildAgent) 3575 if (IsChildAgent || Animator == null)
3372 return; 3576 return;
3373 3577
3374 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3578 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
@@ -3384,7 +3588,6 @@ namespace OpenSim.Region.Framework.Scenes
3384 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3588 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3385 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3589 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3386 3590
3387 CollisionPlane = Vector4.UnitW;
3388 3591
3389// // No collisions at all means we may be flying. Update always 3592// // No collisions at all means we may be flying. Update always
3390// // to make falling work 3593// // to make falling work
@@ -3396,6 +3599,7 @@ namespace OpenSim.Region.Framework.Scenes
3396 3599
3397 if (coldata.Count != 0) 3600 if (coldata.Count != 0)
3398 { 3601 {
3602/*
3399 switch (Animator.CurrentMovementAnimation) 3603 switch (Animator.CurrentMovementAnimation)
3400 { 3604 {
3401 case "STAND": 3605 case "STAND":
@@ -3404,24 +3608,38 @@ namespace OpenSim.Region.Framework.Scenes
3404 case "CROUCH": 3608 case "CROUCH":
3405 case "CROUCHWALK": 3609 case "CROUCHWALK":
3406 { 3610 {
3611 */
3407 ContactPoint lowest; 3612 ContactPoint lowest;
3408 lowest.SurfaceNormal = Vector3.Zero; 3613 lowest.SurfaceNormal = Vector3.Zero;
3409 lowest.Position = Vector3.Zero; 3614 lowest.Position = Vector3.Zero;
3410 lowest.Position.Z = Single.NaN; 3615 lowest.Position.Z = float.MaxValue;
3411 3616
3412 foreach (ContactPoint contact in coldata.Values) 3617 foreach (ContactPoint contact in coldata.Values)
3413 { 3618 {
3414 if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z) 3619
3620 if (contact.CharacterFeet && contact.Position.Z < lowest.Position.Z)
3415 { 3621 {
3416 lowest = contact; 3622 lowest = contact;
3417 } 3623 }
3418 } 3624 }
3419 3625
3420 CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal)); 3626 if (lowest.Position.Z != float.MaxValue)
3627 {
3628 lowest.SurfaceNormal = -lowest.SurfaceNormal;
3629 CollisionPlane = new Vector4(lowest.SurfaceNormal, Vector3.Dot(lowest.Position, lowest.SurfaceNormal));
3630 }
3631 else
3632 CollisionPlane = Vector4.UnitW;
3633/*
3421 } 3634 }
3422 break; 3635 break;
3423 } 3636 }
3637*/
3424 } 3638 }
3639 else
3640 CollisionPlane = Vector4.UnitW;
3641
3642 RaiseCollisionScriptEvents(coldata);
3425 3643
3426 // Gods do not take damage and Invulnerable is set depending on parcel/region flags 3644 // Gods do not take damage and Invulnerable is set depending on parcel/region flags
3427 if (Invulnerable || GodLevel > 0) 3645 if (Invulnerable || GodLevel > 0)
@@ -3520,6 +3738,13 @@ namespace OpenSim.Region.Framework.Scenes
3520 // m_reprioritizationTimer.Dispose(); 3738 // m_reprioritizationTimer.Dispose();
3521 3739
3522 RemoveFromPhysicalScene(); 3740 RemoveFromPhysicalScene();
3741
3742 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
3743
3744// if (Animator != null)
3745// Animator.Close();
3746 Animator = null;
3747
3523 } 3748 }
3524 3749
3525 public void AddAttachment(SceneObjectGroup gobj) 3750 public void AddAttachment(SceneObjectGroup gobj)
@@ -3753,10 +3978,18 @@ namespace OpenSim.Region.Framework.Scenes
3753 3978
3754 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 3979 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
3755 { 3980 {
3981 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID);
3982 if (p == null)
3983 return;
3984
3985 ControllingClient.SendTakeControls(controls, false, false);
3986 ControllingClient.SendTakeControls(controls, true, false);
3987
3756 ScriptControllers obj = new ScriptControllers(); 3988 ScriptControllers obj = new ScriptControllers();
3757 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 3989 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
3758 obj.eventControls = ScriptControlled.CONTROL_ZERO; 3990 obj.eventControls = ScriptControlled.CONTROL_ZERO;
3759 3991
3992 obj.objectID = p.ParentGroup.UUID;
3760 obj.itemID = Script_item_UUID; 3993 obj.itemID = Script_item_UUID;
3761 if (pass_on == 0 && accept == 0) 3994 if (pass_on == 0 && accept == 0)
3762 { 3995 {
@@ -3805,6 +4038,21 @@ namespace OpenSim.Region.Framework.Scenes
3805 ControllingClient.SendTakeControls(int.MaxValue, false, false); 4038 ControllingClient.SendTakeControls(int.MaxValue, false, false);
3806 } 4039 }
3807 4040
4041 private void UnRegisterSeatControls(UUID obj)
4042 {
4043 List<UUID> takers = new List<UUID>();
4044
4045 foreach (ScriptControllers c in scriptedcontrols.Values)
4046 {
4047 if (c.objectID == obj)
4048 takers.Add(c.itemID);
4049 }
4050 foreach (UUID t in takers)
4051 {
4052 UnRegisterControlEventsToScript(0, t);
4053 }
4054 }
4055
3808 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 4056 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
3809 { 4057 {
3810 ScriptControllers takecontrols; 4058 ScriptControllers takecontrols;
@@ -4134,6 +4382,12 @@ namespace OpenSim.Region.Framework.Scenes
4134 4382
4135 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4383 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
4136 { 4384 {
4385 string reason;
4386
4387 // Honor bans
4388 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
4389 return;
4390
4137 SceneObjectGroup telehub = null; 4391 SceneObjectGroup telehub = null;
4138 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 4392 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
4139 { 4393 {
@@ -4173,11 +4427,206 @@ namespace OpenSim.Region.Framework.Scenes
4173 pos = land.LandData.UserLocation; 4427 pos = land.LandData.UserLocation;
4174 } 4428 }
4175 } 4429 }
4176 4430
4177 land.SendLandUpdateToClient(ControllingClient); 4431 land.SendLandUpdateToClient(ControllingClient);
4178 } 4432 }
4179 } 4433 }
4180 4434
4435 private DetectedObject CreateDetObject(SceneObjectPart obj)
4436 {
4437 DetectedObject detobj = new DetectedObject();
4438 detobj.keyUUID = obj.UUID;
4439 detobj.nameStr = obj.Name;
4440 detobj.ownerUUID = obj.OwnerID;
4441 detobj.posVector = obj.AbsolutePosition;
4442 detobj.rotQuat = obj.GetWorldRotation();
4443 detobj.velVector = obj.Velocity;
4444 detobj.colliderType = 0;
4445 detobj.groupUUID = obj.GroupID;
4446
4447 return detobj;
4448 }
4449
4450 private DetectedObject CreateDetObject(ScenePresence av)
4451 {
4452 DetectedObject detobj = new DetectedObject();
4453 detobj.keyUUID = av.UUID;
4454 detobj.nameStr = av.ControllingClient.Name;
4455 detobj.ownerUUID = av.UUID;
4456 detobj.posVector = av.AbsolutePosition;
4457 detobj.rotQuat = av.Rotation;
4458 detobj.velVector = av.Velocity;
4459 detobj.colliderType = 0;
4460 detobj.groupUUID = av.ControllingClient.ActiveGroupId;
4461
4462 return detobj;
4463 }
4464
4465 private DetectedObject CreateDetObjectForGround()
4466 {
4467 DetectedObject detobj = new DetectedObject();
4468 detobj.keyUUID = UUID.Zero;
4469 detobj.nameStr = "";
4470 detobj.ownerUUID = UUID.Zero;
4471 detobj.posVector = AbsolutePosition;
4472 detobj.rotQuat = Quaternion.Identity;
4473 detobj.velVector = Vector3.Zero;
4474 detobj.colliderType = 0;
4475 detobj.groupUUID = UUID.Zero;
4476
4477 return detobj;
4478 }
4479
4480 private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
4481 {
4482 ColliderArgs colliderArgs = new ColliderArgs();
4483 List<DetectedObject> colliding = new List<DetectedObject>();
4484 foreach (uint localId in colliders)
4485 {
4486 if (localId == 0)
4487 continue;
4488
4489 SceneObjectPart obj = m_scene.GetSceneObjectPart(localId);
4490 if (obj != null)
4491 {
4492 if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
4493 colliding.Add(CreateDetObject(obj));
4494 }
4495 else
4496 {
4497 ScenePresence av = m_scene.GetScenePresence(localId);
4498 if (av != null && (!av.IsChildAgent))
4499 {
4500 if (!dest.CollisionFilteredOut(av.UUID, av.Name))
4501 colliding.Add(CreateDetObject(av));
4502 }
4503 }
4504 }
4505
4506 colliderArgs.Colliders = colliding;
4507
4508 return colliderArgs;
4509 }
4510
4511 private delegate void ScriptCollidingNotification(uint localID, ColliderArgs message);
4512
4513 private void SendCollisionEvent(SceneObjectGroup dest, scriptEvents ev, List<uint> colliders, ScriptCollidingNotification notify)
4514 {
4515 ColliderArgs CollidingMessage;
4516
4517 if (colliders.Count > 0)
4518 {
4519 if ((dest.RootPart.ScriptEvents & ev) != 0)
4520 {
4521 CollidingMessage = CreateColliderArgs(dest.RootPart, colliders);
4522
4523 if (CollidingMessage.Colliders.Count > 0)
4524 notify(dest.RootPart.LocalId, CollidingMessage);
4525 }
4526 }
4527 }
4528
4529 private void SendLandCollisionEvent(SceneObjectGroup dest, scriptEvents ev, ScriptCollidingNotification notify)
4530 {
4531 if ((dest.RootPart.ScriptEvents & ev) != 0)
4532 {
4533 ColliderArgs LandCollidingMessage = new ColliderArgs();
4534 List<DetectedObject> colliding = new List<DetectedObject>();
4535
4536 colliding.Add(CreateDetObjectForGround());
4537 LandCollidingMessage.Colliders = colliding;
4538
4539 notify(dest.RootPart.LocalId, LandCollidingMessage);
4540 }
4541 }
4542
4543 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4544 {
4545 try
4546 {
4547 List<uint> thisHitColliders = new List<uint>();
4548 List<uint> endedColliders = new List<uint>();
4549 List<uint> startedColliders = new List<uint>();
4550 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
4551 CollisionForSoundInfo soundinfo;
4552 ContactPoint curcontact;
4553
4554 if (coldata.Count == 0)
4555 {
4556 if (m_lastColliders.Count == 0)
4557 return; // nothing to do
4558
4559 foreach (uint localID in m_lastColliders)
4560 {
4561 endedColliders.Add(localID);
4562 }
4563 m_lastColliders.Clear();
4564 }
4565
4566 else
4567 {
4568 foreach (uint id in coldata.Keys)
4569 {
4570 thisHitColliders.Add(id);
4571 if (!m_lastColliders.Contains(id))
4572 {
4573 startedColliders.Add(id);
4574 curcontact = coldata[id];
4575 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
4576 {
4577 soundinfo = new CollisionForSoundInfo();
4578 soundinfo.colliderID = id;
4579 soundinfo.position = curcontact.Position;
4580 soundinfo.relativeVel = curcontact.RelativeSpeed;
4581 soundinfolist.Add(soundinfo);
4582 }
4583 }
4584 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4585 }
4586
4587 // calculate things that ended colliding
4588 foreach (uint localID in m_lastColliders)
4589 {
4590 if (!thisHitColliders.Contains(localID))
4591 {
4592 endedColliders.Add(localID);
4593 }
4594 }
4595 //add the items that started colliding this time to the last colliders list.
4596 foreach (uint localID in startedColliders)
4597 {
4598 m_lastColliders.Add(localID);
4599 }
4600 // remove things that ended colliding from the last colliders list
4601 foreach (uint localID in endedColliders)
4602 {
4603 m_lastColliders.Remove(localID);
4604 }
4605
4606 if (soundinfolist.Count > 0)
4607 CollisionSounds.AvatarCollisionSound(this, soundinfolist);
4608 }
4609
4610 foreach (SceneObjectGroup att in GetAttachments())
4611 {
4612 SendCollisionEvent(att, scriptEvents.collision_start, startedColliders, m_scene.EventManager.TriggerScriptCollidingStart);
4613 SendCollisionEvent(att, scriptEvents.collision , m_lastColliders , m_scene.EventManager.TriggerScriptColliding);
4614 SendCollisionEvent(att, scriptEvents.collision_end , endedColliders , m_scene.EventManager.TriggerScriptCollidingEnd);
4615
4616 if (startedColliders.Contains(0))
4617 SendLandCollisionEvent(att, scriptEvents.land_collision_start, m_scene.EventManager.TriggerScriptLandCollidingStart);
4618 if (m_lastColliders.Contains(0))
4619 SendLandCollisionEvent(att, scriptEvents.land_collision, m_scene.EventManager.TriggerScriptLandColliding);
4620 if (endedColliders.Contains(0))
4621 SendLandCollisionEvent(att, scriptEvents.land_collision_end, m_scene.EventManager.TriggerScriptLandCollidingEnd);
4622 }
4623 }
4624 finally
4625 {
4626 m_collisionEventFlag = false;
4627 }
4628 }
4629
4181 private void TeleportFlagsDebug() { 4630 private void TeleportFlagsDebug() {
4182 4631
4183 // Some temporary debugging help to show all the TeleportFlags we have... 4632 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -4202,6 +4651,5 @@ namespace OpenSim.Region.Framework.Scenes
4202 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4651 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
4203 4652
4204 } 4653 }
4205
4206 } 4654 }
4207} 4655}