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 9e9089b..5184585 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 }
@@ -1349,13 +1551,15 @@ namespace OpenSim.Region.Framework.Scenes
1349 if (openChildAgents && !IsChildAgent) 1551 if (openChildAgents && !IsChildAgent)
1350 { 1552 {
1351 SendInitialDataToMe(); 1553 SendInitialDataToMe();
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)
1748 {
1749 Vector3 posAdjusted = AbsolutePosition;
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))
1516 { 1770 {
1517 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; 1771 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right...
1518 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); 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)
@@ -3187,6 +3400,10 @@ namespace OpenSim.Region.Framework.Scenes
3187 } 3400 }
3188 3401
3189 private static Vector3 marker = new Vector3(-1f, -1f, -1f); 3402 private static Vector3 marker = new Vector3(-1f, -1f, -1f);
3403 private void RaiseUpdateThrottles()
3404 {
3405 m_scene.EventManager.TriggerThrottleUpdate(this);
3406 }
3190 /// <summary> 3407 /// <summary>
3191 /// This updates important decision making data about a child agent 3408 /// This updates important decision making data about a child agent
3192 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region 3409 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region
@@ -3267,6 +3484,9 @@ namespace OpenSim.Region.Framework.Scenes
3267 cAgent.AlwaysRun = SetAlwaysRun; 3484 cAgent.AlwaysRun = SetAlwaysRun;
3268 3485
3269 cAgent.Appearance = new AvatarAppearance(Appearance); 3486 cAgent.Appearance = new AvatarAppearance(Appearance);
3487
3488 cAgent.ParentPart = ParentUUID;
3489 cAgent.SitOffset = m_pos;
3270 3490
3271 lock (scriptedcontrols) 3491 lock (scriptedcontrols)
3272 { 3492 {
@@ -3275,7 +3495,7 @@ namespace OpenSim.Region.Framework.Scenes
3275 3495
3276 foreach (ScriptControllers c in scriptedcontrols.Values) 3496 foreach (ScriptControllers c in scriptedcontrols.Values)
3277 { 3497 {
3278 controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); 3498 controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
3279 } 3499 }
3280 cAgent.Controllers = controls; 3500 cAgent.Controllers = controls;
3281 } 3501 }
@@ -3308,6 +3528,8 @@ namespace OpenSim.Region.Framework.Scenes
3308 CameraAtAxis = cAgent.AtAxis; 3528 CameraAtAxis = cAgent.AtAxis;
3309 CameraLeftAxis = cAgent.LeftAxis; 3529 CameraLeftAxis = cAgent.LeftAxis;
3310 CameraUpAxis = cAgent.UpAxis; 3530 CameraUpAxis = cAgent.UpAxis;
3531 ParentUUID = cAgent.ParentPart;
3532 m_prevSitOffset = cAgent.SitOffset;
3311 3533
3312 // When we get to the point of re-computing neighbors everytime this 3534 // When we get to the point of re-computing neighbors everytime this
3313 // changes, then start using the agent's drawdistance rather than the 3535 // changes, then start using the agent's drawdistance rather than the
@@ -3345,6 +3567,7 @@ namespace OpenSim.Region.Framework.Scenes
3345 foreach (ControllerData c in cAgent.Controllers) 3567 foreach (ControllerData c in cAgent.Controllers)
3346 { 3568 {
3347 ScriptControllers sc = new ScriptControllers(); 3569 ScriptControllers sc = new ScriptControllers();
3570 sc.objectID = c.ObjectID;
3348 sc.itemID = c.ItemID; 3571 sc.itemID = c.ItemID;
3349 sc.ignoreControls = (ScriptControlled)c.IgnoreControls; 3572 sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
3350 sc.eventControls = (ScriptControlled)c.EventControls; 3573 sc.eventControls = (ScriptControlled)c.EventControls;
@@ -3412,20 +3635,27 @@ namespace OpenSim.Region.Framework.Scenes
3412 } 3635 }
3413 3636
3414 if (Appearance.AvatarHeight == 0) 3637 if (Appearance.AvatarHeight == 0)
3415 Appearance.SetHeight(); 3638// Appearance.SetHeight();
3639 Appearance.SetSize(new Vector3(0.45f,0.6f,1.9f));
3416 3640
3417 PhysicsScene scene = m_scene.PhysicsScene; 3641 PhysicsScene scene = m_scene.PhysicsScene;
3418 3642
3419 Vector3 pVec = AbsolutePosition; 3643 Vector3 pVec = AbsolutePosition;
3420 3644
3645/*
3421 PhysicsActor = scene.AddAvatar( 3646 PhysicsActor = scene.AddAvatar(
3422 LocalId, Firstname + "." + Lastname, pVec, 3647 LocalId, Firstname + "." + Lastname, pVec,
3423 new Vector3(0f, 0f, Appearance.AvatarHeight), isFlying); 3648 new Vector3(0.45f, 0.6f, Appearance.AvatarHeight), isFlying);
3649*/
3650
3651 PhysicsActor = scene.AddAvatar(
3652 LocalId, Firstname + "." + Lastname, pVec,
3653 Appearance.AvatarBoxSize,Appearance.AvatarFeetOffset, isFlying);
3424 3654
3425 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3655 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3426 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3656 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
3427 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong 3657 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
3428 PhysicsActor.SubscribeEvents(500); 3658 PhysicsActor.SubscribeEvents(100);
3429 PhysicsActor.LocalID = LocalId; 3659 PhysicsActor.LocalID = LocalId;
3430 } 3660 }
3431 3661
@@ -3439,6 +3669,7 @@ namespace OpenSim.Region.Framework.Scenes
3439 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); 3669 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true);
3440 } 3670 }
3441 3671
3672
3442 /// <summary> 3673 /// <summary>
3443 /// Event called by the physics plugin to tell the avatar about a collision. 3674 /// Event called by the physics plugin to tell the avatar about a collision.
3444 /// </summary> 3675 /// </summary>
@@ -3452,7 +3683,7 @@ namespace OpenSim.Region.Framework.Scenes
3452 /// <param name="e"></param> 3683 /// <param name="e"></param>
3453 public void PhysicsCollisionUpdate(EventArgs e) 3684 public void PhysicsCollisionUpdate(EventArgs e)
3454 { 3685 {
3455 if (IsChildAgent) 3686 if (IsChildAgent || Animator == null)
3456 return; 3687 return;
3457 3688
3458 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3689 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
@@ -3468,7 +3699,6 @@ namespace OpenSim.Region.Framework.Scenes
3468 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3699 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3469 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3700 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3470 3701
3471 CollisionPlane = Vector4.UnitW;
3472 3702
3473// // No collisions at all means we may be flying. Update always 3703// // No collisions at all means we may be flying. Update always
3474// // to make falling work 3704// // to make falling work
@@ -3480,6 +3710,7 @@ namespace OpenSim.Region.Framework.Scenes
3480 3710
3481 if (coldata.Count != 0) 3711 if (coldata.Count != 0)
3482 { 3712 {
3713/*
3483 switch (Animator.CurrentMovementAnimation) 3714 switch (Animator.CurrentMovementAnimation)
3484 { 3715 {
3485 case "STAND": 3716 case "STAND":
@@ -3488,24 +3719,38 @@ namespace OpenSim.Region.Framework.Scenes
3488 case "CROUCH": 3719 case "CROUCH":
3489 case "CROUCHWALK": 3720 case "CROUCHWALK":
3490 { 3721 {
3722 */
3491 ContactPoint lowest; 3723 ContactPoint lowest;
3492 lowest.SurfaceNormal = Vector3.Zero; 3724 lowest.SurfaceNormal = Vector3.Zero;
3493 lowest.Position = Vector3.Zero; 3725 lowest.Position = Vector3.Zero;
3494 lowest.Position.Z = Single.NaN; 3726 lowest.Position.Z = float.MaxValue;
3495 3727
3496 foreach (ContactPoint contact in coldata.Values) 3728 foreach (ContactPoint contact in coldata.Values)
3497 { 3729 {
3498 if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z) 3730
3731 if (contact.CharacterFeet && contact.Position.Z < lowest.Position.Z)
3499 { 3732 {
3500 lowest = contact; 3733 lowest = contact;
3501 } 3734 }
3502 } 3735 }
3503 3736
3504 CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal)); 3737 if (lowest.Position.Z != float.MaxValue)
3738 {
3739 lowest.SurfaceNormal = -lowest.SurfaceNormal;
3740 CollisionPlane = new Vector4(lowest.SurfaceNormal, Vector3.Dot(lowest.Position, lowest.SurfaceNormal));
3741 }
3742 else
3743 CollisionPlane = Vector4.UnitW;
3744/*
3505 } 3745 }
3506 break; 3746 break;
3507 } 3747 }
3748*/
3508 } 3749 }
3750 else
3751 CollisionPlane = Vector4.UnitW;
3752
3753 RaiseCollisionScriptEvents(coldata);
3509 3754
3510 // Gods do not take damage and Invulnerable is set depending on parcel/region flags 3755 // Gods do not take damage and Invulnerable is set depending on parcel/region flags
3511 if (Invulnerable || GodLevel > 0) 3756 if (Invulnerable || GodLevel > 0)
@@ -3604,6 +3849,13 @@ namespace OpenSim.Region.Framework.Scenes
3604 // m_reprioritizationTimer.Dispose(); 3849 // m_reprioritizationTimer.Dispose();
3605 3850
3606 RemoveFromPhysicalScene(); 3851 RemoveFromPhysicalScene();
3852
3853 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
3854
3855// if (Animator != null)
3856// Animator.Close();
3857 Animator = null;
3858
3607 } 3859 }
3608 3860
3609 public void AddAttachment(SceneObjectGroup gobj) 3861 public void AddAttachment(SceneObjectGroup gobj)
@@ -3837,10 +4089,18 @@ namespace OpenSim.Region.Framework.Scenes
3837 4089
3838 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 4090 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
3839 { 4091 {
4092 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID);
4093 if (p == null)
4094 return;
4095
4096 ControllingClient.SendTakeControls(controls, false, false);
4097 ControllingClient.SendTakeControls(controls, true, false);
4098
3840 ScriptControllers obj = new ScriptControllers(); 4099 ScriptControllers obj = new ScriptControllers();
3841 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 4100 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
3842 obj.eventControls = ScriptControlled.CONTROL_ZERO; 4101 obj.eventControls = ScriptControlled.CONTROL_ZERO;
3843 4102
4103 obj.objectID = p.ParentGroup.UUID;
3844 obj.itemID = Script_item_UUID; 4104 obj.itemID = Script_item_UUID;
3845 if (pass_on == 0 && accept == 0) 4105 if (pass_on == 0 && accept == 0)
3846 { 4106 {
@@ -3889,6 +4149,21 @@ namespace OpenSim.Region.Framework.Scenes
3889 ControllingClient.SendTakeControls(int.MaxValue, false, false); 4149 ControllingClient.SendTakeControls(int.MaxValue, false, false);
3890 } 4150 }
3891 4151
4152 private void UnRegisterSeatControls(UUID obj)
4153 {
4154 List<UUID> takers = new List<UUID>();
4155
4156 foreach (ScriptControllers c in scriptedcontrols.Values)
4157 {
4158 if (c.objectID == obj)
4159 takers.Add(c.itemID);
4160 }
4161 foreach (UUID t in takers)
4162 {
4163 UnRegisterControlEventsToScript(0, t);
4164 }
4165 }
4166
3892 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 4167 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
3893 { 4168 {
3894 ScriptControllers takecontrols; 4169 ScriptControllers takecontrols;
@@ -4218,6 +4493,12 @@ namespace OpenSim.Region.Framework.Scenes
4218 4493
4219 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4494 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
4220 { 4495 {
4496 string reason;
4497
4498 // Honor bans
4499 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
4500 return;
4501
4221 SceneObjectGroup telehub = null; 4502 SceneObjectGroup telehub = null;
4222 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 4503 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
4223 { 4504 {
@@ -4257,11 +4538,206 @@ namespace OpenSim.Region.Framework.Scenes
4257 pos = land.LandData.UserLocation; 4538 pos = land.LandData.UserLocation;
4258 } 4539 }
4259 } 4540 }
4260 4541
4261 land.SendLandUpdateToClient(ControllingClient); 4542 land.SendLandUpdateToClient(ControllingClient);
4262 } 4543 }
4263 } 4544 }
4264 4545
4546 private DetectedObject CreateDetObject(SceneObjectPart obj)
4547 {
4548 DetectedObject detobj = new DetectedObject();
4549 detobj.keyUUID = obj.UUID;
4550 detobj.nameStr = obj.Name;
4551 detobj.ownerUUID = obj.OwnerID;
4552 detobj.posVector = obj.AbsolutePosition;
4553 detobj.rotQuat = obj.GetWorldRotation();
4554 detobj.velVector = obj.Velocity;
4555 detobj.colliderType = 0;
4556 detobj.groupUUID = obj.GroupID;
4557
4558 return detobj;
4559 }
4560
4561 private DetectedObject CreateDetObject(ScenePresence av)
4562 {
4563 DetectedObject detobj = new DetectedObject();
4564 detobj.keyUUID = av.UUID;
4565 detobj.nameStr = av.ControllingClient.Name;
4566 detobj.ownerUUID = av.UUID;
4567 detobj.posVector = av.AbsolutePosition;
4568 detobj.rotQuat = av.Rotation;
4569 detobj.velVector = av.Velocity;
4570 detobj.colliderType = 0;
4571 detobj.groupUUID = av.ControllingClient.ActiveGroupId;
4572
4573 return detobj;
4574 }
4575
4576 private DetectedObject CreateDetObjectForGround()
4577 {
4578 DetectedObject detobj = new DetectedObject();
4579 detobj.keyUUID = UUID.Zero;
4580 detobj.nameStr = "";
4581 detobj.ownerUUID = UUID.Zero;
4582 detobj.posVector = AbsolutePosition;
4583 detobj.rotQuat = Quaternion.Identity;
4584 detobj.velVector = Vector3.Zero;
4585 detobj.colliderType = 0;
4586 detobj.groupUUID = UUID.Zero;
4587
4588 return detobj;
4589 }
4590
4591 private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
4592 {
4593 ColliderArgs colliderArgs = new ColliderArgs();
4594 List<DetectedObject> colliding = new List<DetectedObject>();
4595 foreach (uint localId in colliders)
4596 {
4597 if (localId == 0)
4598 continue;
4599
4600 SceneObjectPart obj = m_scene.GetSceneObjectPart(localId);
4601 if (obj != null)
4602 {
4603 if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
4604 colliding.Add(CreateDetObject(obj));
4605 }
4606 else
4607 {
4608 ScenePresence av = m_scene.GetScenePresence(localId);
4609 if (av != null && (!av.IsChildAgent))
4610 {
4611 if (!dest.CollisionFilteredOut(av.UUID, av.Name))
4612 colliding.Add(CreateDetObject(av));
4613 }
4614 }
4615 }
4616
4617 colliderArgs.Colliders = colliding;
4618
4619 return colliderArgs;
4620 }
4621
4622 private delegate void ScriptCollidingNotification(uint localID, ColliderArgs message);
4623
4624 private void SendCollisionEvent(SceneObjectGroup dest, scriptEvents ev, List<uint> colliders, ScriptCollidingNotification notify)
4625 {
4626 ColliderArgs CollidingMessage;
4627
4628 if (colliders.Count > 0)
4629 {
4630 if ((dest.RootPart.ScriptEvents & ev) != 0)
4631 {
4632 CollidingMessage = CreateColliderArgs(dest.RootPart, colliders);
4633
4634 if (CollidingMessage.Colliders.Count > 0)
4635 notify(dest.RootPart.LocalId, CollidingMessage);
4636 }
4637 }
4638 }
4639
4640 private void SendLandCollisionEvent(SceneObjectGroup dest, scriptEvents ev, ScriptCollidingNotification notify)
4641 {
4642 if ((dest.RootPart.ScriptEvents & ev) != 0)
4643 {
4644 ColliderArgs LandCollidingMessage = new ColliderArgs();
4645 List<DetectedObject> colliding = new List<DetectedObject>();
4646
4647 colliding.Add(CreateDetObjectForGround());
4648 LandCollidingMessage.Colliders = colliding;
4649
4650 notify(dest.RootPart.LocalId, LandCollidingMessage);
4651 }
4652 }
4653
4654 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4655 {
4656 try
4657 {
4658 List<uint> thisHitColliders = new List<uint>();
4659 List<uint> endedColliders = new List<uint>();
4660 List<uint> startedColliders = new List<uint>();
4661 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
4662 CollisionForSoundInfo soundinfo;
4663 ContactPoint curcontact;
4664
4665 if (coldata.Count == 0)
4666 {
4667 if (m_lastColliders.Count == 0)
4668 return; // nothing to do
4669
4670 foreach (uint localID in m_lastColliders)
4671 {
4672 endedColliders.Add(localID);
4673 }
4674 m_lastColliders.Clear();
4675 }
4676
4677 else
4678 {
4679 foreach (uint id in coldata.Keys)
4680 {
4681 thisHitColliders.Add(id);
4682 if (!m_lastColliders.Contains(id))
4683 {
4684 startedColliders.Add(id);
4685 curcontact = coldata[id];
4686 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
4687 {
4688 soundinfo = new CollisionForSoundInfo();
4689 soundinfo.colliderID = id;
4690 soundinfo.position = curcontact.Position;
4691 soundinfo.relativeVel = curcontact.RelativeSpeed;
4692 soundinfolist.Add(soundinfo);
4693 }
4694 }
4695 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4696 }
4697
4698 // calculate things that ended colliding
4699 foreach (uint localID in m_lastColliders)
4700 {
4701 if (!thisHitColliders.Contains(localID))
4702 {
4703 endedColliders.Add(localID);
4704 }
4705 }
4706 //add the items that started colliding this time to the last colliders list.
4707 foreach (uint localID in startedColliders)
4708 {
4709 m_lastColliders.Add(localID);
4710 }
4711 // remove things that ended colliding from the last colliders list
4712 foreach (uint localID in endedColliders)
4713 {
4714 m_lastColliders.Remove(localID);
4715 }
4716
4717 if (soundinfolist.Count > 0)
4718 CollisionSounds.AvatarCollisionSound(this, soundinfolist);
4719 }
4720
4721 foreach (SceneObjectGroup att in GetAttachments())
4722 {
4723 SendCollisionEvent(att, scriptEvents.collision_start, startedColliders, m_scene.EventManager.TriggerScriptCollidingStart);
4724 SendCollisionEvent(att, scriptEvents.collision , m_lastColliders , m_scene.EventManager.TriggerScriptColliding);
4725 SendCollisionEvent(att, scriptEvents.collision_end , endedColliders , m_scene.EventManager.TriggerScriptCollidingEnd);
4726
4727 if (startedColliders.Contains(0))
4728 SendLandCollisionEvent(att, scriptEvents.land_collision_start, m_scene.EventManager.TriggerScriptLandCollidingStart);
4729 if (m_lastColliders.Contains(0))
4730 SendLandCollisionEvent(att, scriptEvents.land_collision, m_scene.EventManager.TriggerScriptLandColliding);
4731 if (endedColliders.Contains(0))
4732 SendLandCollisionEvent(att, scriptEvents.land_collision_end, m_scene.EventManager.TriggerScriptLandCollidingEnd);
4733 }
4734 }
4735 finally
4736 {
4737 m_collisionEventFlag = false;
4738 }
4739 }
4740
4265 private void TeleportFlagsDebug() { 4741 private void TeleportFlagsDebug() {
4266 4742
4267 // Some temporary debugging help to show all the TeleportFlags we have... 4743 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -4286,6 +4762,5 @@ namespace OpenSim.Region.Framework.Scenes
4286 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4762 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
4287 4763
4288 } 4764 }
4289
4290 } 4765 }
4291} 4766}