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.cs1103
1 files changed, 788 insertions, 315 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index f3b923f..322afd2 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
@@ -490,7 +504,7 @@ namespace OpenSim.Region.Framework.Scenes
490 if (ParentID == 0) 504 if (ParentID == 0)
491 { 505 {
492 m_pos = value; 506 m_pos = value;
493 ParentPosition = Vector3.Zero; 507// ParentPosition = Vector3.Zero;
494 } 508 }
495 509
496 //m_log.DebugFormat( 510 //m_log.DebugFormat(
@@ -559,7 +573,24 @@ namespace OpenSim.Region.Framework.Scenes
559// Scene.RegionInfo.RegionName, Name, m_velocity); 573// Scene.RegionInfo.RegionName, Name, m_velocity);
560 } 574 }
561 } 575 }
576/*
577 public override Vector3 AngularVelocity
578 {
579 get
580 {
581 if (PhysicsActor != null)
582 {
583 m_rotationalvelocity = PhysicsActor.RotationalVelocity;
562 584
585 // m_log.DebugFormat(
586 // "[SCENE PRESENCE]: Set velocity {0} for {1} in {2} via getting Velocity!",
587 // m_velocity, Name, Scene.RegionInfo.RegionName);
588 }
589
590 return m_rotationalvelocity;
591 }
592 }
593*/
563 private Quaternion m_bodyRot = Quaternion.Identity; 594 private Quaternion m_bodyRot = Quaternion.Identity;
564 595
565 /// <summary> 596 /// <summary>
@@ -582,8 +613,16 @@ namespace OpenSim.Region.Framework.Scenes
582 m_bodyRot = value; 613 m_bodyRot = value;
583 614
584 if (PhysicsActor != null) 615 if (PhysicsActor != null)
585 PhysicsActor.Orientation = m_bodyRot; 616 {
586 617 try
618 {
619 PhysicsActor.Orientation = m_bodyRot;
620 }
621 catch (Exception e)
622 {
623 m_log.Error("[SCENE PRESENCE]: Orientation " + e.Message);
624 }
625 }
587// m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot); 626// m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot);
588 } 627 }
589 } 628 }
@@ -597,12 +636,20 @@ namespace OpenSim.Region.Framework.Scenes
597 } 636 }
598 637
599 public bool IsChildAgent { get; set; } 638 public bool IsChildAgent { get; set; }
639 public bool IsLoggingIn { get; set; }
600 640
601 /// <summary> 641 /// <summary>
602 /// If the avatar is sitting, the local ID of the prim that it's sitting on. If not sitting then zero. 642 /// If the avatar is sitting, the local ID of the prim that it's sitting on. If not sitting then zero.
603 /// </summary> 643 /// </summary>
604 public uint ParentID { get; set; } 644 public uint ParentID { get; set; }
605 645
646 public UUID ParentUUID
647 {
648 get { return m_parentUUID; }
649 set { m_parentUUID = value; }
650 }
651 private UUID m_parentUUID = UUID.Zero;
652
606 /// <summary> 653 /// <summary>
607 /// Are we sitting on an object? 654 /// Are we sitting on an object?
608 /// </summary> 655 /// </summary>
@@ -752,6 +799,7 @@ namespace OpenSim.Region.Framework.Scenes
752 AttachmentsSyncLock = new Object(); 799 AttachmentsSyncLock = new Object();
753 AllowMovement = true; 800 AllowMovement = true;
754 IsChildAgent = true; 801 IsChildAgent = true;
802 IsLoggingIn = false;
755 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault; 803 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault;
756 Animator = new ScenePresenceAnimator(this); 804 Animator = new ScenePresenceAnimator(this);
757 PresenceType = type; 805 PresenceType = type;
@@ -795,6 +843,33 @@ namespace OpenSim.Region.Framework.Scenes
795 Appearance = appearance; 843 Appearance = appearance;
796 } 844 }
797 845
846 private void RegionHeartbeatEnd(Scene scene)
847 {
848 if (IsChildAgent)
849 return;
850
851 m_movementAnimationUpdateCounter ++;
852 if (m_movementAnimationUpdateCounter >= 2)
853 {
854 m_movementAnimationUpdateCounter = 0;
855 if (Animator != null)
856 {
857 // If the parentID == 0 we are not sitting
858 // if !SitGournd then we are not sitting on the ground
859 // Fairly straightforward, now here comes the twist
860 // if ParentUUID is NOT UUID.Zero, we are looking to
861 // be sat on an object that isn't there yet. Should
862 // be treated as if sat.
863 if(ParentID == 0 && !SitGround && ParentUUID == UUID.Zero) // skip it if sitting
864 Animator.UpdateMovementAnimations();
865 }
866 else
867 {
868 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
869 }
870 }
871 }
872
798 public void RegisterToEvents() 873 public void RegisterToEvents()
799 { 874 {
800 ControllingClient.OnCompleteMovementToRegion += CompleteMovement; 875 ControllingClient.OnCompleteMovementToRegion += CompleteMovement;
@@ -804,8 +879,10 @@ namespace OpenSim.Region.Framework.Scenes
804 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; 879 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
805 ControllingClient.OnStartAnim += HandleStartAnim; 880 ControllingClient.OnStartAnim += HandleStartAnim;
806 ControllingClient.OnStopAnim += HandleStopAnim; 881 ControllingClient.OnStopAnim += HandleStopAnim;
882 ControllingClient.OnChangeAnim += avnHandleChangeAnim;
807 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls; 883 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls;
808 ControllingClient.OnAutoPilotGo += MoveToTarget; 884 ControllingClient.OnAutoPilotGo += MoveToTarget;
885 ControllingClient.OnUpdateThrottles += RaiseUpdateThrottles;
809 886
810 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); 887 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
811 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); 888 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
@@ -864,10 +941,40 @@ namespace OpenSim.Region.Framework.Scenes
864 "[SCENE]: Upgrading child to root agent for {0} in {1}", 941 "[SCENE]: Upgrading child to root agent for {0} in {1}",
865 Name, m_scene.RegionInfo.RegionName); 942 Name, m_scene.RegionInfo.RegionName);
866 943
867 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
868
869 bool wasChild = IsChildAgent; 944 bool wasChild = IsChildAgent;
870 IsChildAgent = false; 945
946 if (ParentUUID != UUID.Zero)
947 {
948 m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID);
949 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID);
950 if (part == null)
951 {
952 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
953 }
954 else
955 {
956 part.ParentGroup.AddAvatar(UUID);
957 if (part.SitTargetPosition != Vector3.Zero)
958 part.SitTargetAvatar = UUID;
959// ParentPosition = part.GetWorldPosition();
960 ParentID = part.LocalId;
961 ParentPart = part;
962 m_pos = m_prevSitOffset;
963// pos = ParentPosition;
964 pos = part.GetWorldPosition();
965 }
966 ParentUUID = UUID.Zero;
967
968 IsChildAgent = false;
969
970// Animator.TrySetMovementAnimation("SIT");
971 }
972 else
973 {
974 IsChildAgent = false;
975 IsLoggingIn = false;
976 }
977
871 978
872 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 979 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
873 if (gm != null) 980 if (gm != null)
@@ -877,70 +984,106 @@ namespace OpenSim.Region.Framework.Scenes
877 984
878 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 985 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
879 986
880 // Moved this from SendInitialData to ensure that Appearance is initialized 987 UUID groupUUID = UUID.Zero;
881 // before the inventory is processed in MakeRootAgent. This fixes a race condition 988 string GroupName = string.Empty;
882 // related to the handling of attachments 989 ulong groupPowers = 0;
883 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
884 990
885 if (m_scene.TestBorderCross(pos, Cardinals.E)) 991 // ----------------------------------
992 // Previous Agent Difference - AGNI sends an unsolicited AgentDataUpdate upon root agent status
993 try
886 { 994 {
887 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 995 if (gm != null)
888 pos.X = crossedBorder.BorderLine.Z - 1; 996 {
997 groupUUID = ControllingClient.ActiveGroupId;
998 GroupRecord record = gm.GetGroupRecord(groupUUID);
999 if (record != null)
1000 GroupName = record.GroupName;
1001 GroupMembershipData groupMembershipData = gm.GetMembershipData(groupUUID, m_uuid);
1002 if (groupMembershipData != null)
1003 groupPowers = groupMembershipData.GroupPowers;
1004 }
1005 ControllingClient.SendAgentDataUpdate(m_uuid, groupUUID, Firstname, Lastname, groupPowers, GroupName,
1006 Grouptitle);
889 } 1007 }
890 1008 catch (Exception e)
891 if (m_scene.TestBorderCross(pos, Cardinals.N))
892 { 1009 {
893 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 1010 m_log.Debug("[AGENTUPDATE]: " + e.ToString());
894 pos.Y = crossedBorder.BorderLine.Z - 1;
895 } 1011 }
1012 // ------------------------------------
896 1013
897 CheckAndAdjustLandingPoint(ref pos); 1014 if (ParentID == 0)
898
899 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
900 { 1015 {
901 m_log.WarnFormat( 1016 // Moved this from SendInitialData to ensure that Appearance is initialized
902 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", 1017 // before the inventory is processed in MakeRootAgent. This fixes a race condition
903 pos, Name, UUID); 1018 // related to the handling of attachments
1019 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
1020 if (m_scene.TestBorderCross(pos, Cardinals.E))
1021 {
1022 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
1023 pos.X = crossedBorder.BorderLine.Z - 1;
1024 }
904 1025
905 if (pos.X < 0f) pos.X = 0f; 1026 if (m_scene.TestBorderCross(pos, Cardinals.N))
906 if (pos.Y < 0f) pos.Y = 0f; 1027 {
907 if (pos.Z < 0f) pos.Z = 0f; 1028 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
908 } 1029 pos.Y = crossedBorder.BorderLine.Z - 1;
1030 }
909 1031
910 float localAVHeight = 1.56f; 1032 CheckAndAdjustLandingPoint(ref pos);
911 if (Appearance.AvatarHeight > 0)
912 localAVHeight = Appearance.AvatarHeight;
913 1033
914 float posZLimit = 0; 1034 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
1035 {
1036 m_log.WarnFormat(
1037 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
1038 pos, Name, UUID);
915 1039
916 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 1040 if (pos.X < 0f) pos.X = 0f;
917 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 1041 if (pos.Y < 0f) pos.Y = 0f;
918 1042 if (pos.Z < 0f) pos.Z = 0f;
919 float newPosZ = posZLimit + localAVHeight / 2; 1043 }
920 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
921 {
922 pos.Z = newPosZ;
923 }
924 AbsolutePosition = pos;
925 1044
926 AddToPhysicalScene(isFlying); 1045 float localAVHeight = 1.56f;
1046 if (Appearance.AvatarHeight > 0)
1047 localAVHeight = Appearance.AvatarHeight;
927 1048
928 // XXX: This is to trigger any secondary teleport needed for a megaregion when the user has teleported to a 1049 float posZLimit = 0;
929 // location outside the 'root region' (the south-west 256x256 corner). This is the earlist we can do it
930 // since it requires a physics actor to be present. If it is left any later, then physics appears to reset
931 // the value to a negative position which does not trigger the border cross.
932 // This may not be the best location for this.
933 CheckForBorderCrossing();
934 1050
935 if (ForceFly) 1051 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
936 { 1052 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
937 Flying = true; 1053
938 } 1054 float newPosZ = posZLimit + localAVHeight / 2;
939 else if (FlyDisabled) 1055 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
940 { 1056 {
941 Flying = false; 1057 pos.Z = newPosZ;
942 } 1058 }
1059 AbsolutePosition = pos;
943 1060
1061 if (m_teleportFlags == TeleportFlags.Default)
1062 {
1063 Vector3 vel = Velocity;
1064 AddToPhysicalScene(isFlying);
1065 if (PhysicsActor != null)
1066 PhysicsActor.SetMomentum(vel);
1067 }
1068 else
1069 AddToPhysicalScene(isFlying);
1070
1071 // XXX: This is to trigger any secondary teleport needed for a megaregion when the user has teleported to a
1072 // location outside the 'root region' (the south-west 256x256 corner). This is the earlist we can do it
1073 // since it requires a physics actor to be present. If it is left any later, then physics appears to reset
1074 // the value to a negative position which does not trigger the border cross.
1075 // This may not be the best location for this.
1076 CheckForBorderCrossing();
1077
1078 if (ForceFly)
1079 {
1080 Flying = true;
1081 }
1082 else if (FlyDisabled)
1083 {
1084 Flying = false;
1085 }
1086 }
944 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 1087 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
945 // avatar to return to the standing position in mid-air. On login it looks like this is being sent 1088 // avatar to return to the standing position in mid-air. On login it looks like this is being sent
946 // elsewhere anyway 1089 // elsewhere anyway
@@ -960,14 +1103,19 @@ namespace OpenSim.Region.Framework.Scenes
960 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name); 1103 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name);
961 1104
962 // Resume scripts 1105 // Resume scripts
963 foreach (SceneObjectGroup sog in m_attachments) 1106 Util.FireAndForget(delegate(object x) {
964 { 1107 foreach (SceneObjectGroup sog in m_attachments)
965 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); 1108 {
966 sog.ResumeScripts(); 1109 sog.ScheduleGroupForFullUpdate();
967 } 1110 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
1111 sog.ResumeScripts();
1112 }
1113 });
968 } 1114 }
969 } 1115 }
970 1116
1117 SendAvatarDataToAllAgents();
1118
971 // send the animations of the other presences to me 1119 // send the animations of the other presences to me
972 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) 1120 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence)
973 { 1121 {
@@ -978,9 +1126,12 @@ namespace OpenSim.Region.Framework.Scenes
978 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will 1126 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will
979 // stall on the border crossing since the existing child agent will still have the last movement 1127 // stall on the border crossing since the existing child agent will still have the last movement
980 // recorded, which stops the input from being processed. 1128 // recorded, which stops the input from being processed.
1129
981 MovementFlag = 0; 1130 MovementFlag = 0;
982 1131
983 m_scene.EventManager.TriggerOnMakeRootAgent(this); 1132 m_scene.EventManager.TriggerOnMakeRootAgent(this);
1133
1134 m_scene.EventManager.OnRegionHeartbeatEnd += RegionHeartbeatEnd;
984 } 1135 }
985 1136
986 public int GetStateSource() 1137 public int GetStateSource()
@@ -1008,12 +1159,16 @@ namespace OpenSim.Region.Framework.Scenes
1008 /// </remarks> 1159 /// </remarks>
1009 public void MakeChildAgent() 1160 public void MakeChildAgent()
1010 { 1161 {
1162 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
1163
1011 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); 1164 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName);
1012 1165
1013 // Reset these so that teleporting in and walking out isn't seen 1166 // Reset these so that teleporting in and walking out isn't seen
1014 // as teleporting back 1167 // as teleporting back
1015 TeleportFlags = TeleportFlags.Default; 1168 TeleportFlags = TeleportFlags.Default;
1016 1169
1170 MovementFlag = 0;
1171
1017 // It looks like Animator is set to null somewhere, and MakeChild 1172 // It looks like Animator is set to null somewhere, and MakeChild
1018 // is called after that. Probably in aborted teleports. 1173 // is called after that. Probably in aborted teleports.
1019 if (Animator == null) 1174 if (Animator == null)
@@ -1021,6 +1176,7 @@ namespace OpenSim.Region.Framework.Scenes
1021 else 1176 else
1022 Animator.ResetAnimations(); 1177 Animator.ResetAnimations();
1023 1178
1179
1024// m_log.DebugFormat( 1180// m_log.DebugFormat(
1025// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", 1181// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
1026// Name, UUID, m_scene.RegionInfo.RegionName); 1182// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -1032,6 +1188,7 @@ namespace OpenSim.Region.Framework.Scenes
1032 IsChildAgent = true; 1188 IsChildAgent = true;
1033 m_scene.SwapRootAgentCount(true); 1189 m_scene.SwapRootAgentCount(true);
1034 RemoveFromPhysicalScene(); 1190 RemoveFromPhysicalScene();
1191 ParentID = 0; // Child agents can't be sitting
1035 1192
1036 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into 1193 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into
1037 1194
@@ -1047,9 +1204,9 @@ namespace OpenSim.Region.Framework.Scenes
1047 { 1204 {
1048// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1205// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
1049 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall; 1206 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall;
1050 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1051 PhysicsActor.UnSubscribeEvents();
1052 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1207 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
1208 PhysicsActor.UnSubscribeEvents();
1209 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1053 PhysicsActor = null; 1210 PhysicsActor = null;
1054 } 1211 }
1055// else 1212// else
@@ -1066,7 +1223,7 @@ namespace OpenSim.Region.Framework.Scenes
1066 /// <param name="pos"></param> 1223 /// <param name="pos"></param>
1067 public void Teleport(Vector3 pos) 1224 public void Teleport(Vector3 pos)
1068 { 1225 {
1069 TeleportWithMomentum(pos, null); 1226 TeleportWithMomentum(pos, Vector3.Zero);
1070 } 1227 }
1071 1228
1072 public void TeleportWithMomentum(Vector3 pos, Vector3? v) 1229 public void TeleportWithMomentum(Vector3 pos, Vector3? v)
@@ -1090,6 +1247,41 @@ namespace OpenSim.Region.Framework.Scenes
1090 SendTerseUpdateToAllClients(); 1247 SendTerseUpdateToAllClients();
1091 } 1248 }
1092 1249
1250 public void avnLocalTeleport(Vector3 newpos, Vector3? newvel, bool rotateToVelXY)
1251 {
1252 CheckLandingPoint(ref newpos);
1253 AbsolutePosition = newpos;
1254
1255 if (newvel.HasValue)
1256 {
1257 if ((Vector3)newvel == Vector3.Zero)
1258 {
1259 if (PhysicsActor != null)
1260 PhysicsActor.SetMomentum(Vector3.Zero);
1261 m_velocity = Vector3.Zero;
1262 }
1263 else
1264 {
1265 if (PhysicsActor != null)
1266 PhysicsActor.SetMomentum((Vector3)newvel);
1267 m_velocity = (Vector3)newvel;
1268
1269 if (rotateToVelXY)
1270 {
1271 Vector3 lookAt = (Vector3)newvel;
1272 lookAt.Z = 0;
1273 lookAt.Normalize();
1274 ControllingClient.SendLocalTeleport(newpos, lookAt, (uint)TeleportFlags.ViaLocation);
1275 return;
1276 }
1277 }
1278 }
1279
1280 SendTerseUpdateToAllClients();
1281 }
1282
1283
1284
1093 public void StopFlying() 1285 public void StopFlying()
1094 { 1286 {
1095 ControllingClient.StopFlying(this); 1287 ControllingClient.StopFlying(this);
@@ -1259,6 +1451,13 @@ namespace OpenSim.Region.Framework.Scenes
1259 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height); 1451 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height);
1260 } 1452 }
1261 1453
1454 public void SetSize(Vector3 size, float feetoffset)
1455 {
1456 if (PhysicsActor != null && !IsChildAgent)
1457 PhysicsActor.setAvatarSize(size, feetoffset);
1458
1459 }
1460
1262 /// <summary> 1461 /// <summary>
1263 /// Complete Avatar's movement into the region. 1462 /// Complete Avatar's movement into the region.
1264 /// </summary> 1463 /// </summary>
@@ -1278,7 +1477,8 @@ namespace OpenSim.Region.Framework.Scenes
1278 1477
1279 Vector3 look = Velocity; 1478 Vector3 look = Velocity;
1280 1479
1281 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) 1480 // if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
1481 if ((Math.Abs(look.X) < 0.1) && (Math.Abs(look.Y) < 0.1) && (Math.Abs(look.Z) < 0.1))
1282 { 1482 {
1283 look = new Vector3(0.99f, 0.042f, 0); 1483 look = new Vector3(0.99f, 0.042f, 0);
1284 } 1484 }
@@ -1328,13 +1528,15 @@ namespace OpenSim.Region.Framework.Scenes
1328 // Create child agents in neighbouring regions 1528 // Create child agents in neighbouring regions
1329 if (openChildAgents && !IsChildAgent) 1529 if (openChildAgents && !IsChildAgent)
1330 { 1530 {
1531
1331 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); 1532 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
1332 if (m_agentTransfer != null) 1533 if (m_agentTransfer != null)
1333 Util.FireAndForget(delegate { m_agentTransfer.EnableChildAgents(this); }); 1534 m_agentTransfer.EnableChildAgents(this);
1334 1535
1335 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); 1536 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
1336 if (friendsModule != null) 1537 if (friendsModule != null)
1337 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); 1538 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient);
1539
1338 } 1540 }
1339 1541
1340 // XXX: If we force an update here, then multiple attachments do appear correctly on a destination region 1542 // XXX: If we force an update here, then multiple attachments do appear correctly on a destination region
@@ -1359,36 +1561,69 @@ namespace OpenSim.Region.Framework.Scenes
1359 /// <param name="collisionPoint"></param> 1561 /// <param name="collisionPoint"></param>
1360 /// <param name="localid"></param> 1562 /// <param name="localid"></param>
1361 /// <param name="distance"></param> 1563 /// <param name="distance"></param>
1564 ///
1565
1566 private void UpdateCameraCollisionPlane(Vector4 plane)
1567 {
1568 if (m_lastCameraCollisionPlane != plane)
1569 {
1570 m_lastCameraCollisionPlane = plane;
1571 ControllingClient.SendCameraConstraint(plane);
1572 }
1573 }
1574
1362 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) 1575 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal)
1363 { 1576 {
1364 const float POSITION_TOLERANCE = 0.02f; 1577 const float POSITION_TOLERANCE = 0.02f;
1365 const float VELOCITY_TOLERANCE = 0.02f;
1366 const float ROTATION_TOLERANCE = 0.02f; 1578 const float ROTATION_TOLERANCE = 0.02f;
1367 1579
1368 if (m_followCamAuto) 1580 m_doingCamRayCast = false;
1581 if (hitYN && localid != LocalId)
1369 { 1582 {
1370 if (hitYN) 1583 SceneObjectGroup group = m_scene.GetGroupByPrim(localid);
1584 bool IsPrim = group != null;
1585 if (IsPrim)
1371 { 1586 {
1372 CameraConstraintActive = true; 1587 SceneObjectPart part = group.GetPart(localid);
1373 //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); 1588 if (part != null && !part.VolumeDetectActive)
1374 1589 {
1375 Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); 1590 CameraConstraintActive = true;
1376 ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); 1591 pNormal.X = (float) Math.Round(pNormal.X, 2);
1592 pNormal.Y = (float) Math.Round(pNormal.Y, 2);
1593 pNormal.Z = (float) Math.Round(pNormal.Z, 2);
1594 pNormal.Normalize();
1595 collisionPoint.X = (float) Math.Round(collisionPoint.X, 1);
1596 collisionPoint.Y = (float) Math.Round(collisionPoint.Y, 1);
1597 collisionPoint.Z = (float) Math.Round(collisionPoint.Z, 1);
1598
1599 Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z,
1600 Vector3.Dot(collisionPoint, pNormal));
1601 UpdateCameraCollisionPlane(plane);
1602 }
1377 } 1603 }
1378 else 1604 else
1379 { 1605 {
1380 if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || 1606 CameraConstraintActive = true;
1381 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || 1607 pNormal.X = (float) Math.Round(pNormal.X, 2);
1382 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) 1608 pNormal.Y = (float) Math.Round(pNormal.Y, 2);
1383 { 1609 pNormal.Z = (float) Math.Round(pNormal.Z, 2);
1384 if (CameraConstraintActive) 1610 pNormal.Normalize();
1385 { 1611 collisionPoint.X = (float) Math.Round(collisionPoint.X, 1);
1386 ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); 1612 collisionPoint.Y = (float) Math.Round(collisionPoint.Y, 1);
1387 CameraConstraintActive = false; 1613 collisionPoint.Z = (float) Math.Round(collisionPoint.Z, 1);
1388 } 1614
1389 } 1615 Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z,
1616 Vector3.Dot(collisionPoint, pNormal));
1617 UpdateCameraCollisionPlane(plane);
1390 } 1618 }
1391 } 1619 }
1620 else if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
1621 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE))
1622 {
1623 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -9000f); // not right...
1624 UpdateCameraCollisionPlane(plane);
1625 CameraConstraintActive = false;
1626 }
1392 } 1627 }
1393 1628
1394 /// <summary> 1629 /// <summary>
@@ -1462,12 +1697,6 @@ namespace OpenSim.Region.Framework.Scenes
1462 // DrawDistance = agentData.Far; 1697 // DrawDistance = agentData.Far;
1463 DrawDistance = Scene.DefaultDrawDistance; 1698 DrawDistance = Scene.DefaultDrawDistance;
1464 1699
1465 // Check if Client has camera in 'follow cam' or 'build' mode.
1466 Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation);
1467
1468 m_followCamAuto = ((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.98f)
1469 && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false;
1470
1471 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; 1700 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0;
1472 m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; 1701 m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0;
1473 1702
@@ -1487,14 +1716,38 @@ namespace OpenSim.Region.Framework.Scenes
1487 StandUp(); 1716 StandUp();
1488 } 1717 }
1489 1718
1490 //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto);
1491 // Raycast from the avatar's head to the camera to see if there's anything blocking the view 1719 // Raycast from the avatar's head to the camera to see if there's anything blocking the view
1492 if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) 1720 // this exclude checks may not be complete
1721
1722 if (m_movementUpdateCount % NumMovementsBetweenRayCast == 0 && m_scene.PhysicsScene.SupportsRayCast())
1493 { 1723 {
1494 if (m_followCamAuto) 1724 if (!m_doingCamRayCast && !m_mouseLook && ParentID == 0)
1495 { 1725 {
1496 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; 1726 Vector3 posAdjusted = AbsolutePosition;
1497 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); 1727// posAdjusted.Z += 0.5f * Appearance.AvatarSize.Z - 0.5f;
1728 posAdjusted.Z += 1.0f; // viewer current camera focus point
1729 Vector3 tocam = CameraPosition - posAdjusted;
1730 tocam.X = (float)Math.Round(tocam.X, 1);
1731 tocam.Y = (float)Math.Round(tocam.Y, 1);
1732 tocam.Z = (float)Math.Round(tocam.Z, 1);
1733
1734 float distTocamlen = tocam.Length();
1735 if (distTocamlen > 0.3f)
1736 {
1737 tocam *= (1.0f / distTocamlen);
1738 posAdjusted.X = (float)Math.Round(posAdjusted.X, 1);
1739 posAdjusted.Y = (float)Math.Round(posAdjusted.Y, 1);
1740 posAdjusted.Z = (float)Math.Round(posAdjusted.Z, 1);
1741
1742 m_doingCamRayCast = true;
1743 m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback);
1744 }
1745 }
1746 else if (CameraConstraintActive && (m_mouseLook || ParentID != 0))
1747 {
1748 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right...
1749 UpdateCameraCollisionPlane(plane);
1750 CameraConstraintActive = false;
1498 } 1751 }
1499 } 1752 }
1500 1753
@@ -1959,7 +2212,8 @@ namespace OpenSim.Region.Framework.Scenes
1959// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name); 2212// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name);
1960 2213
1961 MovingToTarget = false; 2214 MovingToTarget = false;
1962 MoveToPositionTarget = Vector3.Zero; 2215// MoveToPositionTarget = Vector3.Zero;
2216 m_forceToApply = null; // cancel possible last action
1963 2217
1964 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct 2218 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct
1965 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag. 2219 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag.
@@ -1977,12 +2231,17 @@ namespace OpenSim.Region.Framework.Scenes
1977// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); 2231// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name);
1978 2232
1979 SitGround = false; 2233 SitGround = false;
2234
2235/* move this down so avatar gets physical in the new position and not where it is siting
1980 if (PhysicsActor == null) 2236 if (PhysicsActor == null)
1981 AddToPhysicalScene(false); 2237 AddToPhysicalScene(false);
2238 */
1982 2239
1983 if (ParentID != 0) 2240 if (ParentID != 0)
1984 { 2241 {
1985 SceneObjectPart part = ParentPart; 2242 SceneObjectPart part = ParentPart;
2243 UnRegisterSeatControls(part.ParentGroup.UUID);
2244
1986 TaskInventoryDictionary taskIDict = part.TaskInventory; 2245 TaskInventoryDictionary taskIDict = part.TaskInventory;
1987 if (taskIDict != null) 2246 if (taskIDict != null)
1988 { 2247 {
@@ -1998,14 +2257,22 @@ namespace OpenSim.Region.Framework.Scenes
1998 } 2257 }
1999 } 2258 }
2000 2259
2001 ParentPosition = part.GetWorldPosition(); 2260 part.ParentGroup.DeleteAvatar(UUID);
2261// ParentPosition = part.GetWorldPosition();
2002 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 2262 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
2003 2263
2004 m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight); 2264// m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
2005 ParentPosition = Vector3.Zero; 2265// ParentPosition = Vector3.Zero;
2266 m_pos = part.AbsolutePosition + (m_pos * part.GetWorldRotation()) + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
2267 if (part.SitTargetAvatar == UUID)
2268 m_bodyRot = part.GetWorldRotation() * part.SitTargetOrientation;
2006 2269
2007 ParentID = 0; 2270 ParentID = 0;
2008 ParentPart = null; 2271 ParentPart = null;
2272
2273 if (PhysicsActor == null)
2274 AddToPhysicalScene(false);
2275
2009 SendAvatarDataToAllAgents(); 2276 SendAvatarDataToAllAgents();
2010 m_requestedSitTargetID = 0; 2277 m_requestedSitTargetID = 0;
2011 2278
@@ -2015,6 +2282,9 @@ namespace OpenSim.Region.Framework.Scenes
2015 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 2282 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2016 } 2283 }
2017 2284
2285 else if (PhysicsActor == null)
2286 AddToPhysicalScene(false);
2287
2018 Animator.TrySetMovementAnimation("STAND"); 2288 Animator.TrySetMovementAnimation("STAND");
2019 } 2289 }
2020 2290
@@ -2062,11 +2332,8 @@ namespace OpenSim.Region.Framework.Scenes
2062 if (part == null) 2332 if (part == null)
2063 return; 2333 return;
2064 2334
2065 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
2066 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
2067
2068 if (PhysicsActor != null) 2335 if (PhysicsActor != null)
2069 m_sitAvatarHeight = PhysicsActor.Size.Z; 2336 m_sitAvatarHeight = PhysicsActor.Size.Z * 0.5f;
2070 2337
2071 bool canSit = false; 2338 bool canSit = false;
2072 Vector3 pos = part.AbsolutePosition + offset; 2339 Vector3 pos = part.AbsolutePosition + offset;
@@ -2083,31 +2350,31 @@ namespace OpenSim.Region.Framework.Scenes
2083 } 2350 }
2084 else 2351 else
2085 { 2352 {
2353 if (PhysicsSit(part,offset)) // physics engine
2354 return;
2355
2086 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10) 2356 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10)
2087 { 2357 {
2088// m_log.DebugFormat(
2089// "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is unset and within 10m",
2090// Name, part.Name, part.LocalId);
2091 2358
2092 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 2359 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
2093 canSit = true; 2360 canSit = true;
2094 } 2361 }
2095// else
2096// {
2097// m_log.DebugFormat(
2098// "[SCENE PRESENCE]: Ignoring sit request of {0} on {1} {2} because sit target is unset and outside 10m",
2099// Name, part.Name, part.LocalId);
2100// }
2101 } 2362 }
2102 2363
2103 if (canSit) 2364 if (canSit)
2104 { 2365 {
2366
2105 if (PhysicsActor != null) 2367 if (PhysicsActor != null)
2106 { 2368 {
2107 // We can remove the physicsActor until they stand up. 2369 // We can remove the physicsActor until they stand up.
2108 RemoveFromPhysicalScene(); 2370 RemoveFromPhysicalScene();
2109 } 2371 }
2110 2372
2373 if (MovingToTarget)
2374 ResetMoveToTarget();
2375
2376 Velocity = Vector3.Zero;
2377
2111 part.AddSittingAvatar(UUID); 2378 part.AddSittingAvatar(UUID);
2112 2379
2113 cameraAtOffset = part.GetCameraAtOffset(); 2380 cameraAtOffset = part.GetCameraAtOffset();
@@ -2115,7 +2382,7 @@ namespace OpenSim.Region.Framework.Scenes
2115 forceMouselook = part.GetForceMouselook(); 2382 forceMouselook = part.GetForceMouselook();
2116 2383
2117 ControllingClient.SendSitResponse( 2384 ControllingClient.SendSitResponse(
2118 targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 2385 part.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
2119 2386
2120 m_requestedSitTargetUUID = targetID; 2387 m_requestedSitTargetUUID = targetID;
2121 2388
@@ -2129,6 +2396,9 @@ namespace OpenSim.Region.Framework.Scenes
2129 2396
2130 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) 2397 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset)
2131 { 2398 {
2399 if (IsChildAgent)
2400 return;
2401
2132 if (ParentID != 0) 2402 if (ParentID != 0)
2133 { 2403 {
2134 if (ParentPart.UUID == targetID) 2404 if (ParentPart.UUID == targetID)
@@ -2144,14 +2414,6 @@ namespace OpenSim.Region.Framework.Scenes
2144 m_requestedSitTargetID = part.LocalId; 2414 m_requestedSitTargetID = part.LocalId;
2145 m_requestedSitTargetUUID = targetID; 2415 m_requestedSitTargetUUID = targetID;
2146 2416
2147// m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset);
2148
2149 if (m_scene.PhysicsScene.SupportsRayCast())
2150 {
2151 //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback());
2152 //SitRayCastAvatarPosition(part);
2153 //return;
2154 }
2155 } 2417 }
2156 else 2418 else
2157 { 2419 {
@@ -2161,197 +2423,111 @@ namespace OpenSim.Region.Framework.Scenes
2161 SendSitResponse(targetID, offset, Quaternion.Identity); 2423 SendSitResponse(targetID, offset, Quaternion.Identity);
2162 } 2424 }
2163 2425
2164 /* 2426 // returns false if does not suport so older sit can be tried
2165 public void SitRayCastAvatarPosition(SceneObjectPart part) 2427 public bool PhysicsSit(SceneObjectPart part, Vector3 offset)
2166 { 2428 {
2167 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2429 if (part == null || part.ParentGroup.IsAttachment)
2168 Vector3 StartRayCastPosition = AbsolutePosition;
2169 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2170 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2171 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionResponse);
2172 }
2173
2174 public void SitRayCastAvatarPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal)
2175 {
2176 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2177 if (part != null)
2178 {
2179 if (hitYN)
2180 {
2181 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2182 {
2183 SitRaycastFindEdge(collisionPoint, normal);
2184 m_log.DebugFormat("[SIT]: Raycast Avatar Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2185 }
2186 else
2187 {
2188 SitRayCastAvatarPositionCameraZ(part);
2189 }
2190 }
2191 else
2192 {
2193 SitRayCastAvatarPositionCameraZ(part);
2194 }
2195 }
2196 else
2197 { 2430 {
2198 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2431 return true;
2199 m_requestedSitTargetUUID = UUID.Zero;
2200 m_requestedSitTargetID = 0;
2201 m_requestedSitOffset = Vector3.Zero;
2202 } 2432 }
2203 2433
2204 } 2434 if ( m_scene.PhysicsScene == null)
2435 return false;
2205 2436
2206 public void SitRayCastAvatarPositionCameraZ(SceneObjectPart part) 2437 if (part.PhysActor == null)
2207 {
2208 // Next, try to raycast from the camera Z position
2209 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2210 Vector3 StartRayCastPosition = AbsolutePosition; StartRayCastPosition.Z = CameraPosition.Z;
2211 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2212 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2213 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionCameraZResponse);
2214 }
2215
2216 public void SitRayCastAvatarPositionCameraZResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal)
2217 {
2218 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2219 if (part != null)
2220 { 2438 {
2221 if (hitYN) 2439 // none physcis shape
2222 { 2440 if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
2223 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) 2441 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2224 {
2225 SitRaycastFindEdge(collisionPoint, normal);
2226 m_log.DebugFormat("[SIT]: Raycast Avatar Position + CameraZ succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2227 }
2228 else
2229 {
2230 SitRayCastCameraPosition(part);
2231 }
2232 }
2233 else 2442 else
2234 { 2443 { // non physical phantom TODO
2235 SitRayCastCameraPosition(part); 2444 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2445 return false;
2236 } 2446 }
2237 } 2447 return true;
2238 else
2239 {
2240 ControllingClient.SendAlertMessage("Sit position no longer exists");
2241 m_requestedSitTargetUUID = UUID.Zero;
2242 m_requestedSitTargetID = 0;
2243 m_requestedSitOffset = Vector3.Zero;
2244 } 2448 }
2245 2449
2246 }
2247 2450
2248 public void SitRayCastCameraPosition(SceneObjectPart part) 2451 // not doing autopilot
2249 { 2452 m_requestedSitTargetID = 0;
2250 // Next, try to raycast from the camera position
2251 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2252 Vector3 StartRayCastPosition = CameraPosition;
2253 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2254 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2255 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastCameraPositionResponse);
2256 }
2257 2453
2258 public void SitRayCastCameraPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2454 if (m_scene.PhysicsScene.SitAvatar(part.PhysActor, AbsolutePosition, CameraPosition, offset, new Vector3(0.35f, 0, 0.65f), PhysicsSitResponse) != 0)
2259 { 2455 return true;
2260 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2261 if (part != null)
2262 {
2263 if (hitYN)
2264 {
2265 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2266 {
2267 SitRaycastFindEdge(collisionPoint, normal);
2268 m_log.DebugFormat("[SIT]: Raycast Camera Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2269 }
2270 else
2271 {
2272 SitRayHorizontal(part);
2273 }
2274 }
2275 else
2276 {
2277 SitRayHorizontal(part);
2278 }
2279 }
2280 else
2281 {
2282 ControllingClient.SendAlertMessage("Sit position no longer exists");
2283 m_requestedSitTargetUUID = UUID.Zero;
2284 m_requestedSitTargetID = 0;
2285 m_requestedSitOffset = Vector3.Zero;
2286 }
2287 2456
2457 return false;
2288 } 2458 }
2289 2459
2290 public void SitRayHorizontal(SceneObjectPart part) 2460
2461 private bool CanEnterLandPosition(Vector3 testPos)
2291 { 2462 {
2292 // Next, try to raycast from the avatar position to fwd 2463 ILandObject land = m_scene.LandChannel.GetLandObject(testPos.X, testPos.Y);
2293 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2464
2294 Vector3 StartRayCastPosition = CameraPosition; 2465 if (land == null || land.LandData.Name == "NO_LAND")
2295 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); 2466 return true;
2296 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); 2467
2297 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastHorizontalResponse); 2468 return land.CanBeOnThisLand(UUID,testPos.Z);
2298 } 2469 }
2299 2470
2300 public void SitRayCastHorizontalResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2471 // status
2472 // < 0 ignore
2473 // 0 bad sit spot
2474 public void PhysicsSitResponse(int status, uint partID, Vector3 offset, Quaternion Orientation)
2301 { 2475 {
2302 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); 2476 if (status < 0)
2303 if (part != null) 2477 return;
2478
2479 if (status == 0)
2304 { 2480 {
2305 if (hitYN) 2481 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2306 { 2482 return;
2307 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2308 {
2309 SitRaycastFindEdge(collisionPoint, normal);
2310 m_log.DebugFormat("[SIT]: Raycast Horizontal Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2311 // Next, try to raycast from the camera position
2312 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2313 Vector3 StartRayCastPosition = CameraPosition;
2314 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2315 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2316 //m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastResponseAvatarPosition);
2317 }
2318 else
2319 {
2320 ControllingClient.SendAlertMessage("Sit position not accessable.");
2321 m_requestedSitTargetUUID = UUID.Zero;
2322 m_requestedSitTargetID = 0;
2323 m_requestedSitOffset = Vector3.Zero;
2324 }
2325 }
2326 else
2327 {
2328 ControllingClient.SendAlertMessage("Sit position not accessable.");
2329 m_requestedSitTargetUUID = UUID.Zero;
2330 m_requestedSitTargetID = 0;
2331 m_requestedSitOffset = Vector3.Zero;
2332 }
2333 } 2483 }
2334 else 2484
2485 SceneObjectPart part = m_scene.GetSceneObjectPart(partID);
2486 if (part == null)
2487 return;
2488
2489 Vector3 targetPos = part.GetWorldPosition() + offset * part.GetWorldRotation();
2490 if(!CanEnterLandPosition(targetPos))
2335 { 2491 {
2336 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2492 ControllingClient.SendAlertMessage(" Sit position on restricted land, try another spot");
2337 m_requestedSitTargetUUID = UUID.Zero; 2493 return;
2338 m_requestedSitTargetID = 0;
2339 m_requestedSitOffset = Vector3.Zero;
2340 } 2494 }
2341 2495
2342 } 2496 RemoveFromPhysicalScene();
2343 2497
2344 private void SitRaycastFindEdge(Vector3 collisionPoint, Vector3 collisionNormal) 2498 if (MovingToTarget)
2345 { 2499 ResetMoveToTarget();
2346 int i = 0; 2500
2347 //throw new NotImplementedException(); 2501 Velocity = Vector3.Zero;
2348 //m_requestedSitTargetUUID = UUID.Zero; 2502
2349 //m_requestedSitTargetID = 0; 2503 part.AddSittingAvatar(UUID);
2350 //m_requestedSitOffset = Vector3.Zero;
2351 2504
2352 SendSitResponse(ControllingClient, m_requestedSitTargetUUID, collisionPoint - m_requestedSitOffset, Quaternion.Identity); 2505 Vector3 cameraAtOffset = part.GetCameraAtOffset();
2506 Vector3 cameraEyeOffset = part.GetCameraEyeOffset();
2507 bool forceMouselook = part.GetForceMouselook();
2508
2509 ControllingClient.SendSitResponse(
2510 part.UUID, offset, Orientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
2511
2512 // not using autopilot
2513
2514 Rotation = Orientation;
2515 m_pos = offset;
2516
2517 m_requestedSitTargetID = 0;
2518 part.ParentGroup.AddAvatar(UUID);
2519
2520 ParentPart = part;
2521 ParentID = part.LocalId;
2522 if(status == 3)
2523 Animator.TrySetMovementAnimation("SIT_GROUND");
2524 else
2525 Animator.TrySetMovementAnimation("SIT");
2526 SendAvatarDataToAllAgents();
2527
2528 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2353 } 2529 }
2354 */ 2530
2355 2531
2356 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) 2532 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID)
2357 { 2533 {
@@ -2368,6 +2544,7 @@ namespace OpenSim.Region.Framework.Scenes
2368 return; 2544 return;
2369 } 2545 }
2370 2546
2547
2371 if (part.SitTargetAvatar == UUID) 2548 if (part.SitTargetAvatar == UUID)
2372 { 2549 {
2373 Vector3 sitTargetPos = part.SitTargetPosition; 2550 Vector3 sitTargetPos = part.SitTargetPosition;
@@ -2382,14 +2559,39 @@ namespace OpenSim.Region.Framework.Scenes
2382 2559
2383 //Quaternion result = (sitTargetOrient * vq) * nq; 2560 //Quaternion result = (sitTargetOrient * vq) * nq;
2384 2561
2385 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2562 double x, y, z, m;
2563
2564 Quaternion r = sitTargetOrient;
2565 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2566
2567 if (Math.Abs(1.0 - m) > 0.000001)
2568 {
2569 m = 1.0 / Math.Sqrt(m);
2570 r.X *= (float)m;
2571 r.Y *= (float)m;
2572 r.Z *= (float)m;
2573 r.W *= (float)m;
2574 }
2575
2576 x = 2 * (r.X * r.Z + r.Y * r.W);
2577 y = 2 * (-r.X * r.W + r.Y * r.Z);
2578 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2579
2580 Vector3 up = new Vector3((float)x, (float)y, (float)z);
2581 Vector3 sitOffset = up * Appearance.AvatarHeight * 0.02638f;
2582
2583 m_pos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT;
2584
2585// m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT - sitOffset;
2386 Rotation = sitTargetOrient; 2586 Rotation = sitTargetOrient;
2387 ParentPosition = part.AbsolutePosition; 2587// ParentPosition = part.AbsolutePosition;
2588 part.ParentGroup.AddAvatar(UUID);
2388 } 2589 }
2389 else 2590 else
2390 { 2591 {
2391 m_pos -= part.AbsolutePosition; 2592 m_pos -= part.AbsolutePosition;
2392 ParentPosition = part.AbsolutePosition; 2593// ParentPosition = part.AbsolutePosition;
2594 part.ParentGroup.AddAvatar(UUID);
2393 2595
2394// m_log.DebugFormat( 2596// m_log.DebugFormat(
2395// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2597// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -2440,6 +2642,13 @@ namespace OpenSim.Region.Framework.Scenes
2440 Animator.RemoveAnimation(animID, false); 2642 Animator.RemoveAnimation(animID, false);
2441 } 2643 }
2442 2644
2645 public void avnHandleChangeAnim(UUID animID, bool addRemove,bool sendPack)
2646 {
2647 Animator.avnChangeAnim(animID, addRemove, sendPack);
2648 }
2649
2650
2651
2443 /// <summary> 2652 /// <summary>
2444 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector 2653 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
2445 /// </summary> 2654 /// </summary>
@@ -2496,8 +2705,8 @@ namespace OpenSim.Region.Framework.Scenes
2496 direc.Z *= 2.6f; 2705 direc.Z *= 2.6f;
2497 2706
2498 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2707 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
2499 Animator.TrySetMovementAnimation("PREJUMP"); 2708// Animator.TrySetMovementAnimation("PREJUMP");
2500 Animator.TrySetMovementAnimation("JUMP"); 2709// Animator.TrySetMovementAnimation("JUMP");
2501 } 2710 }
2502 } 2711 }
2503 } 2712 }
@@ -2506,6 +2715,7 @@ namespace OpenSim.Region.Framework.Scenes
2506 2715
2507 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2716 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2508 m_forceToApply = direc; 2717 m_forceToApply = direc;
2718 Animator.UpdateMovementAnimations();
2509 } 2719 }
2510 2720
2511 #endregion 2721 #endregion
@@ -2523,16 +2733,12 @@ namespace OpenSim.Region.Framework.Scenes
2523 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to 2733 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to
2524 // grab the latest PhysicsActor velocity, whereas m_velocity is often 2734 // grab the latest PhysicsActor velocity, whereas m_velocity is often
2525 // storing a requested force instead of an actual traveling velocity 2735 // storing a requested force instead of an actual traveling velocity
2736 if (Appearance.AvatarSize != m_lastSize && !IsLoggingIn)
2737 SendAvatarDataToAllAgents();
2526 2738
2527 // Throw away duplicate or insignificant updates 2739 if (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||
2528 if ( 2740 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
2529 // If the velocity has become zero, send it no matter what. 2741 !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))
2530 (Velocity != m_lastVelocity && Velocity == Vector3.Zero)
2531 // otherwise, if things have changed reasonably, send the update
2532 || (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)
2533 || !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE)
2534 || !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)))
2535
2536 { 2742 {
2537 SendTerseUpdateToAllClients(); 2743 SendTerseUpdateToAllClients();
2538 2744
@@ -2721,6 +2927,8 @@ namespace OpenSim.Region.Framework.Scenes
2721 return; 2927 return;
2722 } 2928 }
2723 2929
2930 m_lastSize = Appearance.AvatarSize;
2931
2724 int count = 0; 2932 int count = 0;
2725 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) 2933 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
2726 { 2934 {
@@ -2828,6 +3036,8 @@ namespace OpenSim.Region.Framework.Scenes
2828 3036
2829 avatar.ControllingClient.SendAppearance( 3037 avatar.ControllingClient.SendAppearance(
2830 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes()); 3038 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes());
3039
3040
2831 } 3041 }
2832 3042
2833 #endregion 3043 #endregion
@@ -2902,8 +3112,9 @@ namespace OpenSim.Region.Framework.Scenes
2902 3112
2903 // If we don't have a PhysActor, we can't cross anyway 3113 // If we don't have a PhysActor, we can't cross anyway
2904 // Also don't do this while sat, sitting avatars cross with the 3114 // Also don't do this while sat, sitting avatars cross with the
2905 // object they sit on. 3115 // object they sit on. ParentUUID denoted a pending sit, don't
2906 if (ParentID != 0 || PhysicsActor == null) 3116 // interfere with it.
3117 if (ParentID != 0 || PhysicsActor == null || ParentUUID != UUID.Zero)
2907 return; 3118 return;
2908 3119
2909 if (!IsInTransit) 3120 if (!IsInTransit)
@@ -3168,6 +3379,10 @@ namespace OpenSim.Region.Framework.Scenes
3168 } 3379 }
3169 3380
3170 private static Vector3 marker = new Vector3(-1f, -1f, -1f); 3381 private static Vector3 marker = new Vector3(-1f, -1f, -1f);
3382 private void RaiseUpdateThrottles()
3383 {
3384 m_scene.EventManager.TriggerThrottleUpdate(this);
3385 }
3171 /// <summary> 3386 /// <summary>
3172 /// This updates important decision making data about a child agent 3387 /// This updates important decision making data about a child agent
3173 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region 3388 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region
@@ -3248,6 +3463,9 @@ namespace OpenSim.Region.Framework.Scenes
3248 cAgent.AlwaysRun = SetAlwaysRun; 3463 cAgent.AlwaysRun = SetAlwaysRun;
3249 3464
3250 cAgent.Appearance = new AvatarAppearance(Appearance); 3465 cAgent.Appearance = new AvatarAppearance(Appearance);
3466
3467 cAgent.ParentPart = ParentUUID;
3468 cAgent.SitOffset = m_pos;
3251 3469
3252 lock (scriptedcontrols) 3470 lock (scriptedcontrols)
3253 { 3471 {
@@ -3256,7 +3474,7 @@ namespace OpenSim.Region.Framework.Scenes
3256 3474
3257 foreach (ScriptControllers c in scriptedcontrols.Values) 3475 foreach (ScriptControllers c in scriptedcontrols.Values)
3258 { 3476 {
3259 controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); 3477 controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
3260 } 3478 }
3261 cAgent.Controllers = controls; 3479 cAgent.Controllers = controls;
3262 } 3480 }
@@ -3289,6 +3507,8 @@ namespace OpenSim.Region.Framework.Scenes
3289 CameraAtAxis = cAgent.AtAxis; 3507 CameraAtAxis = cAgent.AtAxis;
3290 CameraLeftAxis = cAgent.LeftAxis; 3508 CameraLeftAxis = cAgent.LeftAxis;
3291 CameraUpAxis = cAgent.UpAxis; 3509 CameraUpAxis = cAgent.UpAxis;
3510 ParentUUID = cAgent.ParentPart;
3511 m_prevSitOffset = cAgent.SitOffset;
3292 3512
3293 // When we get to the point of re-computing neighbors everytime this 3513 // When we get to the point of re-computing neighbors everytime this
3294 // changes, then start using the agent's drawdistance rather than the 3514 // changes, then start using the agent's drawdistance rather than the
@@ -3326,6 +3546,7 @@ namespace OpenSim.Region.Framework.Scenes
3326 foreach (ControllerData c in cAgent.Controllers) 3546 foreach (ControllerData c in cAgent.Controllers)
3327 { 3547 {
3328 ScriptControllers sc = new ScriptControllers(); 3548 ScriptControllers sc = new ScriptControllers();
3549 sc.objectID = c.ObjectID;
3329 sc.itemID = c.ItemID; 3550 sc.itemID = c.ItemID;
3330 sc.ignoreControls = (ScriptControlled)c.IgnoreControls; 3551 sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
3331 sc.eventControls = (ScriptControlled)c.EventControls; 3552 sc.eventControls = (ScriptControlled)c.EventControls;
@@ -3393,20 +3614,27 @@ namespace OpenSim.Region.Framework.Scenes
3393 } 3614 }
3394 3615
3395 if (Appearance.AvatarHeight == 0) 3616 if (Appearance.AvatarHeight == 0)
3396 Appearance.SetHeight(); 3617// Appearance.SetHeight();
3618 Appearance.SetSize(new Vector3(0.45f,0.6f,1.9f));
3397 3619
3398 PhysicsScene scene = m_scene.PhysicsScene; 3620 PhysicsScene scene = m_scene.PhysicsScene;
3399 3621
3400 Vector3 pVec = AbsolutePosition; 3622 Vector3 pVec = AbsolutePosition;
3401 3623
3624/*
3402 PhysicsActor = scene.AddAvatar( 3625 PhysicsActor = scene.AddAvatar(
3403 LocalId, Firstname + "." + Lastname, pVec, 3626 LocalId, Firstname + "." + Lastname, pVec,
3404 new Vector3(0f, 0f, Appearance.AvatarHeight), isFlying); 3627 new Vector3(0.45f, 0.6f, Appearance.AvatarHeight), isFlying);
3628*/
3629
3630 PhysicsActor = scene.AddAvatar(
3631 LocalId, Firstname + "." + Lastname, pVec,
3632 Appearance.AvatarBoxSize,Appearance.AvatarFeetOffset, isFlying);
3405 3633
3406 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3634 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3407 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3635 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
3408 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong 3636 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
3409 PhysicsActor.SubscribeEvents(500); 3637 PhysicsActor.SubscribeEvents(100);
3410 PhysicsActor.LocalID = LocalId; 3638 PhysicsActor.LocalID = LocalId;
3411 } 3639 }
3412 3640
@@ -3420,6 +3648,7 @@ namespace OpenSim.Region.Framework.Scenes
3420 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); 3648 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true);
3421 } 3649 }
3422 3650
3651
3423 /// <summary> 3652 /// <summary>
3424 /// Event called by the physics plugin to tell the avatar about a collision. 3653 /// Event called by the physics plugin to tell the avatar about a collision.
3425 /// </summary> 3654 /// </summary>
@@ -3433,7 +3662,7 @@ namespace OpenSim.Region.Framework.Scenes
3433 /// <param name="e"></param> 3662 /// <param name="e"></param>
3434 public void PhysicsCollisionUpdate(EventArgs e) 3663 public void PhysicsCollisionUpdate(EventArgs e)
3435 { 3664 {
3436 if (IsChildAgent) 3665 if (IsChildAgent || Animator == null)
3437 return; 3666 return;
3438 3667
3439 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3668 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
@@ -3449,7 +3678,6 @@ namespace OpenSim.Region.Framework.Scenes
3449 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3678 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3450 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3679 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3451 3680
3452 CollisionPlane = Vector4.UnitW;
3453 3681
3454// // No collisions at all means we may be flying. Update always 3682// // No collisions at all means we may be flying. Update always
3455// // to make falling work 3683// // to make falling work
@@ -3461,6 +3689,7 @@ namespace OpenSim.Region.Framework.Scenes
3461 3689
3462 if (coldata.Count != 0) 3690 if (coldata.Count != 0)
3463 { 3691 {
3692/*
3464 switch (Animator.CurrentMovementAnimation) 3693 switch (Animator.CurrentMovementAnimation)
3465 { 3694 {
3466 case "STAND": 3695 case "STAND":
@@ -3469,24 +3698,38 @@ namespace OpenSim.Region.Framework.Scenes
3469 case "CROUCH": 3698 case "CROUCH":
3470 case "CROUCHWALK": 3699 case "CROUCHWALK":
3471 { 3700 {
3701 */
3472 ContactPoint lowest; 3702 ContactPoint lowest;
3473 lowest.SurfaceNormal = Vector3.Zero; 3703 lowest.SurfaceNormal = Vector3.Zero;
3474 lowest.Position = Vector3.Zero; 3704 lowest.Position = Vector3.Zero;
3475 lowest.Position.Z = Single.NaN; 3705 lowest.Position.Z = float.MaxValue;
3476 3706
3477 foreach (ContactPoint contact in coldata.Values) 3707 foreach (ContactPoint contact in coldata.Values)
3478 { 3708 {
3479 if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z) 3709
3710 if (contact.CharacterFeet && contact.Position.Z < lowest.Position.Z)
3480 { 3711 {
3481 lowest = contact; 3712 lowest = contact;
3482 } 3713 }
3483 } 3714 }
3484 3715
3485 CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal)); 3716 if (lowest.Position.Z != float.MaxValue)
3717 {
3718 lowest.SurfaceNormal = -lowest.SurfaceNormal;
3719 CollisionPlane = new Vector4(lowest.SurfaceNormal, Vector3.Dot(lowest.Position, lowest.SurfaceNormal));
3720 }
3721 else
3722 CollisionPlane = Vector4.UnitW;
3723/*
3486 } 3724 }
3487 break; 3725 break;
3488 } 3726 }
3727*/
3489 } 3728 }
3729 else
3730 CollisionPlane = Vector4.UnitW;
3731
3732 RaiseCollisionScriptEvents(coldata);
3490 3733
3491 // Gods do not take damage and Invulnerable is set depending on parcel/region flags 3734 // Gods do not take damage and Invulnerable is set depending on parcel/region flags
3492 if (Invulnerable || GodLevel > 0) 3735 if (Invulnerable || GodLevel > 0)
@@ -3585,6 +3828,13 @@ namespace OpenSim.Region.Framework.Scenes
3585 // m_reprioritizationTimer.Dispose(); 3828 // m_reprioritizationTimer.Dispose();
3586 3829
3587 RemoveFromPhysicalScene(); 3830 RemoveFromPhysicalScene();
3831
3832 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
3833
3834// if (Animator != null)
3835// Animator.Close();
3836 Animator = null;
3837
3588 } 3838 }
3589 3839
3590 public void AddAttachment(SceneObjectGroup gobj) 3840 public void AddAttachment(SceneObjectGroup gobj)
@@ -3818,10 +4068,18 @@ namespace OpenSim.Region.Framework.Scenes
3818 4068
3819 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 4069 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
3820 { 4070 {
4071 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID);
4072 if (p == null)
4073 return;
4074
4075 ControllingClient.SendTakeControls(controls, false, false);
4076 ControllingClient.SendTakeControls(controls, true, false);
4077
3821 ScriptControllers obj = new ScriptControllers(); 4078 ScriptControllers obj = new ScriptControllers();
3822 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 4079 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
3823 obj.eventControls = ScriptControlled.CONTROL_ZERO; 4080 obj.eventControls = ScriptControlled.CONTROL_ZERO;
3824 4081
4082 obj.objectID = p.ParentGroup.UUID;
3825 obj.itemID = Script_item_UUID; 4083 obj.itemID = Script_item_UUID;
3826 if (pass_on == 0 && accept == 0) 4084 if (pass_on == 0 && accept == 0)
3827 { 4085 {
@@ -3870,6 +4128,21 @@ namespace OpenSim.Region.Framework.Scenes
3870 ControllingClient.SendTakeControls(int.MaxValue, false, false); 4128 ControllingClient.SendTakeControls(int.MaxValue, false, false);
3871 } 4129 }
3872 4130
4131 private void UnRegisterSeatControls(UUID obj)
4132 {
4133 List<UUID> takers = new List<UUID>();
4134
4135 foreach (ScriptControllers c in scriptedcontrols.Values)
4136 {
4137 if (c.objectID == obj)
4138 takers.Add(c.itemID);
4139 }
4140 foreach (UUID t in takers)
4141 {
4142 UnRegisterControlEventsToScript(0, t);
4143 }
4144 }
4145
3873 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 4146 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
3874 { 4147 {
3875 ScriptControllers takecontrols; 4148 ScriptControllers takecontrols;
@@ -4199,6 +4472,12 @@ namespace OpenSim.Region.Framework.Scenes
4199 4472
4200 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4473 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
4201 { 4474 {
4475 string reason;
4476
4477 // Honor bans
4478 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
4479 return;
4480
4202 SceneObjectGroup telehub = null; 4481 SceneObjectGroup telehub = null;
4203 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 4482 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
4204 { 4483 {
@@ -4238,11 +4517,206 @@ namespace OpenSim.Region.Framework.Scenes
4238 pos = land.LandData.UserLocation; 4517 pos = land.LandData.UserLocation;
4239 } 4518 }
4240 } 4519 }
4241 4520
4242 land.SendLandUpdateToClient(ControllingClient); 4521 land.SendLandUpdateToClient(ControllingClient);
4243 } 4522 }
4244 } 4523 }
4245 4524
4525 private DetectedObject CreateDetObject(SceneObjectPart obj)
4526 {
4527 DetectedObject detobj = new DetectedObject();
4528 detobj.keyUUID = obj.UUID;
4529 detobj.nameStr = obj.Name;
4530 detobj.ownerUUID = obj.OwnerID;
4531 detobj.posVector = obj.AbsolutePosition;
4532 detobj.rotQuat = obj.GetWorldRotation();
4533 detobj.velVector = obj.Velocity;
4534 detobj.colliderType = 0;
4535 detobj.groupUUID = obj.GroupID;
4536
4537 return detobj;
4538 }
4539
4540 private DetectedObject CreateDetObject(ScenePresence av)
4541 {
4542 DetectedObject detobj = new DetectedObject();
4543 detobj.keyUUID = av.UUID;
4544 detobj.nameStr = av.ControllingClient.Name;
4545 detobj.ownerUUID = av.UUID;
4546 detobj.posVector = av.AbsolutePosition;
4547 detobj.rotQuat = av.Rotation;
4548 detobj.velVector = av.Velocity;
4549 detobj.colliderType = 0;
4550 detobj.groupUUID = av.ControllingClient.ActiveGroupId;
4551
4552 return detobj;
4553 }
4554
4555 private DetectedObject CreateDetObjectForGround()
4556 {
4557 DetectedObject detobj = new DetectedObject();
4558 detobj.keyUUID = UUID.Zero;
4559 detobj.nameStr = "";
4560 detobj.ownerUUID = UUID.Zero;
4561 detobj.posVector = AbsolutePosition;
4562 detobj.rotQuat = Quaternion.Identity;
4563 detobj.velVector = Vector3.Zero;
4564 detobj.colliderType = 0;
4565 detobj.groupUUID = UUID.Zero;
4566
4567 return detobj;
4568 }
4569
4570 private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
4571 {
4572 ColliderArgs colliderArgs = new ColliderArgs();
4573 List<DetectedObject> colliding = new List<DetectedObject>();
4574 foreach (uint localId in colliders)
4575 {
4576 if (localId == 0)
4577 continue;
4578
4579 SceneObjectPart obj = m_scene.GetSceneObjectPart(localId);
4580 if (obj != null)
4581 {
4582 if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
4583 colliding.Add(CreateDetObject(obj));
4584 }
4585 else
4586 {
4587 ScenePresence av = m_scene.GetScenePresence(localId);
4588 if (av != null && (!av.IsChildAgent))
4589 {
4590 if (!dest.CollisionFilteredOut(av.UUID, av.Name))
4591 colliding.Add(CreateDetObject(av));
4592 }
4593 }
4594 }
4595
4596 colliderArgs.Colliders = colliding;
4597
4598 return colliderArgs;
4599 }
4600
4601 private delegate void ScriptCollidingNotification(uint localID, ColliderArgs message);
4602
4603 private void SendCollisionEvent(SceneObjectGroup dest, scriptEvents ev, List<uint> colliders, ScriptCollidingNotification notify)
4604 {
4605 ColliderArgs CollidingMessage;
4606
4607 if (colliders.Count > 0)
4608 {
4609 if ((dest.RootPart.ScriptEvents & ev) != 0)
4610 {
4611 CollidingMessage = CreateColliderArgs(dest.RootPart, colliders);
4612
4613 if (CollidingMessage.Colliders.Count > 0)
4614 notify(dest.RootPart.LocalId, CollidingMessage);
4615 }
4616 }
4617 }
4618
4619 private void SendLandCollisionEvent(SceneObjectGroup dest, scriptEvents ev, ScriptCollidingNotification notify)
4620 {
4621 if ((dest.RootPart.ScriptEvents & ev) != 0)
4622 {
4623 ColliderArgs LandCollidingMessage = new ColliderArgs();
4624 List<DetectedObject> colliding = new List<DetectedObject>();
4625
4626 colliding.Add(CreateDetObjectForGround());
4627 LandCollidingMessage.Colliders = colliding;
4628
4629 notify(dest.RootPart.LocalId, LandCollidingMessage);
4630 }
4631 }
4632
4633 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4634 {
4635 try
4636 {
4637 List<uint> thisHitColliders = new List<uint>();
4638 List<uint> endedColliders = new List<uint>();
4639 List<uint> startedColliders = new List<uint>();
4640 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
4641 CollisionForSoundInfo soundinfo;
4642 ContactPoint curcontact;
4643
4644 if (coldata.Count == 0)
4645 {
4646 if (m_lastColliders.Count == 0)
4647 return; // nothing to do
4648
4649 foreach (uint localID in m_lastColliders)
4650 {
4651 endedColliders.Add(localID);
4652 }
4653 m_lastColliders.Clear();
4654 }
4655
4656 else
4657 {
4658 foreach (uint id in coldata.Keys)
4659 {
4660 thisHitColliders.Add(id);
4661 if (!m_lastColliders.Contains(id))
4662 {
4663 startedColliders.Add(id);
4664 curcontact = coldata[id];
4665 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
4666 {
4667 soundinfo = new CollisionForSoundInfo();
4668 soundinfo.colliderID = id;
4669 soundinfo.position = curcontact.Position;
4670 soundinfo.relativeVel = curcontact.RelativeSpeed;
4671 soundinfolist.Add(soundinfo);
4672 }
4673 }
4674 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4675 }
4676
4677 // calculate things that ended colliding
4678 foreach (uint localID in m_lastColliders)
4679 {
4680 if (!thisHitColliders.Contains(localID))
4681 {
4682 endedColliders.Add(localID);
4683 }
4684 }
4685 //add the items that started colliding this time to the last colliders list.
4686 foreach (uint localID in startedColliders)
4687 {
4688 m_lastColliders.Add(localID);
4689 }
4690 // remove things that ended colliding from the last colliders list
4691 foreach (uint localID in endedColliders)
4692 {
4693 m_lastColliders.Remove(localID);
4694 }
4695
4696 if (soundinfolist.Count > 0)
4697 CollisionSounds.AvatarCollisionSound(this, soundinfolist);
4698 }
4699
4700 foreach (SceneObjectGroup att in GetAttachments())
4701 {
4702 SendCollisionEvent(att, scriptEvents.collision_start, startedColliders, m_scene.EventManager.TriggerScriptCollidingStart);
4703 SendCollisionEvent(att, scriptEvents.collision , m_lastColliders , m_scene.EventManager.TriggerScriptColliding);
4704 SendCollisionEvent(att, scriptEvents.collision_end , endedColliders , m_scene.EventManager.TriggerScriptCollidingEnd);
4705
4706 if (startedColliders.Contains(0))
4707 SendLandCollisionEvent(att, scriptEvents.land_collision_start, m_scene.EventManager.TriggerScriptLandCollidingStart);
4708 if (m_lastColliders.Contains(0))
4709 SendLandCollisionEvent(att, scriptEvents.land_collision, m_scene.EventManager.TriggerScriptLandColliding);
4710 if (endedColliders.Contains(0))
4711 SendLandCollisionEvent(att, scriptEvents.land_collision_end, m_scene.EventManager.TriggerScriptLandCollidingEnd);
4712 }
4713 }
4714 finally
4715 {
4716 m_collisionEventFlag = false;
4717 }
4718 }
4719
4246 private void TeleportFlagsDebug() { 4720 private void TeleportFlagsDebug() {
4247 4721
4248 // Some temporary debugging help to show all the TeleportFlags we have... 4722 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -4267,6 +4741,5 @@ namespace OpenSim.Region.Framework.Scenes
4267 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4741 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
4268 4742
4269 } 4743 }
4270
4271 } 4744 }
4272} 4745}