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.cs1101
1 files changed, 788 insertions, 313 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 4fb9a1b..300ddb3 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,6 +941,38 @@ 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
944 if (ParentUUID != UUID.Zero)
945 {
946 m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID);
947 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID);
948 if (part == null)
949 {
950 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
951 }
952 else
953 {
954 part.ParentGroup.AddAvatar(UUID);
955 if (part.SitTargetPosition != Vector3.Zero)
956 part.SitTargetAvatar = UUID;
957// ParentPosition = part.GetWorldPosition();
958 ParentID = part.LocalId;
959 ParentPart = part;
960 m_pos = m_prevSitOffset;
961// pos = ParentPosition;
962 pos = part.GetWorldPosition();
963 }
964 ParentUUID = UUID.Zero;
965
966 IsChildAgent = false;
967
968// Animator.TrySetMovementAnimation("SIT");
969 }
970 else
971 {
972 IsChildAgent = false;
973 IsLoggingIn = false;
974 }
975
867 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); 976 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
868 977
869 IsChildAgent = false; 978 IsChildAgent = false;
@@ -876,70 +985,106 @@ namespace OpenSim.Region.Framework.Scenes
876 985
877 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 986 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
878 987
879 // Moved this from SendInitialData to ensure that Appearance is initialized 988 UUID groupUUID = UUID.Zero;
880 // before the inventory is processed in MakeRootAgent. This fixes a race condition 989 string GroupName = string.Empty;
881 // related to the handling of attachments 990 ulong groupPowers = 0;
882 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
883 991
884 if (m_scene.TestBorderCross(pos, Cardinals.E)) 992 // ----------------------------------
993 // Previous Agent Difference - AGNI sends an unsolicited AgentDataUpdate upon root agent status
994 try
885 { 995 {
886 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 996 if (gm != null)
887 pos.X = crossedBorder.BorderLine.Z - 1; 997 {
998 groupUUID = ControllingClient.ActiveGroupId;
999 GroupRecord record = gm.GetGroupRecord(groupUUID);
1000 if (record != null)
1001 GroupName = record.GroupName;
1002 GroupMembershipData groupMembershipData = gm.GetMembershipData(groupUUID, m_uuid);
1003 if (groupMembershipData != null)
1004 groupPowers = groupMembershipData.GroupPowers;
1005 }
1006 ControllingClient.SendAgentDataUpdate(m_uuid, groupUUID, Firstname, Lastname, groupPowers, GroupName,
1007 Grouptitle);
888 } 1008 }
889 1009 catch (Exception e)
890 if (m_scene.TestBorderCross(pos, Cardinals.N))
891 { 1010 {
892 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 1011 m_log.Debug("[AGENTUPDATE]: " + e.ToString());
893 pos.Y = crossedBorder.BorderLine.Z - 1;
894 } 1012 }
1013 // ------------------------------------
895 1014
896 CheckAndAdjustLandingPoint(ref pos); 1015 if (ParentID == 0)
897
898 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
899 { 1016 {
900 m_log.WarnFormat( 1017 // Moved this from SendInitialData to ensure that Appearance is initialized
901 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", 1018 // before the inventory is processed in MakeRootAgent. This fixes a race condition
902 pos, Name, UUID); 1019 // related to the handling of attachments
1020 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
1021 if (m_scene.TestBorderCross(pos, Cardinals.E))
1022 {
1023 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
1024 pos.X = crossedBorder.BorderLine.Z - 1;
1025 }
903 1026
904 if (pos.X < 0f) pos.X = 0f; 1027 if (m_scene.TestBorderCross(pos, Cardinals.N))
905 if (pos.Y < 0f) pos.Y = 0f; 1028 {
906 if (pos.Z < 0f) pos.Z = 0f; 1029 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
907 } 1030 pos.Y = crossedBorder.BorderLine.Z - 1;
1031 }
908 1032
909 float localAVHeight = 1.56f; 1033 CheckAndAdjustLandingPoint(ref pos);
910 if (Appearance.AvatarHeight > 0)
911 localAVHeight = Appearance.AvatarHeight;
912 1034
913 float posZLimit = 0; 1035 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
1036 {
1037 m_log.WarnFormat(
1038 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
1039 pos, Name, UUID);
914 1040
915 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 1041 if (pos.X < 0f) pos.X = 0f;
916 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 1042 if (pos.Y < 0f) pos.Y = 0f;
917 1043 if (pos.Z < 0f) pos.Z = 0f;
918 float newPosZ = posZLimit + localAVHeight / 2; 1044 }
919 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
920 {
921 pos.Z = newPosZ;
922 }
923 AbsolutePosition = pos;
924 1045
925 AddToPhysicalScene(isFlying); 1046 float localAVHeight = 1.56f;
1047 if (Appearance.AvatarHeight > 0)
1048 localAVHeight = Appearance.AvatarHeight;
926 1049
927 // XXX: This is to trigger any secondary teleport needed for a megaregion when the user has teleported to a 1050 float posZLimit = 0;
928 // location outside the 'root region' (the south-west 256x256 corner). This is the earlist we can do it
929 // since it requires a physics actor to be present. If it is left any later, then physics appears to reset
930 // the value to a negative position which does not trigger the border cross.
931 // This may not be the best location for this.
932 CheckForBorderCrossing();
933 1051
934 if (ForceFly) 1052 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
935 { 1053 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
936 Flying = true; 1054
937 } 1055 float newPosZ = posZLimit + localAVHeight / 2;
938 else if (FlyDisabled) 1056 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
939 { 1057 {
940 Flying = false; 1058 pos.Z = newPosZ;
941 } 1059 }
1060 AbsolutePosition = pos;
1061
1062 if (m_teleportFlags == TeleportFlags.Default)
1063 {
1064 Vector3 vel = Velocity;
1065 AddToPhysicalScene(isFlying);
1066 if (PhysicsActor != null)
1067 PhysicsActor.SetMomentum(vel);
1068 }
1069 else
1070 AddToPhysicalScene(isFlying);
942 1071
1072 // XXX: This is to trigger any secondary teleport needed for a megaregion when the user has teleported to a
1073 // location outside the 'root region' (the south-west 256x256 corner). This is the earlist we can do it
1074 // since it requires a physics actor to be present. If it is left any later, then physics appears to reset
1075 // the value to a negative position which does not trigger the border cross.
1076 // This may not be the best location for this.
1077 CheckForBorderCrossing();
1078
1079 if (ForceFly)
1080 {
1081 Flying = true;
1082 }
1083 else if (FlyDisabled)
1084 {
1085 Flying = false;
1086 }
1087 }
943 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 1088 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
944 // avatar to return to the standing position in mid-air. On login it looks like this is being sent 1089 // avatar to return to the standing position in mid-air. On login it looks like this is being sent
945 // elsewhere anyway 1090 // elsewhere anyway
@@ -978,17 +1123,22 @@ namespace OpenSim.Region.Framework.Scenes
978 { 1123 {
979 m_log.DebugFormat( 1124 m_log.DebugFormat(
980 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name); 1125 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name);
981 1126
982 // Resume scripts 1127 // Resume scripts
983 foreach (SceneObjectGroup sog in m_attachments) 1128 Util.FireAndForget(delegate(object x) {
984 { 1129 foreach (SceneObjectGroup sog in m_attachments)
985 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); 1130 {
986 sog.ResumeScripts(); 1131 sog.ScheduleGroupForFullUpdate();
987 } 1132 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
1133 sog.ResumeScripts();
1134 }
1135 });
988 } 1136 }
989 } 1137 }
990 } 1138 }
991 1139
1140 SendAvatarDataToAllAgents();
1141
992 // send the animations of the other presences to me 1142 // send the animations of the other presences to me
993 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) 1143 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence)
994 { 1144 {
@@ -999,9 +1149,12 @@ namespace OpenSim.Region.Framework.Scenes
999 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will 1149 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will
1000 // stall on the border crossing since the existing child agent will still have the last movement 1150 // stall on the border crossing since the existing child agent will still have the last movement
1001 // recorded, which stops the input from being processed. 1151 // recorded, which stops the input from being processed.
1152
1002 MovementFlag = 0; 1153 MovementFlag = 0;
1003 1154
1004 m_scene.EventManager.TriggerOnMakeRootAgent(this); 1155 m_scene.EventManager.TriggerOnMakeRootAgent(this);
1156
1157 m_scene.EventManager.OnRegionHeartbeatEnd += RegionHeartbeatEnd;
1005 } 1158 }
1006 1159
1007 public int GetStateSource() 1160 public int GetStateSource()
@@ -1029,12 +1182,16 @@ namespace OpenSim.Region.Framework.Scenes
1029 /// </remarks> 1182 /// </remarks>
1030 public void MakeChildAgent() 1183 public void MakeChildAgent()
1031 { 1184 {
1185 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
1186
1032 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); 1187 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName);
1033 1188
1034 // Reset these so that teleporting in and walking out isn't seen 1189 // Reset these so that teleporting in and walking out isn't seen
1035 // as teleporting back 1190 // as teleporting back
1036 TeleportFlags = TeleportFlags.Default; 1191 TeleportFlags = TeleportFlags.Default;
1037 1192
1193 MovementFlag = 0;
1194
1038 // It looks like Animator is set to null somewhere, and MakeChild 1195 // It looks like Animator is set to null somewhere, and MakeChild
1039 // is called after that. Probably in aborted teleports. 1196 // is called after that. Probably in aborted teleports.
1040 if (Animator == null) 1197 if (Animator == null)
@@ -1042,6 +1199,7 @@ namespace OpenSim.Region.Framework.Scenes
1042 else 1199 else
1043 Animator.ResetAnimations(); 1200 Animator.ResetAnimations();
1044 1201
1202
1045// m_log.DebugFormat( 1203// m_log.DebugFormat(
1046// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", 1204// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
1047// Name, UUID, m_scene.RegionInfo.RegionName); 1205// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -1053,6 +1211,7 @@ namespace OpenSim.Region.Framework.Scenes
1053 IsChildAgent = true; 1211 IsChildAgent = true;
1054 m_scene.SwapRootAgentCount(true); 1212 m_scene.SwapRootAgentCount(true);
1055 RemoveFromPhysicalScene(); 1213 RemoveFromPhysicalScene();
1214 ParentID = 0; // Child agents can't be sitting
1056 1215
1057 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into 1216 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into
1058 1217
@@ -1068,9 +1227,9 @@ namespace OpenSim.Region.Framework.Scenes
1068 { 1227 {
1069// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1228// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
1070 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall; 1229 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall;
1071 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1072 PhysicsActor.UnSubscribeEvents();
1073 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1230 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
1231 PhysicsActor.UnSubscribeEvents();
1232 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1074 PhysicsActor = null; 1233 PhysicsActor = null;
1075 } 1234 }
1076// else 1235// else
@@ -1087,7 +1246,7 @@ namespace OpenSim.Region.Framework.Scenes
1087 /// <param name="pos"></param> 1246 /// <param name="pos"></param>
1088 public void Teleport(Vector3 pos) 1247 public void Teleport(Vector3 pos)
1089 { 1248 {
1090 TeleportWithMomentum(pos, null); 1249 TeleportWithMomentum(pos, Vector3.Zero);
1091 } 1250 }
1092 1251
1093 public void TeleportWithMomentum(Vector3 pos, Vector3? v) 1252 public void TeleportWithMomentum(Vector3 pos, Vector3? v)
@@ -1111,6 +1270,41 @@ namespace OpenSim.Region.Framework.Scenes
1111 SendTerseUpdateToAllClients(); 1270 SendTerseUpdateToAllClients();
1112 } 1271 }
1113 1272
1273 public void avnLocalTeleport(Vector3 newpos, Vector3? newvel, bool rotateToVelXY)
1274 {
1275 CheckLandingPoint(ref newpos);
1276 AbsolutePosition = newpos;
1277
1278 if (newvel.HasValue)
1279 {
1280 if ((Vector3)newvel == Vector3.Zero)
1281 {
1282 if (PhysicsActor != null)
1283 PhysicsActor.SetMomentum(Vector3.Zero);
1284 m_velocity = Vector3.Zero;
1285 }
1286 else
1287 {
1288 if (PhysicsActor != null)
1289 PhysicsActor.SetMomentum((Vector3)newvel);
1290 m_velocity = (Vector3)newvel;
1291
1292 if (rotateToVelXY)
1293 {
1294 Vector3 lookAt = (Vector3)newvel;
1295 lookAt.Z = 0;
1296 lookAt.Normalize();
1297 ControllingClient.SendLocalTeleport(newpos, lookAt, (uint)TeleportFlags.ViaLocation);
1298 return;
1299 }
1300 }
1301 }
1302
1303 SendTerseUpdateToAllClients();
1304 }
1305
1306
1307
1114 public void StopFlying() 1308 public void StopFlying()
1115 { 1309 {
1116 ControllingClient.StopFlying(this); 1310 ControllingClient.StopFlying(this);
@@ -1280,6 +1474,13 @@ namespace OpenSim.Region.Framework.Scenes
1280 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height); 1474 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height);
1281 } 1475 }
1282 1476
1477 public void SetSize(Vector3 size, float feetoffset)
1478 {
1479 if (PhysicsActor != null && !IsChildAgent)
1480 PhysicsActor.setAvatarSize(size, feetoffset);
1481
1482 }
1483
1283 /// <summary> 1484 /// <summary>
1284 /// Complete Avatar's movement into the region. 1485 /// Complete Avatar's movement into the region.
1285 /// </summary> 1486 /// </summary>
@@ -1299,7 +1500,8 @@ namespace OpenSim.Region.Framework.Scenes
1299 1500
1300 Vector3 look = Velocity; 1501 Vector3 look = Velocity;
1301 1502
1302 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) 1503 // if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
1504 if ((Math.Abs(look.X) < 0.1) && (Math.Abs(look.Y) < 0.1) && (Math.Abs(look.Z) < 0.1))
1303 { 1505 {
1304 look = new Vector3(0.99f, 0.042f, 0); 1506 look = new Vector3(0.99f, 0.042f, 0);
1305 } 1507 }
@@ -1349,13 +1551,15 @@ namespace OpenSim.Region.Framework.Scenes
1349 // Create child agents in neighbouring regions 1551 // Create child agents in neighbouring regions
1350 if (openChildAgents && !IsChildAgent) 1552 if (openChildAgents && !IsChildAgent)
1351 { 1553 {
1554
1352 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); 1555 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
1353 if (m_agentTransfer != null) 1556 if (m_agentTransfer != null)
1354 Util.FireAndForget(delegate { m_agentTransfer.EnableChildAgents(this); }); 1557 m_agentTransfer.EnableChildAgents(this);
1355 1558
1356 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); 1559 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
1357 if (friendsModule != null) 1560 if (friendsModule != null)
1358 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); 1561 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient);
1562
1359 } 1563 }
1360 1564
1361 // XXX: If we force an update here, then multiple attachments do appear correctly on a destination region 1565 // XXX: If we force an update here, then multiple attachments do appear correctly on a destination region
@@ -1380,36 +1584,69 @@ namespace OpenSim.Region.Framework.Scenes
1380 /// <param name="collisionPoint"></param> 1584 /// <param name="collisionPoint"></param>
1381 /// <param name="localid"></param> 1585 /// <param name="localid"></param>
1382 /// <param name="distance"></param> 1586 /// <param name="distance"></param>
1587 ///
1588
1589 private void UpdateCameraCollisionPlane(Vector4 plane)
1590 {
1591 if (m_lastCameraCollisionPlane != plane)
1592 {
1593 m_lastCameraCollisionPlane = plane;
1594 ControllingClient.SendCameraConstraint(plane);
1595 }
1596 }
1597
1383 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) 1598 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal)
1384 { 1599 {
1385 const float POSITION_TOLERANCE = 0.02f; 1600 const float POSITION_TOLERANCE = 0.02f;
1386 const float VELOCITY_TOLERANCE = 0.02f;
1387 const float ROTATION_TOLERANCE = 0.02f; 1601 const float ROTATION_TOLERANCE = 0.02f;
1388 1602
1389 if (m_followCamAuto) 1603 m_doingCamRayCast = false;
1604 if (hitYN && localid != LocalId)
1390 { 1605 {
1391 if (hitYN) 1606 SceneObjectGroup group = m_scene.GetGroupByPrim(localid);
1607 bool IsPrim = group != null;
1608 if (IsPrim)
1392 { 1609 {
1393 CameraConstraintActive = true; 1610 SceneObjectPart part = group.GetPart(localid);
1394 //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); 1611 if (part != null && !part.VolumeDetectActive)
1395 1612 {
1396 Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); 1613 CameraConstraintActive = true;
1397 ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); 1614 pNormal.X = (float) Math.Round(pNormal.X, 2);
1615 pNormal.Y = (float) Math.Round(pNormal.Y, 2);
1616 pNormal.Z = (float) Math.Round(pNormal.Z, 2);
1617 pNormal.Normalize();
1618 collisionPoint.X = (float) Math.Round(collisionPoint.X, 1);
1619 collisionPoint.Y = (float) Math.Round(collisionPoint.Y, 1);
1620 collisionPoint.Z = (float) Math.Round(collisionPoint.Z, 1);
1621
1622 Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z,
1623 Vector3.Dot(collisionPoint, pNormal));
1624 UpdateCameraCollisionPlane(plane);
1625 }
1398 } 1626 }
1399 else 1627 else
1400 { 1628 {
1401 if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || 1629 CameraConstraintActive = true;
1402 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || 1630 pNormal.X = (float) Math.Round(pNormal.X, 2);
1403 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) 1631 pNormal.Y = (float) Math.Round(pNormal.Y, 2);
1404 { 1632 pNormal.Z = (float) Math.Round(pNormal.Z, 2);
1405 if (CameraConstraintActive) 1633 pNormal.Normalize();
1406 { 1634 collisionPoint.X = (float) Math.Round(collisionPoint.X, 1);
1407 ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); 1635 collisionPoint.Y = (float) Math.Round(collisionPoint.Y, 1);
1408 CameraConstraintActive = false; 1636 collisionPoint.Z = (float) Math.Round(collisionPoint.Z, 1);
1409 } 1637
1410 } 1638 Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z,
1639 Vector3.Dot(collisionPoint, pNormal));
1640 UpdateCameraCollisionPlane(plane);
1411 } 1641 }
1412 } 1642 }
1643 else if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
1644 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE))
1645 {
1646 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -9000f); // not right...
1647 UpdateCameraCollisionPlane(plane);
1648 CameraConstraintActive = false;
1649 }
1413 } 1650 }
1414 1651
1415 /// <summary> 1652 /// <summary>
@@ -1483,12 +1720,6 @@ namespace OpenSim.Region.Framework.Scenes
1483 // DrawDistance = agentData.Far; 1720 // DrawDistance = agentData.Far;
1484 DrawDistance = Scene.DefaultDrawDistance; 1721 DrawDistance = Scene.DefaultDrawDistance;
1485 1722
1486 // Check if Client has camera in 'follow cam' or 'build' mode.
1487 Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation);
1488
1489 m_followCamAuto = ((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.98f)
1490 && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false;
1491
1492 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; 1723 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0;
1493 m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; 1724 m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0;
1494 1725
@@ -1508,14 +1739,38 @@ namespace OpenSim.Region.Framework.Scenes
1508 StandUp(); 1739 StandUp();
1509 } 1740 }
1510 1741
1511 //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto);
1512 // Raycast from the avatar's head to the camera to see if there's anything blocking the view 1742 // Raycast from the avatar's head to the camera to see if there's anything blocking the view
1513 if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) 1743 // this exclude checks may not be complete
1744
1745 if (m_movementUpdateCount % NumMovementsBetweenRayCast == 0 && m_scene.PhysicsScene.SupportsRayCast())
1514 { 1746 {
1515 if (m_followCamAuto) 1747 if (!m_doingCamRayCast && !m_mouseLook && ParentID == 0)
1516 { 1748 {
1517 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; 1749 Vector3 posAdjusted = AbsolutePosition;
1518 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); 1750// posAdjusted.Z += 0.5f * Appearance.AvatarSize.Z - 0.5f;
1751 posAdjusted.Z += 1.0f; // viewer current camera focus point
1752 Vector3 tocam = CameraPosition - posAdjusted;
1753 tocam.X = (float)Math.Round(tocam.X, 1);
1754 tocam.Y = (float)Math.Round(tocam.Y, 1);
1755 tocam.Z = (float)Math.Round(tocam.Z, 1);
1756
1757 float distTocamlen = tocam.Length();
1758 if (distTocamlen > 0.3f)
1759 {
1760 tocam *= (1.0f / distTocamlen);
1761 posAdjusted.X = (float)Math.Round(posAdjusted.X, 1);
1762 posAdjusted.Y = (float)Math.Round(posAdjusted.Y, 1);
1763 posAdjusted.Z = (float)Math.Round(posAdjusted.Z, 1);
1764
1765 m_doingCamRayCast = true;
1766 m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback);
1767 }
1768 }
1769 else if (CameraConstraintActive && (m_mouseLook || ParentID != 0))
1770 {
1771 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right...
1772 UpdateCameraCollisionPlane(plane);
1773 CameraConstraintActive = false;
1519 } 1774 }
1520 } 1775 }
1521 1776
@@ -1980,7 +2235,8 @@ namespace OpenSim.Region.Framework.Scenes
1980// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name); 2235// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name);
1981 2236
1982 MovingToTarget = false; 2237 MovingToTarget = false;
1983 MoveToPositionTarget = Vector3.Zero; 2238// MoveToPositionTarget = Vector3.Zero;
2239 m_forceToApply = null; // cancel possible last action
1984 2240
1985 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct 2241 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct
1986 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag. 2242 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag.
@@ -1998,12 +2254,17 @@ namespace OpenSim.Region.Framework.Scenes
1998// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); 2254// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name);
1999 2255
2000 SitGround = false; 2256 SitGround = false;
2257
2258/* move this down so avatar gets physical in the new position and not where it is siting
2001 if (PhysicsActor == null) 2259 if (PhysicsActor == null)
2002 AddToPhysicalScene(false); 2260 AddToPhysicalScene(false);
2261 */
2003 2262
2004 if (ParentID != 0) 2263 if (ParentID != 0)
2005 { 2264 {
2006 SceneObjectPart part = ParentPart; 2265 SceneObjectPart part = ParentPart;
2266 UnRegisterSeatControls(part.ParentGroup.UUID);
2267
2007 TaskInventoryDictionary taskIDict = part.TaskInventory; 2268 TaskInventoryDictionary taskIDict = part.TaskInventory;
2008 if (taskIDict != null) 2269 if (taskIDict != null)
2009 { 2270 {
@@ -2019,14 +2280,22 @@ namespace OpenSim.Region.Framework.Scenes
2019 } 2280 }
2020 } 2281 }
2021 2282
2022 ParentPosition = part.GetWorldPosition(); 2283 part.ParentGroup.DeleteAvatar(UUID);
2284// ParentPosition = part.GetWorldPosition();
2023 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 2285 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
2024 2286
2025 m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight); 2287// m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
2026 ParentPosition = Vector3.Zero; 2288// ParentPosition = Vector3.Zero;
2289 m_pos = part.AbsolutePosition + (m_pos * part.GetWorldRotation()) + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
2290 if (part.SitTargetAvatar == UUID)
2291 m_bodyRot = part.GetWorldRotation() * part.SitTargetOrientation;
2027 2292
2028 ParentID = 0; 2293 ParentID = 0;
2029 ParentPart = null; 2294 ParentPart = null;
2295
2296 if (PhysicsActor == null)
2297 AddToPhysicalScene(false);
2298
2030 SendAvatarDataToAllAgents(); 2299 SendAvatarDataToAllAgents();
2031 m_requestedSitTargetID = 0; 2300 m_requestedSitTargetID = 0;
2032 2301
@@ -2036,6 +2305,9 @@ namespace OpenSim.Region.Framework.Scenes
2036 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 2305 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2037 } 2306 }
2038 2307
2308 else if (PhysicsActor == null)
2309 AddToPhysicalScene(false);
2310
2039 Animator.TrySetMovementAnimation("STAND"); 2311 Animator.TrySetMovementAnimation("STAND");
2040 } 2312 }
2041 2313
@@ -2083,11 +2355,8 @@ namespace OpenSim.Region.Framework.Scenes
2083 if (part == null) 2355 if (part == null)
2084 return; 2356 return;
2085 2357
2086 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
2087 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
2088
2089 if (PhysicsActor != null) 2358 if (PhysicsActor != null)
2090 m_sitAvatarHeight = PhysicsActor.Size.Z; 2359 m_sitAvatarHeight = PhysicsActor.Size.Z * 0.5f;
2091 2360
2092 bool canSit = false; 2361 bool canSit = false;
2093 Vector3 pos = part.AbsolutePosition + offset; 2362 Vector3 pos = part.AbsolutePosition + offset;
@@ -2104,31 +2373,31 @@ namespace OpenSim.Region.Framework.Scenes
2104 } 2373 }
2105 else 2374 else
2106 { 2375 {
2376 if (PhysicsSit(part,offset)) // physics engine
2377 return;
2378
2107 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10) 2379 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10)
2108 { 2380 {
2109// m_log.DebugFormat(
2110// "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is unset and within 10m",
2111// Name, part.Name, part.LocalId);
2112 2381
2113 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 2382 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
2114 canSit = true; 2383 canSit = true;
2115 } 2384 }
2116// else
2117// {
2118// m_log.DebugFormat(
2119// "[SCENE PRESENCE]: Ignoring sit request of {0} on {1} {2} because sit target is unset and outside 10m",
2120// Name, part.Name, part.LocalId);
2121// }
2122 } 2385 }
2123 2386
2124 if (canSit) 2387 if (canSit)
2125 { 2388 {
2389
2126 if (PhysicsActor != null) 2390 if (PhysicsActor != null)
2127 { 2391 {
2128 // We can remove the physicsActor until they stand up. 2392 // We can remove the physicsActor until they stand up.
2129 RemoveFromPhysicalScene(); 2393 RemoveFromPhysicalScene();
2130 } 2394 }
2131 2395
2396 if (MovingToTarget)
2397 ResetMoveToTarget();
2398
2399 Velocity = Vector3.Zero;
2400
2132 part.AddSittingAvatar(UUID); 2401 part.AddSittingAvatar(UUID);
2133 2402
2134 cameraAtOffset = part.GetCameraAtOffset(); 2403 cameraAtOffset = part.GetCameraAtOffset();
@@ -2136,7 +2405,7 @@ namespace OpenSim.Region.Framework.Scenes
2136 forceMouselook = part.GetForceMouselook(); 2405 forceMouselook = part.GetForceMouselook();
2137 2406
2138 ControllingClient.SendSitResponse( 2407 ControllingClient.SendSitResponse(
2139 targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 2408 part.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
2140 2409
2141 m_requestedSitTargetUUID = targetID; 2410 m_requestedSitTargetUUID = targetID;
2142 2411
@@ -2150,6 +2419,9 @@ namespace OpenSim.Region.Framework.Scenes
2150 2419
2151 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) 2420 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset)
2152 { 2421 {
2422 if (IsChildAgent)
2423 return;
2424
2153 if (ParentID != 0) 2425 if (ParentID != 0)
2154 { 2426 {
2155 if (ParentPart.UUID == targetID) 2427 if (ParentPart.UUID == targetID)
@@ -2165,14 +2437,6 @@ namespace OpenSim.Region.Framework.Scenes
2165 m_requestedSitTargetID = part.LocalId; 2437 m_requestedSitTargetID = part.LocalId;
2166 m_requestedSitTargetUUID = targetID; 2438 m_requestedSitTargetUUID = targetID;
2167 2439
2168// m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset);
2169
2170 if (m_scene.PhysicsScene.SupportsRayCast())
2171 {
2172 //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback());
2173 //SitRayCastAvatarPosition(part);
2174 //return;
2175 }
2176 } 2440 }
2177 else 2441 else
2178 { 2442 {
@@ -2182,197 +2446,111 @@ namespace OpenSim.Region.Framework.Scenes
2182 SendSitResponse(targetID, offset, Quaternion.Identity); 2446 SendSitResponse(targetID, offset, Quaternion.Identity);
2183 } 2447 }
2184 2448
2185 /* 2449 // returns false if does not suport so older sit can be tried
2186 public void SitRayCastAvatarPosition(SceneObjectPart part) 2450 public bool PhysicsSit(SceneObjectPart part, Vector3 offset)
2187 { 2451 {
2188 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2452 if (part == null || part.ParentGroup.IsAttachment)
2189 Vector3 StartRayCastPosition = AbsolutePosition;
2190 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2191 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2192 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionResponse);
2193 }
2194
2195 public void SitRayCastAvatarPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal)
2196 {
2197 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2198 if (part != null)
2199 {
2200 if (hitYN)
2201 {
2202 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2203 {
2204 SitRaycastFindEdge(collisionPoint, normal);
2205 m_log.DebugFormat("[SIT]: Raycast Avatar Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2206 }
2207 else
2208 {
2209 SitRayCastAvatarPositionCameraZ(part);
2210 }
2211 }
2212 else
2213 {
2214 SitRayCastAvatarPositionCameraZ(part);
2215 }
2216 }
2217 else
2218 { 2453 {
2219 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2454 return true;
2220 m_requestedSitTargetUUID = UUID.Zero;
2221 m_requestedSitTargetID = 0;
2222 m_requestedSitOffset = Vector3.Zero;
2223 } 2455 }
2224 2456
2225 } 2457 if ( m_scene.PhysicsScene == null)
2458 return false;
2226 2459
2227 public void SitRayCastAvatarPositionCameraZ(SceneObjectPart part) 2460 if (part.PhysActor == null)
2228 {
2229 // Next, try to raycast from the camera Z position
2230 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2231 Vector3 StartRayCastPosition = AbsolutePosition; StartRayCastPosition.Z = CameraPosition.Z;
2232 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2233 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2234 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionCameraZResponse);
2235 }
2236
2237 public void SitRayCastAvatarPositionCameraZResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal)
2238 {
2239 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2240 if (part != null)
2241 { 2461 {
2242 if (hitYN) 2462 // none physcis shape
2243 { 2463 if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
2244 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) 2464 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2245 {
2246 SitRaycastFindEdge(collisionPoint, normal);
2247 m_log.DebugFormat("[SIT]: Raycast Avatar Position + CameraZ succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2248 }
2249 else
2250 {
2251 SitRayCastCameraPosition(part);
2252 }
2253 }
2254 else 2465 else
2255 { 2466 { // non physical phantom TODO
2256 SitRayCastCameraPosition(part); 2467 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2468 return false;
2257 } 2469 }
2258 } 2470 return true;
2259 else
2260 {
2261 ControllingClient.SendAlertMessage("Sit position no longer exists");
2262 m_requestedSitTargetUUID = UUID.Zero;
2263 m_requestedSitTargetID = 0;
2264 m_requestedSitOffset = Vector3.Zero;
2265 } 2471 }
2266 2472
2267 }
2268 2473
2269 public void SitRayCastCameraPosition(SceneObjectPart part) 2474 // not doing autopilot
2270 { 2475 m_requestedSitTargetID = 0;
2271 // Next, try to raycast from the camera position
2272 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2273 Vector3 StartRayCastPosition = CameraPosition;
2274 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2275 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2276 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastCameraPositionResponse);
2277 }
2278 2476
2279 public void SitRayCastCameraPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2477 if (m_scene.PhysicsScene.SitAvatar(part.PhysActor, AbsolutePosition, CameraPosition, offset, new Vector3(0.35f, 0, 0.65f), PhysicsSitResponse) != 0)
2280 { 2478 return true;
2281 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2282 if (part != null)
2283 {
2284 if (hitYN)
2285 {
2286 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2287 {
2288 SitRaycastFindEdge(collisionPoint, normal);
2289 m_log.DebugFormat("[SIT]: Raycast Camera Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2290 }
2291 else
2292 {
2293 SitRayHorizontal(part);
2294 }
2295 }
2296 else
2297 {
2298 SitRayHorizontal(part);
2299 }
2300 }
2301 else
2302 {
2303 ControllingClient.SendAlertMessage("Sit position no longer exists");
2304 m_requestedSitTargetUUID = UUID.Zero;
2305 m_requestedSitTargetID = 0;
2306 m_requestedSitOffset = Vector3.Zero;
2307 }
2308 2479
2480 return false;
2309 } 2481 }
2310 2482
2311 public void SitRayHorizontal(SceneObjectPart part) 2483
2484 private bool CanEnterLandPosition(Vector3 testPos)
2312 { 2485 {
2313 // Next, try to raycast from the avatar position to fwd 2486 ILandObject land = m_scene.LandChannel.GetLandObject(testPos.X, testPos.Y);
2314 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2487
2315 Vector3 StartRayCastPosition = CameraPosition; 2488 if (land == null || land.LandData.Name == "NO_LAND")
2316 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); 2489 return true;
2317 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); 2490
2318 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastHorizontalResponse); 2491 return land.CanBeOnThisLand(UUID,testPos.Z);
2319 } 2492 }
2320 2493
2321 public void SitRayCastHorizontalResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2494 // status
2495 // < 0 ignore
2496 // 0 bad sit spot
2497 public void PhysicsSitResponse(int status, uint partID, Vector3 offset, Quaternion Orientation)
2322 { 2498 {
2323 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); 2499 if (status < 0)
2324 if (part != null) 2500 return;
2501
2502 if (status == 0)
2325 { 2503 {
2326 if (hitYN) 2504 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2327 { 2505 return;
2328 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2329 {
2330 SitRaycastFindEdge(collisionPoint, normal);
2331 m_log.DebugFormat("[SIT]: Raycast Horizontal Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2332 // Next, try to raycast from the camera position
2333 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2334 Vector3 StartRayCastPosition = CameraPosition;
2335 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2336 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2337 //m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastResponseAvatarPosition);
2338 }
2339 else
2340 {
2341 ControllingClient.SendAlertMessage("Sit position not accessable.");
2342 m_requestedSitTargetUUID = UUID.Zero;
2343 m_requestedSitTargetID = 0;
2344 m_requestedSitOffset = Vector3.Zero;
2345 }
2346 }
2347 else
2348 {
2349 ControllingClient.SendAlertMessage("Sit position not accessable.");
2350 m_requestedSitTargetUUID = UUID.Zero;
2351 m_requestedSitTargetID = 0;
2352 m_requestedSitOffset = Vector3.Zero;
2353 }
2354 } 2506 }
2355 else 2507
2508 SceneObjectPart part = m_scene.GetSceneObjectPart(partID);
2509 if (part == null)
2510 return;
2511
2512 Vector3 targetPos = part.GetWorldPosition() + offset * part.GetWorldRotation();
2513 if(!CanEnterLandPosition(targetPos))
2356 { 2514 {
2357 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2515 ControllingClient.SendAlertMessage(" Sit position on restricted land, try another spot");
2358 m_requestedSitTargetUUID = UUID.Zero; 2516 return;
2359 m_requestedSitTargetID = 0;
2360 m_requestedSitOffset = Vector3.Zero;
2361 } 2517 }
2362 2518
2363 } 2519 RemoveFromPhysicalScene();
2364 2520
2365 private void SitRaycastFindEdge(Vector3 collisionPoint, Vector3 collisionNormal) 2521 if (MovingToTarget)
2366 { 2522 ResetMoveToTarget();
2367 int i = 0; 2523
2368 //throw new NotImplementedException(); 2524 Velocity = Vector3.Zero;
2369 //m_requestedSitTargetUUID = UUID.Zero; 2525
2370 //m_requestedSitTargetID = 0; 2526 part.AddSittingAvatar(UUID);
2371 //m_requestedSitOffset = Vector3.Zero;
2372 2527
2373 SendSitResponse(ControllingClient, m_requestedSitTargetUUID, collisionPoint - m_requestedSitOffset, Quaternion.Identity); 2528 Vector3 cameraAtOffset = part.GetCameraAtOffset();
2529 Vector3 cameraEyeOffset = part.GetCameraEyeOffset();
2530 bool forceMouselook = part.GetForceMouselook();
2531
2532 ControllingClient.SendSitResponse(
2533 part.UUID, offset, Orientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
2534
2535 // not using autopilot
2536
2537 Rotation = Orientation;
2538 m_pos = offset;
2539
2540 m_requestedSitTargetID = 0;
2541 part.ParentGroup.AddAvatar(UUID);
2542
2543 ParentPart = part;
2544 ParentID = part.LocalId;
2545 if(status == 3)
2546 Animator.TrySetMovementAnimation("SIT_GROUND");
2547 else
2548 Animator.TrySetMovementAnimation("SIT");
2549 SendAvatarDataToAllAgents();
2550
2551 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2374 } 2552 }
2375 */ 2553
2376 2554
2377 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) 2555 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID)
2378 { 2556 {
@@ -2389,6 +2567,7 @@ namespace OpenSim.Region.Framework.Scenes
2389 return; 2567 return;
2390 } 2568 }
2391 2569
2570
2392 if (part.SitTargetAvatar == UUID) 2571 if (part.SitTargetAvatar == UUID)
2393 { 2572 {
2394 Vector3 sitTargetPos = part.SitTargetPosition; 2573 Vector3 sitTargetPos = part.SitTargetPosition;
@@ -2403,14 +2582,39 @@ namespace OpenSim.Region.Framework.Scenes
2403 2582
2404 //Quaternion result = (sitTargetOrient * vq) * nq; 2583 //Quaternion result = (sitTargetOrient * vq) * nq;
2405 2584
2406 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2585 double x, y, z, m;
2586
2587 Quaternion r = sitTargetOrient;
2588 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2589
2590 if (Math.Abs(1.0 - m) > 0.000001)
2591 {
2592 m = 1.0 / Math.Sqrt(m);
2593 r.X *= (float)m;
2594 r.Y *= (float)m;
2595 r.Z *= (float)m;
2596 r.W *= (float)m;
2597 }
2598
2599 x = 2 * (r.X * r.Z + r.Y * r.W);
2600 y = 2 * (-r.X * r.W + r.Y * r.Z);
2601 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2602
2603 Vector3 up = new Vector3((float)x, (float)y, (float)z);
2604 Vector3 sitOffset = up * Appearance.AvatarHeight * 0.02638f;
2605
2606 m_pos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT;
2607
2608// m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT - sitOffset;
2407 Rotation = sitTargetOrient; 2609 Rotation = sitTargetOrient;
2408 ParentPosition = part.AbsolutePosition; 2610// ParentPosition = part.AbsolutePosition;
2611 part.ParentGroup.AddAvatar(UUID);
2409 } 2612 }
2410 else 2613 else
2411 { 2614 {
2412 m_pos -= part.AbsolutePosition; 2615 m_pos -= part.AbsolutePosition;
2413 ParentPosition = part.AbsolutePosition; 2616// ParentPosition = part.AbsolutePosition;
2617 part.ParentGroup.AddAvatar(UUID);
2414 2618
2415// m_log.DebugFormat( 2619// m_log.DebugFormat(
2416// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2620// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -2461,6 +2665,13 @@ namespace OpenSim.Region.Framework.Scenes
2461 Animator.RemoveAnimation(animID, false); 2665 Animator.RemoveAnimation(animID, false);
2462 } 2666 }
2463 2667
2668 public void avnHandleChangeAnim(UUID animID, bool addRemove,bool sendPack)
2669 {
2670 Animator.avnChangeAnim(animID, addRemove, sendPack);
2671 }
2672
2673
2674
2464 /// <summary> 2675 /// <summary>
2465 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector 2676 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
2466 /// </summary> 2677 /// </summary>
@@ -2517,8 +2728,8 @@ namespace OpenSim.Region.Framework.Scenes
2517 direc.Z *= 2.6f; 2728 direc.Z *= 2.6f;
2518 2729
2519 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2730 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
2520 Animator.TrySetMovementAnimation("PREJUMP"); 2731// Animator.TrySetMovementAnimation("PREJUMP");
2521 Animator.TrySetMovementAnimation("JUMP"); 2732// Animator.TrySetMovementAnimation("JUMP");
2522 } 2733 }
2523 } 2734 }
2524 } 2735 }
@@ -2527,6 +2738,7 @@ namespace OpenSim.Region.Framework.Scenes
2527 2738
2528 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2739 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2529 m_forceToApply = direc; 2740 m_forceToApply = direc;
2741 Animator.UpdateMovementAnimations();
2530 } 2742 }
2531 2743
2532 #endregion 2744 #endregion
@@ -2544,16 +2756,12 @@ namespace OpenSim.Region.Framework.Scenes
2544 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to 2756 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to
2545 // grab the latest PhysicsActor velocity, whereas m_velocity is often 2757 // grab the latest PhysicsActor velocity, whereas m_velocity is often
2546 // storing a requested force instead of an actual traveling velocity 2758 // storing a requested force instead of an actual traveling velocity
2759 if (Appearance.AvatarSize != m_lastSize && !IsLoggingIn)
2760 SendAvatarDataToAllAgents();
2547 2761
2548 // Throw away duplicate or insignificant updates 2762 if (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||
2549 if ( 2763 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
2550 // If the velocity has become zero, send it no matter what. 2764 !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))
2551 (Velocity != m_lastVelocity && Velocity == Vector3.Zero)
2552 // otherwise, if things have changed reasonably, send the update
2553 || (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)
2554 || !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE)
2555 || !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)))
2556
2557 { 2765 {
2558 SendTerseUpdateToAllClients(); 2766 SendTerseUpdateToAllClients();
2559 2767
@@ -2742,6 +2950,8 @@ namespace OpenSim.Region.Framework.Scenes
2742 return; 2950 return;
2743 } 2951 }
2744 2952
2953 m_lastSize = Appearance.AvatarSize;
2954
2745 int count = 0; 2955 int count = 0;
2746 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) 2956 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
2747 { 2957 {
@@ -2849,6 +3059,8 @@ namespace OpenSim.Region.Framework.Scenes
2849 3059
2850 avatar.ControllingClient.SendAppearance( 3060 avatar.ControllingClient.SendAppearance(
2851 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes()); 3061 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes());
3062
3063
2852 } 3064 }
2853 3065
2854 #endregion 3066 #endregion
@@ -2923,8 +3135,9 @@ namespace OpenSim.Region.Framework.Scenes
2923 3135
2924 // If we don't have a PhysActor, we can't cross anyway 3136 // If we don't have a PhysActor, we can't cross anyway
2925 // Also don't do this while sat, sitting avatars cross with the 3137 // Also don't do this while sat, sitting avatars cross with the
2926 // object they sit on. 3138 // object they sit on. ParentUUID denoted a pending sit, don't
2927 if (ParentID != 0 || PhysicsActor == null) 3139 // interfere with it.
3140 if (ParentID != 0 || PhysicsActor == null || ParentUUID != UUID.Zero)
2928 return; 3141 return;
2929 3142
2930 if (!IsInTransit) 3143 if (!IsInTransit)
@@ -3189,6 +3402,10 @@ namespace OpenSim.Region.Framework.Scenes
3189 } 3402 }
3190 3403
3191 private static Vector3 marker = new Vector3(-1f, -1f, -1f); 3404 private static Vector3 marker = new Vector3(-1f, -1f, -1f);
3405 private void RaiseUpdateThrottles()
3406 {
3407 m_scene.EventManager.TriggerThrottleUpdate(this);
3408 }
3192 /// <summary> 3409 /// <summary>
3193 /// This updates important decision making data about a child agent 3410 /// This updates important decision making data about a child agent
3194 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region 3411 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region
@@ -3269,6 +3486,9 @@ namespace OpenSim.Region.Framework.Scenes
3269 cAgent.AlwaysRun = SetAlwaysRun; 3486 cAgent.AlwaysRun = SetAlwaysRun;
3270 3487
3271 cAgent.Appearance = new AvatarAppearance(Appearance); 3488 cAgent.Appearance = new AvatarAppearance(Appearance);
3489
3490 cAgent.ParentPart = ParentUUID;
3491 cAgent.SitOffset = m_pos;
3272 3492
3273 lock (scriptedcontrols) 3493 lock (scriptedcontrols)
3274 { 3494 {
@@ -3277,7 +3497,7 @@ namespace OpenSim.Region.Framework.Scenes
3277 3497
3278 foreach (ScriptControllers c in scriptedcontrols.Values) 3498 foreach (ScriptControllers c in scriptedcontrols.Values)
3279 { 3499 {
3280 controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); 3500 controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
3281 } 3501 }
3282 cAgent.Controllers = controls; 3502 cAgent.Controllers = controls;
3283 } 3503 }
@@ -3310,6 +3530,8 @@ namespace OpenSim.Region.Framework.Scenes
3310 CameraAtAxis = cAgent.AtAxis; 3530 CameraAtAxis = cAgent.AtAxis;
3311 CameraLeftAxis = cAgent.LeftAxis; 3531 CameraLeftAxis = cAgent.LeftAxis;
3312 CameraUpAxis = cAgent.UpAxis; 3532 CameraUpAxis = cAgent.UpAxis;
3533 ParentUUID = cAgent.ParentPart;
3534 m_prevSitOffset = cAgent.SitOffset;
3313 3535
3314 // When we get to the point of re-computing neighbors everytime this 3536 // When we get to the point of re-computing neighbors everytime this
3315 // changes, then start using the agent's drawdistance rather than the 3537 // changes, then start using the agent's drawdistance rather than the
@@ -3347,6 +3569,7 @@ namespace OpenSim.Region.Framework.Scenes
3347 foreach (ControllerData c in cAgent.Controllers) 3569 foreach (ControllerData c in cAgent.Controllers)
3348 { 3570 {
3349 ScriptControllers sc = new ScriptControllers(); 3571 ScriptControllers sc = new ScriptControllers();
3572 sc.objectID = c.ObjectID;
3350 sc.itemID = c.ItemID; 3573 sc.itemID = c.ItemID;
3351 sc.ignoreControls = (ScriptControlled)c.IgnoreControls; 3574 sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
3352 sc.eventControls = (ScriptControlled)c.EventControls; 3575 sc.eventControls = (ScriptControlled)c.EventControls;
@@ -3414,20 +3637,27 @@ namespace OpenSim.Region.Framework.Scenes
3414 } 3637 }
3415 3638
3416 if (Appearance.AvatarHeight == 0) 3639 if (Appearance.AvatarHeight == 0)
3417 Appearance.SetHeight(); 3640// Appearance.SetHeight();
3641 Appearance.SetSize(new Vector3(0.45f,0.6f,1.9f));
3418 3642
3419 PhysicsScene scene = m_scene.PhysicsScene; 3643 PhysicsScene scene = m_scene.PhysicsScene;
3420 3644
3421 Vector3 pVec = AbsolutePosition; 3645 Vector3 pVec = AbsolutePosition;
3422 3646
3647/*
3423 PhysicsActor = scene.AddAvatar( 3648 PhysicsActor = scene.AddAvatar(
3424 LocalId, Firstname + "." + Lastname, pVec, 3649 LocalId, Firstname + "." + Lastname, pVec,
3425 new Vector3(0f, 0f, Appearance.AvatarHeight), isFlying); 3650 new Vector3(0.45f, 0.6f, Appearance.AvatarHeight), isFlying);
3651*/
3652
3653 PhysicsActor = scene.AddAvatar(
3654 LocalId, Firstname + "." + Lastname, pVec,
3655 Appearance.AvatarBoxSize,Appearance.AvatarFeetOffset, isFlying);
3426 3656
3427 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3657 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3428 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3658 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
3429 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong 3659 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
3430 PhysicsActor.SubscribeEvents(500); 3660 PhysicsActor.SubscribeEvents(100);
3431 PhysicsActor.LocalID = LocalId; 3661 PhysicsActor.LocalID = LocalId;
3432 } 3662 }
3433 3663
@@ -3441,6 +3671,7 @@ namespace OpenSim.Region.Framework.Scenes
3441 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); 3671 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true);
3442 } 3672 }
3443 3673
3674
3444 /// <summary> 3675 /// <summary>
3445 /// Event called by the physics plugin to tell the avatar about a collision. 3676 /// Event called by the physics plugin to tell the avatar about a collision.
3446 /// </summary> 3677 /// </summary>
@@ -3454,7 +3685,7 @@ namespace OpenSim.Region.Framework.Scenes
3454 /// <param name="e"></param> 3685 /// <param name="e"></param>
3455 public void PhysicsCollisionUpdate(EventArgs e) 3686 public void PhysicsCollisionUpdate(EventArgs e)
3456 { 3687 {
3457 if (IsChildAgent) 3688 if (IsChildAgent || Animator == null)
3458 return; 3689 return;
3459 3690
3460 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3691 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
@@ -3470,7 +3701,6 @@ namespace OpenSim.Region.Framework.Scenes
3470 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3701 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3471 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3702 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3472 3703
3473 CollisionPlane = Vector4.UnitW;
3474 3704
3475// // No collisions at all means we may be flying. Update always 3705// // No collisions at all means we may be flying. Update always
3476// // to make falling work 3706// // to make falling work
@@ -3482,6 +3712,7 @@ namespace OpenSim.Region.Framework.Scenes
3482 3712
3483 if (coldata.Count != 0) 3713 if (coldata.Count != 0)
3484 { 3714 {
3715/*
3485 switch (Animator.CurrentMovementAnimation) 3716 switch (Animator.CurrentMovementAnimation)
3486 { 3717 {
3487 case "STAND": 3718 case "STAND":
@@ -3490,24 +3721,38 @@ namespace OpenSim.Region.Framework.Scenes
3490 case "CROUCH": 3721 case "CROUCH":
3491 case "CROUCHWALK": 3722 case "CROUCHWALK":
3492 { 3723 {
3724 */
3493 ContactPoint lowest; 3725 ContactPoint lowest;
3494 lowest.SurfaceNormal = Vector3.Zero; 3726 lowest.SurfaceNormal = Vector3.Zero;
3495 lowest.Position = Vector3.Zero; 3727 lowest.Position = Vector3.Zero;
3496 lowest.Position.Z = Single.NaN; 3728 lowest.Position.Z = float.MaxValue;
3497 3729
3498 foreach (ContactPoint contact in coldata.Values) 3730 foreach (ContactPoint contact in coldata.Values)
3499 { 3731 {
3500 if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z) 3732
3733 if (contact.CharacterFeet && contact.Position.Z < lowest.Position.Z)
3501 { 3734 {
3502 lowest = contact; 3735 lowest = contact;
3503 } 3736 }
3504 } 3737 }
3505 3738
3506 CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal)); 3739 if (lowest.Position.Z != float.MaxValue)
3740 {
3741 lowest.SurfaceNormal = -lowest.SurfaceNormal;
3742 CollisionPlane = new Vector4(lowest.SurfaceNormal, Vector3.Dot(lowest.Position, lowest.SurfaceNormal));
3743 }
3744 else
3745 CollisionPlane = Vector4.UnitW;
3746/*
3507 } 3747 }
3508 break; 3748 break;
3509 } 3749 }
3750*/
3510 } 3751 }
3752 else
3753 CollisionPlane = Vector4.UnitW;
3754
3755 RaiseCollisionScriptEvents(coldata);
3511 3756
3512 // Gods do not take damage and Invulnerable is set depending on parcel/region flags 3757 // Gods do not take damage and Invulnerable is set depending on parcel/region flags
3513 if (Invulnerable || GodLevel > 0) 3758 if (Invulnerable || GodLevel > 0)
@@ -3606,6 +3851,13 @@ namespace OpenSim.Region.Framework.Scenes
3606 // m_reprioritizationTimer.Dispose(); 3851 // m_reprioritizationTimer.Dispose();
3607 3852
3608 RemoveFromPhysicalScene(); 3853 RemoveFromPhysicalScene();
3854
3855 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
3856
3857// if (Animator != null)
3858// Animator.Close();
3859 Animator = null;
3860
3609 } 3861 }
3610 3862
3611 public void AddAttachment(SceneObjectGroup gobj) 3863 public void AddAttachment(SceneObjectGroup gobj)
@@ -3839,10 +4091,18 @@ namespace OpenSim.Region.Framework.Scenes
3839 4091
3840 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 4092 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
3841 { 4093 {
4094 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID);
4095 if (p == null)
4096 return;
4097
4098 ControllingClient.SendTakeControls(controls, false, false);
4099 ControllingClient.SendTakeControls(controls, true, false);
4100
3842 ScriptControllers obj = new ScriptControllers(); 4101 ScriptControllers obj = new ScriptControllers();
3843 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 4102 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
3844 obj.eventControls = ScriptControlled.CONTROL_ZERO; 4103 obj.eventControls = ScriptControlled.CONTROL_ZERO;
3845 4104
4105 obj.objectID = p.ParentGroup.UUID;
3846 obj.itemID = Script_item_UUID; 4106 obj.itemID = Script_item_UUID;
3847 if (pass_on == 0 && accept == 0) 4107 if (pass_on == 0 && accept == 0)
3848 { 4108 {
@@ -3891,6 +4151,21 @@ namespace OpenSim.Region.Framework.Scenes
3891 ControllingClient.SendTakeControls(int.MaxValue, false, false); 4151 ControllingClient.SendTakeControls(int.MaxValue, false, false);
3892 } 4152 }
3893 4153
4154 private void UnRegisterSeatControls(UUID obj)
4155 {
4156 List<UUID> takers = new List<UUID>();
4157
4158 foreach (ScriptControllers c in scriptedcontrols.Values)
4159 {
4160 if (c.objectID == obj)
4161 takers.Add(c.itemID);
4162 }
4163 foreach (UUID t in takers)
4164 {
4165 UnRegisterControlEventsToScript(0, t);
4166 }
4167 }
4168
3894 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 4169 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
3895 { 4170 {
3896 ScriptControllers takecontrols; 4171 ScriptControllers takecontrols;
@@ -4220,6 +4495,12 @@ namespace OpenSim.Region.Framework.Scenes
4220 4495
4221 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4496 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
4222 { 4497 {
4498 string reason;
4499
4500 // Honor bans
4501 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
4502 return;
4503
4223 SceneObjectGroup telehub = null; 4504 SceneObjectGroup telehub = null;
4224 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 4505 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
4225 { 4506 {
@@ -4259,11 +4540,206 @@ namespace OpenSim.Region.Framework.Scenes
4259 pos = land.LandData.UserLocation; 4540 pos = land.LandData.UserLocation;
4260 } 4541 }
4261 } 4542 }
4262 4543
4263 land.SendLandUpdateToClient(ControllingClient); 4544 land.SendLandUpdateToClient(ControllingClient);
4264 } 4545 }
4265 } 4546 }
4266 4547
4548 private DetectedObject CreateDetObject(SceneObjectPart obj)
4549 {
4550 DetectedObject detobj = new DetectedObject();
4551 detobj.keyUUID = obj.UUID;
4552 detobj.nameStr = obj.Name;
4553 detobj.ownerUUID = obj.OwnerID;
4554 detobj.posVector = obj.AbsolutePosition;
4555 detobj.rotQuat = obj.GetWorldRotation();
4556 detobj.velVector = obj.Velocity;
4557 detobj.colliderType = 0;
4558 detobj.groupUUID = obj.GroupID;
4559
4560 return detobj;
4561 }
4562
4563 private DetectedObject CreateDetObject(ScenePresence av)
4564 {
4565 DetectedObject detobj = new DetectedObject();
4566 detobj.keyUUID = av.UUID;
4567 detobj.nameStr = av.ControllingClient.Name;
4568 detobj.ownerUUID = av.UUID;
4569 detobj.posVector = av.AbsolutePosition;
4570 detobj.rotQuat = av.Rotation;
4571 detobj.velVector = av.Velocity;
4572 detobj.colliderType = 0;
4573 detobj.groupUUID = av.ControllingClient.ActiveGroupId;
4574
4575 return detobj;
4576 }
4577
4578 private DetectedObject CreateDetObjectForGround()
4579 {
4580 DetectedObject detobj = new DetectedObject();
4581 detobj.keyUUID = UUID.Zero;
4582 detobj.nameStr = "";
4583 detobj.ownerUUID = UUID.Zero;
4584 detobj.posVector = AbsolutePosition;
4585 detobj.rotQuat = Quaternion.Identity;
4586 detobj.velVector = Vector3.Zero;
4587 detobj.colliderType = 0;
4588 detobj.groupUUID = UUID.Zero;
4589
4590 return detobj;
4591 }
4592
4593 private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
4594 {
4595 ColliderArgs colliderArgs = new ColliderArgs();
4596 List<DetectedObject> colliding = new List<DetectedObject>();
4597 foreach (uint localId in colliders)
4598 {
4599 if (localId == 0)
4600 continue;
4601
4602 SceneObjectPart obj = m_scene.GetSceneObjectPart(localId);
4603 if (obj != null)
4604 {
4605 if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
4606 colliding.Add(CreateDetObject(obj));
4607 }
4608 else
4609 {
4610 ScenePresence av = m_scene.GetScenePresence(localId);
4611 if (av != null && (!av.IsChildAgent))
4612 {
4613 if (!dest.CollisionFilteredOut(av.UUID, av.Name))
4614 colliding.Add(CreateDetObject(av));
4615 }
4616 }
4617 }
4618
4619 colliderArgs.Colliders = colliding;
4620
4621 return colliderArgs;
4622 }
4623
4624 private delegate void ScriptCollidingNotification(uint localID, ColliderArgs message);
4625
4626 private void SendCollisionEvent(SceneObjectGroup dest, scriptEvents ev, List<uint> colliders, ScriptCollidingNotification notify)
4627 {
4628 ColliderArgs CollidingMessage;
4629
4630 if (colliders.Count > 0)
4631 {
4632 if ((dest.RootPart.ScriptEvents & ev) != 0)
4633 {
4634 CollidingMessage = CreateColliderArgs(dest.RootPart, colliders);
4635
4636 if (CollidingMessage.Colliders.Count > 0)
4637 notify(dest.RootPart.LocalId, CollidingMessage);
4638 }
4639 }
4640 }
4641
4642 private void SendLandCollisionEvent(SceneObjectGroup dest, scriptEvents ev, ScriptCollidingNotification notify)
4643 {
4644 if ((dest.RootPart.ScriptEvents & ev) != 0)
4645 {
4646 ColliderArgs LandCollidingMessage = new ColliderArgs();
4647 List<DetectedObject> colliding = new List<DetectedObject>();
4648
4649 colliding.Add(CreateDetObjectForGround());
4650 LandCollidingMessage.Colliders = colliding;
4651
4652 notify(dest.RootPart.LocalId, LandCollidingMessage);
4653 }
4654 }
4655
4656 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4657 {
4658 try
4659 {
4660 List<uint> thisHitColliders = new List<uint>();
4661 List<uint> endedColliders = new List<uint>();
4662 List<uint> startedColliders = new List<uint>();
4663 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
4664 CollisionForSoundInfo soundinfo;
4665 ContactPoint curcontact;
4666
4667 if (coldata.Count == 0)
4668 {
4669 if (m_lastColliders.Count == 0)
4670 return; // nothing to do
4671
4672 foreach (uint localID in m_lastColliders)
4673 {
4674 endedColliders.Add(localID);
4675 }
4676 m_lastColliders.Clear();
4677 }
4678
4679 else
4680 {
4681 foreach (uint id in coldata.Keys)
4682 {
4683 thisHitColliders.Add(id);
4684 if (!m_lastColliders.Contains(id))
4685 {
4686 startedColliders.Add(id);
4687 curcontact = coldata[id];
4688 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
4689 {
4690 soundinfo = new CollisionForSoundInfo();
4691 soundinfo.colliderID = id;
4692 soundinfo.position = curcontact.Position;
4693 soundinfo.relativeVel = curcontact.RelativeSpeed;
4694 soundinfolist.Add(soundinfo);
4695 }
4696 }
4697 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4698 }
4699
4700 // calculate things that ended colliding
4701 foreach (uint localID in m_lastColliders)
4702 {
4703 if (!thisHitColliders.Contains(localID))
4704 {
4705 endedColliders.Add(localID);
4706 }
4707 }
4708 //add the items that started colliding this time to the last colliders list.
4709 foreach (uint localID in startedColliders)
4710 {
4711 m_lastColliders.Add(localID);
4712 }
4713 // remove things that ended colliding from the last colliders list
4714 foreach (uint localID in endedColliders)
4715 {
4716 m_lastColliders.Remove(localID);
4717 }
4718
4719 if (soundinfolist.Count > 0)
4720 CollisionSounds.AvatarCollisionSound(this, soundinfolist);
4721 }
4722
4723 foreach (SceneObjectGroup att in GetAttachments())
4724 {
4725 SendCollisionEvent(att, scriptEvents.collision_start, startedColliders, m_scene.EventManager.TriggerScriptCollidingStart);
4726 SendCollisionEvent(att, scriptEvents.collision , m_lastColliders , m_scene.EventManager.TriggerScriptColliding);
4727 SendCollisionEvent(att, scriptEvents.collision_end , endedColliders , m_scene.EventManager.TriggerScriptCollidingEnd);
4728
4729 if (startedColliders.Contains(0))
4730 SendLandCollisionEvent(att, scriptEvents.land_collision_start, m_scene.EventManager.TriggerScriptLandCollidingStart);
4731 if (m_lastColliders.Contains(0))
4732 SendLandCollisionEvent(att, scriptEvents.land_collision, m_scene.EventManager.TriggerScriptLandColliding);
4733 if (endedColliders.Contains(0))
4734 SendLandCollisionEvent(att, scriptEvents.land_collision_end, m_scene.EventManager.TriggerScriptLandCollidingEnd);
4735 }
4736 }
4737 finally
4738 {
4739 m_collisionEventFlag = false;
4740 }
4741 }
4742
4267 private void TeleportFlagsDebug() { 4743 private void TeleportFlagsDebug() {
4268 4744
4269 // Some temporary debugging help to show all the TeleportFlags we have... 4745 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -4288,6 +4764,5 @@ namespace OpenSim.Region.Framework.Scenes
4288 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4764 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
4289 4765
4290 } 4766 }
4291
4292 } 4767 }
4293} 4768}