From 232241ab25ccd9e3184a2eeda0e80f7af15e1641 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 9 Apr 2009 07:46:05 +0000 Subject: * Implements IObject.OnTouch += delegate(IObject sender, TouchEventArgs e) * This is equivalent to LSL 'touch(int senders)' --- .../Scripting/Minimodule/IObject.cs | 22 ++++++++++ .../Scripting/Minimodule/SOPObject.cs | 51 ++++++++++++++++++++++ 2 files changed, 73 insertions(+) (limited to 'OpenSim/Region/OptionalModules/Scripting') diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs index 20d8e54..fd62328 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs @@ -32,8 +32,30 @@ using OpenSim.Region.OptionalModules.Scripting.Minimodule.Object; namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { + public class TouchEventArgs : EventArgs + { + public IAvatar Avatar; + + public Vector3 TouchBiNormal; + public Vector3 TouchNormal; + public Vector3 TouchPosition; + + public Vector2 TouchUV; + public Vector2 TouchST; + + public int TouchMaterialIndex; + } + + public delegate void OnTouchDelegate(IObject sender, TouchEventArgs e); + public interface IObject { + #region Events + + event OnTouchDelegate OnTouch; + + #endregion + /// /// Returns whether or not this object is still in the world. /// Eg, if you store an IObject reference, however the object diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs index 48cae2f..4734fa9 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs @@ -59,6 +59,57 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule return null; } + #region OnTouch + + private event OnTouchDelegate _OnTouch; + private bool _OnTouchActive = false; + + public event OnTouchDelegate OnTouch + { + add + { + if(!_OnTouchActive) + { + _OnTouchActive = true; + m_rootScene.EventManager.OnObjectGrab += EventManager_OnObjectGrab; + } + + _OnTouch += value; + } + remove + { + _OnTouch -= value; + + if (_OnTouch == null) + { + _OnTouchActive = false; + m_rootScene.EventManager.OnObjectGrab -= EventManager_OnObjectGrab; + } + } + } + + void EventManager_OnObjectGrab(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs) + { + if (_OnTouchActive && m_localID == localID) + { + TouchEventArgs e = new TouchEventArgs(); + e.Avatar = new SPAvatar(m_rootScene, remoteClient.AgentId); + e.TouchBiNormal = surfaceArgs.Binormal; + e.TouchMaterialIndex = surfaceArgs.FaceIndex; + e.TouchNormal = surfaceArgs.Normal; + e.TouchPosition = surfaceArgs.Position; + e.TouchST = new Vector2(surfaceArgs.STCoord.X, surfaceArgs.STCoord.Y); + e.TouchUV = new Vector2(surfaceArgs.UVCoord.X, surfaceArgs.UVCoord.Y); + + IObject sender = this; + + if (_OnTouch != null) + _OnTouch(sender, e); + } + } + + #endregion + public bool Exists { get { return GetSOP() != null; } -- cgit v1.1