From 386a13d5d63b32c7c332e7526cdd143e649d7c18 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 28 Aug 2016 14:59:02 +0100 Subject: mantis: rotate avatar to lookAt o login/teleports. Some cases may still be wrong --- .../EntityTransfer/EntityTransferModule.cs | 8 ++++++ OpenSim/Region/Framework/Scenes/ScenePresence.cs | 30 ++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index 58f3dde..71a0e52 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -478,9 +478,17 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.Transferring); sp.ControllingClient.SendTeleportStart(teleportFlags); + lookAt.Z = 0f; + + if(Math.Abs(lookAt.X) < 0.01f && Math.Abs(lookAt.Y) < 0.01f) + { + lookAt.X = 1.0f; + lookAt.Y = 0; + } sp.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags); sp.TeleportFlags = (Constants.TeleportFlags)teleportFlags; + sp.RotateToLookAt(lookAt); sp.Velocity = Vector3.Zero; sp.Teleport(position); diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 50ee9d4..cb7422b 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1927,6 +1927,31 @@ namespace OpenSim.Region.Framework.Scenes return true; } + public void RotateToLookAt(Vector3 lookAt) + { + if(ParentID == 0) + { + float n = lookAt.X * lookAt.X + lookAt.Y * lookAt.Y; + if(n < 0.0001f) + { + Rotation = Quaternion.Identity; + return; + } + n = lookAt.X/(float)Math.Sqrt(n); + float angle = (float)Math.Acos(n); + angle *= 0.5f; + float s = (float)Math.Sin(angle); + if(lookAt.Y < 0) + s = -s; + Rotation = new Quaternion( + 0f, + 0f, + s, + (float)Math.Cos(angle) + ); + } + } + /// /// Complete Avatar's movement into the region. /// @@ -1963,10 +1988,10 @@ namespace OpenSim.Region.Framework.Scenes bool flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); Vector3 look = Lookat; + look.Z = 0f; if ((Math.Abs(look.X) < 0.01) && (Math.Abs(look.Y) < 0.01)) { look = Velocity; - look.Z = 0; look.Normalize(); if ((Math.Abs(look.X) < 0.01) && (Math.Abs(look.Y) < 0.01) ) look = new Vector3(0.99f, 0.042f, 0); @@ -2000,11 +2025,12 @@ namespace OpenSim.Region.Framework.Scenes m_log.DebugFormat("[CompleteMovement]: Missing COF for {0} is {1}", client.AgentId, COF); } + if(!gotCrossUpdate) + RotateToLookAt(look); // Tell the client that we're totally ready ControllingClient.MoveAgentIntoRegion(m_scene.RegionInfo, AbsolutePosition, look); - m_log.DebugFormat("[CompleteMovement] MoveAgentIntoRegion: {0}ms", Util.EnvironmentTickCountSubtract(ts)); if (!string.IsNullOrEmpty(m_callbackURI)) -- cgit v1.1