From a21e98ae1a3e2f570cc119e020d4d4ea111e0ad2 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 11 Aug 2011 23:28:14 +0100 Subject: implement osNpcGetRot() and osNpcSetRot() Rotation works if done around the z axis. Anything else leads to random results. --- .../Shared/Api/Implementation/LSL_Api.cs | 3 +- .../Shared/Api/Implementation/OSSL_Api.cs | 57 ++++++++++++++++++++-- 2 files changed, 55 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 86ee28a..8a281d4 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -369,7 +369,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } // convert a LSL_Rotation to a Quaternion - protected Quaternion Rot2Quaternion(LSL_Rotation r) + public static Quaternion Rot2Quaternion(LSL_Rotation r) { Quaternion q = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s); q.Normalize(); @@ -2061,6 +2061,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { return llGetRootRotation(); } + m_host.AddScriptLPS(1); Quaternion q = m_host.GetWorldRotation(); return new LSL_Rotation(q.X, q.Y, q.Z, q.W); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 939602a..1874826 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2186,9 +2186,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (npcModule != null) { - UUID npcId = new UUID(npc.m_string); - - if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) + UUID npcId; + if (!UUID.TryParse(npc.m_string, out npcId)) return; string appearanceSerialized = LoadNotecard(notecardNameOrUuid); @@ -2210,8 +2209,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule module = World.RequestModuleInterface(); if (module != null) { + UUID npcId; + if (!UUID.TryParse(npc.m_string, out npcId)) + return; + Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); - module.MoveToTarget(new UUID(npc.m_string), World, pos, false, true); + module.MoveToTarget(npcId, World, pos, false, true); } } @@ -2222,6 +2225,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule module = World.RequestModuleInterface(); if (module != null) { + UUID npcId; + if (!UUID.TryParse(npc.m_string, out npcId)) + return; + Vector3 pos = new Vector3((float)position.x, (float)position.y, (float)position.z); module.MoveToTarget( new UUID(npc.m_string), @@ -2232,6 +2239,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } + public LSL_Rotation osNpcGetRot(LSL_Key npc) + { + CheckThreatLevel(ThreatLevel.High, "osNpcGetRot"); + + INPCModule npcModule = World.RequestModuleInterface(); + if (npcModule != null) + { + UUID npcId; + if (!UUID.TryParse(npc.m_string, out npcId)) + return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); + + if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) + return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); + + ScenePresence sp = World.GetScenePresence(npcId); + Quaternion rot = sp.Rotation; + + return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W); + } + + return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); + } + + public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation) + { + CheckThreatLevel(ThreatLevel.High, "osNpcSetRot"); + + INPCModule npcModule = World.RequestModuleInterface(); + if (npcModule != null) + { + UUID npcId; + if (!UUID.TryParse(npc.m_string, out npcId)) + return; + + if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) + return; + + ScenePresence sp = World.GetScenePresence(npcId); + sp.Rotation = LSL_Api.Rot2Quaternion(rotation); + } + } + public void osNpcStopMoveTo(LSL_Key npc) { CheckThreatLevel(ThreatLevel.VeryLow, "osNpcStopMoveTo"); -- cgit v1.1