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