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.cs289
1 files changed, 211 insertions, 78 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index b2cd249..e55acfe 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -73,7 +73,7 @@ namespace OpenSim.Region.Framework.Scenes
73// { 73// {
74// m_log.Debug("[ScenePresence] Destructor called"); 74// m_log.Debug("[ScenePresence] Destructor called");
75// } 75// }
76 76
77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
78 78
79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
@@ -89,7 +89,9 @@ namespace OpenSim.Region.Framework.Scenes
89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
90 /// issue #1716 90 /// issue #1716
91 /// </summary> 91 /// </summary>
92 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 92// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
93 // Value revised by KF 091121 by comparison with SL.
94 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f);
93 95
94 public UUID currentParcelUUID = UUID.Zero; 96 public UUID currentParcelUUID = UUID.Zero;
95 97
@@ -113,7 +115,9 @@ namespace OpenSim.Region.Framework.Scenes
113 public Vector3 lastKnownAllowedPosition; 115 public Vector3 lastKnownAllowedPosition;
114 public bool sentMessageAboutRestrictedParcelFlyingDown; 116 public bool sentMessageAboutRestrictedParcelFlyingDown;
115 public Vector4 CollisionPlane = Vector4.UnitW; 117 public Vector4 CollisionPlane = Vector4.UnitW;
116 118
119 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
120 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
117 private Vector3 m_lastPosition; 121 private Vector3 m_lastPosition;
118 private Quaternion m_lastRotation; 122 private Quaternion m_lastRotation;
119 private Vector3 m_lastVelocity; 123 private Vector3 m_lastVelocity;
@@ -144,7 +148,6 @@ namespace OpenSim.Region.Framework.Scenes
144 private int m_perfMonMS; 148 private int m_perfMonMS;
145 149
146 private bool m_setAlwaysRun; 150 private bool m_setAlwaysRun;
147
148 private bool m_forceFly; 151 private bool m_forceFly;
149 private bool m_flyDisabled; 152 private bool m_flyDisabled;
150 153
@@ -168,7 +171,8 @@ namespace OpenSim.Region.Framework.Scenes
168 protected RegionInfo m_regionInfo; 171 protected RegionInfo m_regionInfo;
169 protected ulong crossingFromRegion; 172 protected ulong crossingFromRegion;
170 173
171 private readonly Vector3[] Dir_Vectors = new Vector3[6]; 174 private readonly Vector3[] Dir_Vectors = new Vector3[11];
175 private bool m_isNudging = false;
172 176
173 // Position of agent's camera in world (region cordinates) 177 // Position of agent's camera in world (region cordinates)
174 protected Vector3 m_CameraCenter; 178 protected Vector3 m_CameraCenter;
@@ -203,6 +207,9 @@ namespace OpenSim.Region.Framework.Scenes
203 private bool m_followCamAuto; 207 private bool m_followCamAuto;
204 208
205 private int m_movementUpdateCount; 209 private int m_movementUpdateCount;
210 private int m_lastColCount = -1; //KF: Look for Collision chnages
211 private int m_updateCount = 0; //KF: Update Anims for a while
212 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
206 213
207 private const int NumMovementsBetweenRayCast = 5; 214 private const int NumMovementsBetweenRayCast = 5;
208 215
@@ -232,6 +239,10 @@ namespace OpenSim.Region.Framework.Scenes
232 DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG, 239 DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG,
233 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 240 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
234 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 241 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
242 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
243 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
244 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
245 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
235 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 246 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
236 } 247 }
237 248
@@ -658,9 +669,7 @@ namespace OpenSim.Region.Framework.Scenes
658 669
659 AdjustKnownSeeds(); 670 AdjustKnownSeeds();
660 671
661 // TODO: I think, this won't send anything, as we are still a child here... 672 Animator.TrySetMovementAnimation("STAND");
662 Animator.TrySetMovementAnimation("STAND");
663
664 // we created a new ScenePresence (a new child agent) in a fresh region. 673 // we created a new ScenePresence (a new child agent) in a fresh region.
665 // Request info about all the (root) agents in this region 674 // Request info about all the (root) agents in this region
666 // Note: This won't send data *to* other clients in that region (children don't send) 675 // Note: This won't send data *to* other clients in that region (children don't send)
@@ -716,21 +725,47 @@ namespace OpenSim.Region.Framework.Scenes
716 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 725 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
717 Dir_Vectors[4] = Vector3.UnitZ; //UP 726 Dir_Vectors[4] = Vector3.UnitZ; //UP
718 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 727 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
719 Dir_Vectors[5] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 728 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
729 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
730 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
731 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
732 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
720 } 733 }
721 734
722 private Vector3[] GetWalkDirectionVectors() 735 private Vector3[] GetWalkDirectionVectors()
723 { 736 {
724 Vector3[] vector = new Vector3[6]; 737 Vector3[] vector = new Vector3[11];
725 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 738 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
726 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 739 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
727 vector[2] = Vector3.UnitY; //LEFT 740 vector[2] = Vector3.UnitY; //LEFT
728 vector[3] = -Vector3.UnitY; //RIGHT 741 vector[3] = -Vector3.UnitY; //RIGHT
729 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 742 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
730 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 743 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
731 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 744 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
745 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
746 vector[8] = Vector3.UnitY; //LEFT_NUDGE
747 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
748 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
732 return vector; 749 return vector;
733 } 750 }
751
752 private bool[] GetDirectionIsNudge()
753 {
754 bool[] isNudge = new bool[11];
755 isNudge[0] = false; //FORWARD
756 isNudge[1] = false; //BACK
757 isNudge[2] = false; //LEFT
758 isNudge[3] = false; //RIGHT
759 isNudge[4] = false; //UP
760 isNudge[5] = false; //DOWN
761 isNudge[6] = true; //FORWARD_NUDGE
762 isNudge[7] = true; //BACK_NUDGE
763 isNudge[8] = true; //LEFT_NUDGE
764 isNudge[9] = true; //RIGHT_NUDGE
765 isNudge[10] = true; //DOWN_Nudge
766 return isNudge;
767 }
768
734 769
735 #endregion 770 #endregion
736 771
@@ -994,7 +1029,9 @@ namespace OpenSim.Region.Framework.Scenes
994 { 1029 {
995 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f)); 1030 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f));
996 } 1031 }
997 1032
1033 m_updateCount = UPDATE_COUNT; //KF: Trigger Anim updates to catch falling anim.
1034
998 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId, 1035 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId,
999 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient))); 1036 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient)));
1000 } 1037 }
@@ -1229,7 +1266,6 @@ namespace OpenSim.Region.Framework.Scenes
1229 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1266 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1230 } 1267 }
1231 } 1268 }
1232
1233 lock (scriptedcontrols) 1269 lock (scriptedcontrols)
1234 { 1270 {
1235 if (scriptedcontrols.Count > 0) 1271 if (scriptedcontrols.Count > 0)
@@ -1244,9 +1280,7 @@ namespace OpenSim.Region.Framework.Scenes
1244 1280
1245 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1281 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1246 { 1282 {
1247 // TODO: This doesn't prevent the user from walking yet. 1283 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1248 // Setting parent ID would fix this, if we knew what value
1249 // to use. Or we could add a m_isSitting variable.
1250 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); 1284 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1251 } 1285 }
1252 1286
@@ -1261,7 +1295,6 @@ namespace OpenSim.Region.Framework.Scenes
1261 { 1295 {
1262 return; 1296 return;
1263 } 1297 }
1264
1265 if (m_allowMovement) 1298 if (m_allowMovement)
1266 { 1299 {
1267 int i = 0; 1300 int i = 0;
@@ -1289,6 +1322,11 @@ namespace OpenSim.Region.Framework.Scenes
1289 update_rotation = true; 1322 update_rotation = true;
1290 } 1323 }
1291 1324
1325 //guilty until proven innocent..
1326 bool Nudging = true;
1327 //Basically, if there is at least one non-nudge control then we don't need
1328 //to worry about stopping the avatar
1329
1292 if (m_parentID == 0) 1330 if (m_parentID == 0)
1293 { 1331 {
1294 bool bAllowUpdateMoveToPosition = false; 1332 bool bAllowUpdateMoveToPosition = false;
@@ -1303,6 +1341,12 @@ namespace OpenSim.Region.Framework.Scenes
1303 else 1341 else
1304 dirVectors = Dir_Vectors; 1342 dirVectors = Dir_Vectors;
1305 1343
1344 bool[] isNudge = GetDirectionIsNudge();
1345
1346
1347
1348
1349
1306 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1350 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1307 { 1351 {
1308 if (((uint)flags & (uint)DCF) != 0) 1352 if (((uint)flags & (uint)DCF) != 0)
@@ -1312,6 +1356,10 @@ namespace OpenSim.Region.Framework.Scenes
1312 try 1356 try
1313 { 1357 {
1314 agent_control_v3 += dirVectors[i]; 1358 agent_control_v3 += dirVectors[i];
1359 if (isNudge[i] == false)
1360 {
1361 Nudging = false;
1362 }
1315 } 1363 }
1316 catch (IndexOutOfRangeException) 1364 catch (IndexOutOfRangeException)
1317 { 1365 {
@@ -1373,6 +1421,9 @@ namespace OpenSim.Region.Framework.Scenes
1373 // Ignore z component of vector 1421 // Ignore z component of vector
1374 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1422 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1375 LocalVectorToTarget2D.Normalize(); 1423 LocalVectorToTarget2D.Normalize();
1424
1425 //We're not nudging
1426 Nudging = false;
1376 agent_control_v3 += LocalVectorToTarget2D; 1427 agent_control_v3 += LocalVectorToTarget2D;
1377 1428
1378 // update avatar movement flags. the avatar coordinate system is as follows: 1429 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1455,7 +1506,7 @@ namespace OpenSim.Region.Framework.Scenes
1455 // m_log.DebugFormat( 1506 // m_log.DebugFormat(
1456 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1507 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1457 1508
1458 AddNewMovement(agent_control_v3, q); 1509 AddNewMovement(agent_control_v3, q, Nudging);
1459 1510
1460 if (update_movementflag) 1511 if (update_movementflag)
1461 Animator.UpdateMovementAnimations(); 1512 Animator.UpdateMovementAnimations();
@@ -1538,7 +1589,7 @@ namespace OpenSim.Region.Framework.Scenes
1538 Velocity = Vector3.Zero; 1589 Velocity = Vector3.Zero;
1539 SendFullUpdateToAllClients(); 1590 SendFullUpdateToAllClients();
1540 1591
1541 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1592 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1542 } 1593 }
1543 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1594 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1544 m_requestedSitTargetUUID = UUID.Zero; 1595 m_requestedSitTargetUUID = UUID.Zero;
@@ -1576,21 +1627,19 @@ namespace OpenSim.Region.Framework.Scenes
1576 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); 1627 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1577 if (part != null) 1628 if (part != null)
1578 { 1629 {
1630 part.TaskInventory.LockItemsForRead(true);
1579 TaskInventoryDictionary taskIDict = part.TaskInventory; 1631 TaskInventoryDictionary taskIDict = part.TaskInventory;
1580 if (taskIDict != null) 1632 if (taskIDict != null)
1581 { 1633 {
1582 lock (taskIDict) 1634 foreach (UUID taskID in taskIDict.Keys)
1583 { 1635 {
1584 foreach (UUID taskID in taskIDict.Keys) 1636 UnRegisterControlEventsToScript(LocalId, taskID);
1585 { 1637 taskIDict[taskID].PermsMask &= ~(
1586 UnRegisterControlEventsToScript(LocalId, taskID); 1638 2048 | //PERMISSION_CONTROL_CAMERA
1587 taskIDict[taskID].PermsMask &= ~( 1639 4); // PERMISSION_TAKE_CONTROLS
1588 2048 | //PERMISSION_CONTROL_CAMERA
1589 4); // PERMISSION_TAKE_CONTROLS
1590 }
1591 } 1640 }
1592
1593 } 1641 }
1642 part.TaskInventory.LockItemsForRead(false);
1594 // Reset sit target. 1643 // Reset sit target.
1595 if (part.GetAvatarOnSitTarget() == UUID) 1644 if (part.GetAvatarOnSitTarget() == UUID)
1596 part.SetAvatarOnSitTarget(UUID.Zero); 1645 part.SetAvatarOnSitTarget(UUID.Zero);
@@ -1603,9 +1652,9 @@ namespace OpenSim.Region.Framework.Scenes
1603 { 1652 {
1604 AddToPhysicalScene(false); 1653 AddToPhysicalScene(false);
1605 } 1654 }
1606
1607 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1655 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight);
1608 m_parentPosition = Vector3.Zero; 1656 m_parentPosition = Vector3.Zero;
1657//Console.WriteLine("Stand Pos {0}", m_pos);
1609 1658
1610 m_parentID = 0; 1659 m_parentID = 0;
1611 SendFullUpdateToAllClients(); 1660 SendFullUpdateToAllClients();
@@ -1651,7 +1700,7 @@ namespace OpenSim.Region.Framework.Scenes
1651 bool SitTargetisSet = 1700 bool SitTargetisSet =
1652 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f && 1701 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1653 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f)); 1702 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1654 1703 // this test is probably failing
1655 if (SitTargetisSet && SitTargetUnOccupied) 1704 if (SitTargetisSet && SitTargetUnOccupied)
1656 { 1705 {
1657 //switch the target to this prim 1706 //switch the target to this prim
@@ -1678,31 +1727,58 @@ namespace OpenSim.Region.Framework.Scenes
1678 { 1727 {
1679 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1728 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1680 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1729 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1681 1730
1731 // part is the prim to sit on
1732 // offset is the vector distance from that prim center to the click-spot
1733 // UUID is the UUID of the Avatar doing the clicking
1734
1735 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1736
1682 // Is a sit target available? 1737 // Is a sit target available?
1683 Vector3 avSitOffSet = part.SitTargetPosition; 1738 Vector3 avSitOffSet = part.SitTargetPosition;
1684 Quaternion avSitOrientation = part.SitTargetOrientation; 1739 Quaternion avSitOrientation = part.SitTargetOrientation;
1685 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1740 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1686 1741
1687 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1742 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero));
1688 bool SitTargetisSet = 1743// bool SitTargetisSet =
1689 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 0f && 1744// (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 0f &&
1690 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f)); 1745// avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f));
1691 1746
1692 if (SitTargetisSet && SitTargetUnOccupied) 1747 bool SitTargetisSet = ((Vector3.Zero != avSitOffSet) || (Quaternion.Identity != avSitOrientation));
1693 { 1748
1694 part.SetAvatarOnSitTarget(UUID); 1749//Console.WriteLine("SendSitResponse offset=" + offset + " UnOccup=" + SitTargetUnOccupied +
1695 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1750// " TargSet=" + SitTargetisSet);
1696 sitOrientation = avSitOrientation; 1751 // Sit analysis rewritten by KF 091125
1697 autopilot = false; 1752 if (SitTargetisSet) // scipted sit
1698 } 1753 {
1754 if (SitTargetUnOccupied)
1755 {
1756 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1757 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1758 sitOrientation = avSitOrientation; // Change rotatione to the scripted one
1759 autopilot = false; // Jump direct to scripted llSitPos()
1760 }
1761 else return;
1762 }
1763 else // Not Scripted
1764 {
1765 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) ) // large prim
1766 {
1767 Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1768 m_avUnscriptedSitPos = offset * partIRot; // sit where clicked
1769 pos = part.AbsolutePosition + (offset * partIRot);
1770 }
1771 else // small prim
1772 {
1773 if (SitTargetUnOccupied)
1774 {
1775 m_avUnscriptedSitPos = Vector3.Zero; // Sit on unoccupied small prim center
1776 pos = part.AbsolutePosition;
1777 }
1778 else return; // occupied small
1779 } // end large/small
1780 } // end Scripted/not
1699 1781
1700 pos = part.AbsolutePosition + offset;
1701 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1)
1702 //{
1703 // offset = pos;
1704 //autopilot = false;
1705 //}
1706 if (m_physicsActor != null) 1782 if (m_physicsActor != null)
1707 { 1783 {
1708 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1784 // If we're not using the client autopilot, we're immediately warping the avatar to the location
@@ -1710,17 +1786,17 @@ namespace OpenSim.Region.Framework.Scenes
1710 m_sitAvatarHeight = m_physicsActor.Size.Z; 1786 m_sitAvatarHeight = m_physicsActor.Size.Z;
1711 1787
1712 if (autopilot) 1788 if (autopilot)
1713 { 1789 { // its not a scripted sit
1714 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1790 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5)
1715 { 1791 {
1716 autopilot = false; 1792 autopilot = false; // close enough
1717 1793
1718 RemoveFromPhysicalScene(); 1794 RemoveFromPhysicalScene();
1719 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 1795 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to Prim
1720 } 1796 } // else the autopilot will get us close
1721 } 1797 }
1722 else 1798 else
1723 { 1799 { // its a scripted sit
1724 RemoveFromPhysicalScene(); 1800 RemoveFromPhysicalScene();
1725 } 1801 }
1726 } 1802 }
@@ -1823,29 +1899,52 @@ namespace OpenSim.Region.Framework.Scenes
1823 { 1899 {
1824 if (part.GetAvatarOnSitTarget() == UUID) 1900 if (part.GetAvatarOnSitTarget() == UUID)
1825 { 1901 {
1902 // Scripted sit
1826 Vector3 sitTargetPos = part.SitTargetPosition; 1903 Vector3 sitTargetPos = part.SitTargetPosition;
1827 Quaternion sitTargetOrient = part.SitTargetOrientation; 1904 Quaternion sitTargetOrient = part.SitTargetOrientation;
1828
1829 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
1830 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
1831
1832 //Quaternion result = (sitTargetOrient * vq) * nq;
1833
1834 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 1905 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
1835 m_pos += SIT_TARGET_ADJUSTMENT; 1906 m_pos += SIT_TARGET_ADJUSTMENT;
1836 m_bodyRot = sitTargetOrient; 1907 m_bodyRot = sitTargetOrient;
1837 //Rotation = sitTargetOrient;
1838 m_parentPosition = part.AbsolutePosition; 1908 m_parentPosition = part.AbsolutePosition;
1839
1840 //SendTerseUpdateToAllClients();
1841 } 1909 }
1842 else 1910 else
1843 { 1911 {
1844 m_pos -= part.AbsolutePosition; 1912 // Non-scripted sit by Kitto Flora 21Nov09
1913 // Calculate angle of line from prim to Av
1914 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
1915 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
1916 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
1917 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
1918 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
1919 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
1920 Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1921 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
1922 // Av sits at world euler <0,0, z>, translated by part rotation
1923 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
1845 m_parentPosition = part.AbsolutePosition; 1924 m_parentPosition = part.AbsolutePosition;
1846 } 1925 if(m_avUnscriptedSitPos != Vector3.Zero)
1847 } 1926 { // sit where clicked on big prim
1848 else 1927 m_pos = m_avUnscriptedSitPos + (new Vector3(0.0f, 0f, 0.625f) * partIRot);
1928 }
1929 else
1930 { // sit at center of small prim
1931 m_pos = new Vector3(0f, 0f, 0.05f) +
1932 (new Vector3(0.0f, 0f, 0.625f) * partIRot) +
1933 (new Vector3(0.25f, 0f, 0.0f) * m_bodyRot);
1934 //Set up raytrace to find top surface of prim
1935 Vector3 size = part.Scale;
1936 float mag = 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
1937 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
1938 Vector3 down = new Vector3(0f, 0f, -1f);
1939 m_scene.PhysicsScene.RaycastWorld(
1940 start, // Vector3 position,
1941 down, // Vector3 direction,
1942 mag, // float length,
1943 SitAltitudeCallback); // retMethod
1944 } // end small/big
1945 } // end scripted/not
1946 }
1947 else // no Av
1849 { 1948 {
1850 return; 1949 return;
1851 } 1950 }
@@ -1857,11 +1956,21 @@ namespace OpenSim.Region.Framework.Scenes
1857 1956
1858 Animator.TrySetMovementAnimation(sitAnimation); 1957 Animator.TrySetMovementAnimation(sitAnimation);
1859 SendFullUpdateToAllClients(); 1958 SendFullUpdateToAllClients();
1860 // This may seem stupid, but Our Full updates don't send avatar rotation :P
1861 // So we're also sending a terse update (which has avatar rotation)
1862 // [Update] We do now.
1863 //SendTerseUpdateToAllClients();
1864 } 1959 }
1960
1961 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance)
1962 {
1963 if(hitYN)
1964 {
1965 // m_pos = Av offset from prim center to make look like on center
1966 // m_parentPosition = Actual center pos of prim
1967 // collisionPoint = spot on prim where we want to sit
1968 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
1969 Vector3 offset = (collisionPoint - m_parentPosition) * Quaternion.Inverse(part.RotationOffset);
1970 m_pos += offset;
1971// Console.WriteLine("m_pos={0}, offset={1} newsit={2}", m_pos, offset, newsit);
1972 }
1973 }
1865 1974
1866 /// <summary> 1975 /// <summary>
1867 /// Event handler for the 'Always run' setting on the client 1976 /// Event handler for the 'Always run' setting on the client
@@ -1891,7 +2000,7 @@ namespace OpenSim.Region.Framework.Scenes
1891 /// </summary> 2000 /// </summary>
1892 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2001 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
1893 /// <param name="rotation">The direction in which this avatar should now face. 2002 /// <param name="rotation">The direction in which this avatar should now face.
1894 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2003 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
1895 { 2004 {
1896 if (m_isChildAgent) 2005 if (m_isChildAgent)
1897 { 2006 {
@@ -1965,7 +2074,7 @@ namespace OpenSim.Region.Framework.Scenes
1965 2074
1966 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2075 // TODO: Add the force instead of only setting it to support multiple forces per frame?
1967 m_forceToApply = direc; 2076 m_forceToApply = direc;
1968 2077 m_isNudging = Nudging;
1969 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2078 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
1970 } 2079 }
1971 2080
@@ -1980,7 +2089,7 @@ namespace OpenSim.Region.Framework.Scenes
1980 const float POSITION_TOLERANCE = 0.05f; 2089 const float POSITION_TOLERANCE = 0.05f;
1981 //const int TIME_MS_TOLERANCE = 3000; 2090 //const int TIME_MS_TOLERANCE = 3000;
1982 2091
1983 SendPrimUpdates(); 2092
1984 2093
1985 if (m_newCoarseLocations) 2094 if (m_newCoarseLocations)
1986 { 2095 {
@@ -2016,6 +2125,9 @@ namespace OpenSim.Region.Framework.Scenes
2016 CheckForBorderCrossing(); 2125 CheckForBorderCrossing();
2017 CheckForSignificantMovement(); // sends update to the modules. 2126 CheckForSignificantMovement(); // sends update to the modules.
2018 } 2127 }
2128
2129 //Sending prim updates AFTER the avatar terse updates are sent
2130 SendPrimUpdates();
2019 } 2131 }
2020 2132
2021 #endregion 2133 #endregion
@@ -2869,14 +2981,25 @@ namespace OpenSim.Region.Framework.Scenes
2869 { 2981 {
2870 if (m_forceToApply.HasValue) 2982 if (m_forceToApply.HasValue)
2871 { 2983 {
2872 Vector3 force = m_forceToApply.Value;
2873 2984
2985 Vector3 force = m_forceToApply.Value;
2874 m_updateflag = true; 2986 m_updateflag = true;
2875// movementvector = force;
2876 Velocity = force; 2987 Velocity = force;
2877 2988
2878 m_forceToApply = null; 2989 m_forceToApply = null;
2879 } 2990 }
2991 else
2992 {
2993 if (m_isNudging)
2994 {
2995 Vector3 force = Vector3.Zero;
2996
2997 m_updateflag = true;
2998 Velocity = force;
2999 m_isNudging = false;
3000 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3001 }
3002 }
2880 } 3003 }
2881 3004
2882 public override void SetText(string text, Vector3 color, double alpha) 3005 public override void SetText(string text, Vector3 color, double alpha)
@@ -2926,19 +3049,29 @@ namespace OpenSim.Region.Framework.Scenes
2926 // Event called by the physics plugin to tell the avatar about a collision. 3049 // Event called by the physics plugin to tell the avatar about a collision.
2927 private void PhysicsCollisionUpdate(EventArgs e) 3050 private void PhysicsCollisionUpdate(EventArgs e)
2928 { 3051 {
3052 if (m_updateCount > 0) //KF: Update Anims for a short period. Many Anim
3053 { // changes are very asynchronous.
3054 Animator.UpdateMovementAnimations();
3055 m_updateCount--;
3056 }
3057
2929 if (e == null) 3058 if (e == null)
2930 return; 3059 return;
2931 3060
2932 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
2933 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents( 3061 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
2934 // as of this comment the interval is set in AddToPhysicalScene 3062 // as of this comment the interval is set in AddToPhysicalScene
2935 Animator.UpdateMovementAnimations(); 3063
2936
2937 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3064 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
2938 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3065 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
2939 3066
2940 CollisionPlane = Vector4.UnitW; 3067 CollisionPlane = Vector4.UnitW;
2941 3068
3069 if (m_lastColCount != coldata.Count)
3070 {
3071 m_updateCount = 10;
3072 m_lastColCount = coldata.Count;
3073 }
3074
2942 if (coldata.Count != 0) 3075 if (coldata.Count != 0)
2943 { 3076 {
2944 switch (Animator.CurrentMovementAnimation) 3077 switch (Animator.CurrentMovementAnimation)
@@ -3587,4 +3720,4 @@ namespace OpenSim.Region.Framework.Scenes
3587 } 3720 }
3588 } 3721 }
3589 } 3722 }
3590} \ No newline at end of file 3723}