From 7ae9ec217d6e1ec039fbd6ed16c952d56cc63dc6 Mon Sep 17 00:00:00 2001 From: idb Date: Fri, 5 Dec 2008 16:48:47 +0000 Subject: Implementation of the llDetectedTouch* functions --- OpenSim/Region/Environment/Scenes/EventManager.cs | 6 +-- .../Environment/Scenes/Scene.PacketHandlers.cs | 8 ++- .../ScriptEngine/DotNetEngine/EventManager.cs | 6 ++- .../Shared/Api/Implementation/LSL_Api.cs | 54 +++++++++++++++----- .../Shared/Api/Runtime/LSL_Constants.cs | 5 ++ OpenSim/Region/ScriptEngine/Shared/Helpers.cs | 58 +++++++++++++++++++++- .../Region/ScriptEngine/XEngine/EventManager.cs | 7 ++- 7 files changed, 124 insertions(+), 20 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Environment/Scenes/EventManager.cs b/OpenSim/Region/Environment/Scenes/EventManager.cs index 598f8b4..ad25670 100644 --- a/OpenSim/Region/Environment/Scenes/EventManager.cs +++ b/OpenSim/Region/Environment/Scenes/EventManager.cs @@ -92,7 +92,7 @@ namespace OpenSim.Region.Environment.Scenes public event OnShutdownDelegate OnShutdown; - public delegate void ObjectGrabDelegate(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient); + public delegate void ObjectGrabDelegate(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs); public delegate void ObjectDeGrabDelegate(uint localID, uint originalID, IClientAPI remoteClient); public delegate void ScriptResetDelegate(uint localID, UUID itemID); @@ -530,12 +530,12 @@ namespace OpenSim.Region.Environment.Scenes handlerShutdown(); } - public void TriggerObjectGrab(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient) + public void TriggerObjectGrab(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs) { handlerObjectGrab = OnObjectGrab; if (handlerObjectGrab != null) { - handlerObjectGrab(localID, originalID, offsetPos, remoteClient); + handlerObjectGrab(localID, originalID, offsetPos, remoteClient, surfaceArgs); } } diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs index 2bd1f1c..8d12a94 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs @@ -217,6 +217,10 @@ namespace OpenSim.Region.Environment.Scenes List EntityList = GetEntities(); + SurfaceTouchEventArgs surfaceArg = null; + if (surfaceArgs != null && surfaceArgs.Count > 0) + surfaceArg = surfaceArgs[0]; + foreach (EntityBase ent in EntityList) { if (ent is SceneObjectGroup) @@ -236,9 +240,9 @@ namespace OpenSim.Region.Environment.Scenes // If the touched prim handles touches, deliver it // If not, deliver to root prim if ((part.ScriptEvents & scriptEvents.touch_start) != 0) - EventManager.TriggerObjectGrab(part.LocalId, 0, part.OffsetPosition, remoteClient); + EventManager.TriggerObjectGrab(part.LocalId, 0, part.OffsetPosition, remoteClient, surfaceArg); else - EventManager.TriggerObjectGrab(obj.RootPart.LocalId, part.LocalId, part.OffsetPosition, remoteClient); + EventManager.TriggerObjectGrab(obj.RootPart.LocalId, part.LocalId, part.OffsetPosition, remoteClient, surfaceArg); return; } diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs index 72766a4..09dbc40 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs @@ -141,7 +141,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine } public void touch_start(uint localID, uint originalID, - Vector3 offsetPos, IClientAPI remoteClient) + Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs) { // Add to queue for all scripts in ObjectID object DetectParams[] det = new DetectParams[1]; @@ -165,6 +165,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine myScriptEngine.World.GetSceneObjectPart(originalID); det[0].LinkNum = originalPart.LinkNum; } + if (surfaceArgs != null) + { + det[0].SurfaceTouchArgs = surfaceArgs; + } myScriptEngine.PostObjectEvent(localID, new EventParams( "touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 7a7c8d6..f98a9bb 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -889,46 +889,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return new LSL_Integer(parms.LinkNum); } + /// + /// See http://wiki.secondlife.com/wiki/LlDetectedTouchBinormal for details + /// public LSL_Vector llDetectedTouchBinormal(int index) { m_host.AddScriptLPS(1); - NotImplemented("llDetectedTouchBinormal"); - return new LSL_Vector(); + DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); + if (detectedParams == null || detectedParams.TouchBinormal == null) + return new LSL_Vector(); + return detectedParams.TouchBinormal; } + /// + /// See http://wiki.secondlife.com/wiki/LlDetectedTouchFace for details + /// public LSL_Integer llDetectedTouchFace(int index) { m_host.AddScriptLPS(1); - NotImplemented("llDetectedTouchFace"); - return new LSL_Integer(0); + DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); + if (detectedParams == null || detectedParams.TouchFace == null) + return new LSL_Integer(-1); + return new LSL_Integer(detectedParams.TouchFace); } + /// + /// See http://wiki.secondlife.com/wiki/LlDetectedTouchNormal for details + /// public LSL_Vector llDetectedTouchNormal(int index) { m_host.AddScriptLPS(1); - NotImplemented("llDetectedTouchNormal"); - return new LSL_Vector(); + DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); + if (detectedParams == null || detectedParams.TouchNormal == null) + return new LSL_Vector(); + return detectedParams.TouchNormal; } + /// + /// See http://wiki.secondlife.com/wiki/LlDetectedTouchPos for details + /// public LSL_Vector llDetectedTouchPos(int index) { m_host.AddScriptLPS(1); - NotImplemented("llDetectedTouchPos"); - return new LSL_Vector(); + DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); + if (detectedParams == null || detectedParams.TouchPos == null) + return new LSL_Vector(); + return detectedParams.TouchPos; } + /// + /// See http://wiki.secondlife.com/wiki/LlDetectedTouchST for details + /// public LSL_Vector llDetectedTouchST(int index) { m_host.AddScriptLPS(1); - NotImplemented("llDetectedTouchST"); - return new LSL_Vector(); + DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); + if (detectedParams == null || detectedParams.TouchST == null) + return new LSL_Vector(-1.0, -1.0, 0.0); + return detectedParams.TouchST; } + /// + /// See http://wiki.secondlife.com/wiki/LlDetectedTouchUV for details + /// public LSL_Vector llDetectedTouchUV(int index) { m_host.AddScriptLPS(1); - NotImplemented("llDetectedTouchUV"); - return new LSL_Vector(); + DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); + if (detectedParams == null || detectedParams.TouchUV == null) + return new LSL_Vector(-1.0, -1.0, 0.0); + return detectedParams.TouchUV; } public void llDie() diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index e087ea2..b97ec99 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs @@ -494,5 +494,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public const int CLICK_ACTION_OPEN = 4; public const int CLICK_ACTION_PLAY = 5; public const int CLICK_ACTION_OPEN_MEDIA = 6; + + // constants for the llDetectedTouch* functions + public const int TOUCH_INVALID_FACE = -1; + public static readonly vector TOUCH_INVALID_TEXCOORD = new vector(-1.0, -1.0, 0.0); + public static readonly vector TOUCH_INVALID_VECTOR = ZERO_VECTOR; } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs index a061fde..b9ff0cd 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs @@ -80,6 +80,7 @@ namespace OpenSim.Region.ScriptEngine.Shared Rotation = new LSL_Types.Quaternion(); Type = 0; Velocity = new LSL_Types.Vector3(); + initializeSurfaceTouch(); } public UUID Key; @@ -93,6 +94,61 @@ namespace OpenSim.Region.ScriptEngine.Shared public int Type; public LSL_Types.Vector3 Velocity; + private LSL_Types.Vector3 touchST; + public LSL_Types.Vector3 TouchST { get { return touchST; } } + + private LSL_Types.Vector3 touchNormal; + public LSL_Types.Vector3 TouchNormal { get { return touchNormal; } } + + private LSL_Types.Vector3 touchBinormal; + public LSL_Types.Vector3 TouchBinormal { get { return touchBinormal; } } + + private LSL_Types.Vector3 touchPos; + public LSL_Types.Vector3 TouchPos { get { return touchPos; } } + + private LSL_Types.Vector3 touchUV; + public LSL_Types.Vector3 TouchUV { get { return touchUV; } } + + private int touchFace; + public int TouchFace { get { return touchFace; } } + + // This can be done in two places including the constructor + // so be carefull what gets added here + private void initializeSurfaceTouch() + { + touchST = new LSL_Types.Vector3(-1.0, -1.0, 0.0); + touchNormal = new LSL_Types.Vector3(); + touchBinormal = new LSL_Types.Vector3(); + touchPos = new LSL_Types.Vector3(); + touchUV = new LSL_Types.Vector3(-1.0, -1.0, 0.0); + touchFace = -1; + } + + /* + * Set up the surface touch detected values + */ + public SurfaceTouchEventArgs SurfaceTouchArgs + { + set + { + if (value == null) + { + // Initialise to defaults if no value + initializeSurfaceTouch(); + } + else + { + // Set the values from the touch data provided by the client + touchST = new LSL_Types.Vector3(value.STCoord.X, value.STCoord.Y, value.STCoord.Z); + touchUV = new LSL_Types.Vector3(value.UVCoord.X, value.UVCoord.Y, value.UVCoord.Z); + touchNormal = new LSL_Types.Vector3(value.Normal.X, value.Normal.Y, value.Normal.Z); + touchBinormal = new LSL_Types.Vector3(value.Binormal.X, value.Binormal.Y, value.Binormal.Z); + touchPos = new LSL_Types.Vector3(value.Position.X, value.Position.Y, value.Position.Z); + touchFace = value.FaceIndex; + } + } + } + public void Populate(Scene scene) { SceneObjectPart part = scene.GetSceneObjectPart(Key); @@ -177,4 +233,4 @@ namespace OpenSim.Region.ScriptEngine.Shared public Object[] Params; public DetectParams[] DetectParams; } -} \ No newline at end of file +} diff --git a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs index 9ed2fbb..67ac0ce 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs @@ -80,7 +80,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine } public void touch_start(uint localID, uint originalID, Vector3 offsetPos, - IClientAPI remoteClient) + IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs) { // Add to queue for all scripts in ObjectID object DetectParams[] det = new DetectParams[1]; @@ -102,6 +102,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine det[0].LinkNum = originalPart.LinkNum; } + if (surfaceArgs != null) + { + det[0].SurfaceTouchArgs = surfaceArgs; + } + myScriptEngine.PostObjectEvent(localID, new EventParams( "touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det)); -- cgit v1.1