aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs151
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs14
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs81
3 files changed, 212 insertions, 34 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs b/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs
new file mode 100644
index 0000000..14501c7
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs
@@ -0,0 +1,151 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Reflection;
31using log4net;
32using Nini.Config;
33using Mono.Addins;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Services.Interfaces;
40using Caps = OpenSim.Framework.Capabilities.Caps;
41using OpenSim.Capabilities.Handlers;
42
43namespace OpenSim.Region.ClientStack.Linden
44{
45 /// <summary>
46 /// This module implements both WebFetchInventoryDescendents and FetchInventoryDescendents2 capabilities.
47 /// </summary>
48 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
49 public class FetchInventory2Module : INonSharedRegionModule
50 {
51// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52
53 public bool Enabled { get; private set; }
54
55 private Scene m_scene;
56
57 private IInventoryService m_inventoryService;
58
59 private string m_fetchInventory2Url;
60
61 private FetchInventory2Handler m_fetchHandler;
62
63 #region ISharedRegionModule Members
64
65 public void Initialise(IConfigSource source)
66 {
67 IConfig config = source.Configs["ClientStack.LindenCaps"];
68 if (config == null)
69 return;
70
71 m_fetchInventory2Url = config.GetString("Cap_FetchInventory2", string.Empty);
72
73 if (m_fetchInventory2Url != string.Empty)
74 Enabled = true;
75 }
76
77 public void AddRegion(Scene s)
78 {
79 if (!Enabled)
80 return;
81
82 m_scene = s;
83 }
84
85 public void RemoveRegion(Scene s)
86 {
87 if (!Enabled)
88 return;
89
90 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
91 m_scene = null;
92 }
93
94 public void RegionLoaded(Scene s)
95 {
96 if (!Enabled)
97 return;
98
99 m_inventoryService = m_scene.InventoryService;
100
101 // We'll reuse the same handler for all requests.
102 if (m_fetchInventory2Url == "localhost")
103 m_fetchHandler = new FetchInventory2Handler(m_inventoryService);
104
105 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
106 }
107
108 public void PostInitialise() {}
109
110 public void Close() {}
111
112 public string Name { get { return "FetchInventory2Module"; } }
113
114 public Type ReplaceableInterface
115 {
116 get { return null; }
117 }
118
119 #endregion
120
121 private void RegisterCaps(UUID agentID, Caps caps)
122 {
123 RegisterFetchCap(agentID, caps, "FetchInventory2", m_fetchInventory2Url);
124 }
125
126 private void RegisterFetchCap(UUID agentID, Caps caps, string capName, string url)
127 {
128 string capUrl;
129
130 if (url == "localhost")
131 {
132 capUrl = "/CAPS/" + UUID.Random();
133
134 IRequestHandler reqHandler
135 = new RestStreamHandler("POST", capUrl, m_fetchHandler.FetchInventoryRequest);
136
137 caps.RegisterHandler(capName, reqHandler);
138 }
139 else
140 {
141 capUrl = url;
142
143 caps.RegisterHandler(capName, capUrl);
144 }
145
146// m_log.DebugFormat(
147// "[FETCH INVENTORY2 MODULE]: Registered capability {0} at {1} in region {2} for {3}",
148// capName, capUrl, m_scene.RegionInfo.RegionName, agentID);
149 }
150 }
151}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 3bc8750..466e540 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -5096,15 +5096,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5096 return (double)Math.Asin(val); 5096 return (double)Math.Asin(val);
5097 } 5097 }
5098 5098
5099 // Xantor 30/apr/2008 5099 // jcochran 5/jan/2012
5100 public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b) 5100 public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
5101 { 5101 {
5102 m_host.AddScriptLPS(1); 5102 m_host.AddScriptLPS(1);
5103 5103
5104 double angle = Math.Acos(a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s) * 2; 5104 double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s);
5105 if (angle < 0) angle = -angle; 5105 double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s);
5106 if (angle > Math.PI) return (Math.PI * 2 - angle); 5106 double aa_bb = aa * bb;
5107 return angle; 5107 if (aa_bb == 0) return 0.0;
5108 double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s);
5109 double quotient = (ab * ab) / aa_bb;
5110 if (quotient >= 1.0) return 0.0;
5111 return Math.Acos(2 * quotient - 1);
5108 } 5112 }
5109 5113
5110 public LSL_String llGetInventoryKey(string name) 5114 public LSL_String llGetInventoryKey(string name)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
index 7594691..3baa723 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
@@ -75,32 +75,49 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
75 [Test] 75 [Test]
76 public void TestllAngleBetween() 76 public void TestllAngleBetween()
77 { 77 {
78 CheckllAngleBetween(new Vector3(1, 0, 0), 0); 78 CheckllAngleBetween(new Vector3(1, 0, 0), 0, 1, 1);
79 CheckllAngleBetween(new Vector3(1, 0, 0), 90); 79 CheckllAngleBetween(new Vector3(1, 0, 0), 90, 1, 1);
80 CheckllAngleBetween(new Vector3(1, 0, 0), 180); 80 CheckllAngleBetween(new Vector3(1, 0, 0), 180, 1, 1);
81 81
82 CheckllAngleBetween(new Vector3(0, 1, 0), 0); 82 CheckllAngleBetween(new Vector3(0, 1, 0), 0, 1, 1);
83 CheckllAngleBetween(new Vector3(0, 1, 0), 90); 83 CheckllAngleBetween(new Vector3(0, 1, 0), 90, 1, 1);
84 CheckllAngleBetween(new Vector3(0, 1, 0), 180); 84 CheckllAngleBetween(new Vector3(0, 1, 0), 180, 1, 1);
85 85
86 CheckllAngleBetween(new Vector3(0, 0, 1), 0); 86 CheckllAngleBetween(new Vector3(0, 0, 1), 0, 1, 1);
87 CheckllAngleBetween(new Vector3(0, 0, 1), 90); 87 CheckllAngleBetween(new Vector3(0, 0, 1), 90, 1, 1);
88 CheckllAngleBetween(new Vector3(0, 0, 1), 180); 88 CheckllAngleBetween(new Vector3(0, 0, 1), 180, 1, 1);
89 89
90 CheckllAngleBetween(new Vector3(1, 1, 1), 0); 90 CheckllAngleBetween(new Vector3(1, 1, 1), 0, 1, 1);
91 CheckllAngleBetween(new Vector3(1, 1, 1), 90); 91 CheckllAngleBetween(new Vector3(1, 1, 1), 90, 1, 1);
92 CheckllAngleBetween(new Vector3(1, 1, 1), 180); 92 CheckllAngleBetween(new Vector3(1, 1, 1), 180, 1, 1);
93
94 CheckllAngleBetween(new Vector3(1, 0, 0), 0, 1.6f, 1.8f);
95 CheckllAngleBetween(new Vector3(1, 0, 0), 90, 0.3f, 3.9f);
96 CheckllAngleBetween(new Vector3(1, 0, 0), 180, 8.8f, 7.4f);
97
98 CheckllAngleBetween(new Vector3(0, 1, 0), 0, 9.8f, -9.4f);
99 CheckllAngleBetween(new Vector3(0, 1, 0), 90, 8.4f, -8.2f);
100 CheckllAngleBetween(new Vector3(0, 1, 0), 180, 0.4f, -5.8f);
101
102 CheckllAngleBetween(new Vector3(0, 0, 1), 0, -6.8f, 3.4f);
103 CheckllAngleBetween(new Vector3(0, 0, 1), 90, -3.6f, 5.6f);
104 CheckllAngleBetween(new Vector3(0, 0, 1), 180, -3.8f, 1.1f);
105
106 CheckllAngleBetween(new Vector3(1, 1, 1), 0, -7.7f, -2.0f);
107 CheckllAngleBetween(new Vector3(1, 1, 1), 90, -3.0f, -9.1f);
108 CheckllAngleBetween(new Vector3(1, 1, 1), 180, -7.9f, -8.0f);
93 } 109 }
94 110
95 private void CheckllAngleBetween(Vector3 axis,float originalAngle) 111 private void CheckllAngleBetween(Vector3 axis,float originalAngle, float denorm1, float denorm2)
96 { 112 {
97 Quaternion rotation1 = Quaternion.CreateFromAxisAngle(axis, 0); 113 Quaternion rotation1 = Quaternion.CreateFromAxisAngle(axis, 0);
98 Quaternion rotation2 = Quaternion.CreateFromAxisAngle(axis, ToRadians(originalAngle)); 114 Quaternion rotation2 = Quaternion.CreateFromAxisAngle(axis, ToRadians(originalAngle));
115 rotation1 *= denorm1;
116 rotation2 *= denorm2;
99 117
100 double deducedAngle = FromLslFloat(m_lslApi.llAngleBetween(ToLslQuaternion(rotation2), ToLslQuaternion(rotation1))); 118 double deducedAngle = FromLslFloat(m_lslApi.llAngleBetween(ToLslQuaternion(rotation2), ToLslQuaternion(rotation1)));
101 119
102 Assert.Greater(deducedAngle, ToRadians(originalAngle) - ANGLE_ACCURACY_IN_RADIANS); 120 Assert.That(deducedAngle, Is.EqualTo(ToRadians(originalAngle)).Within(ANGLE_ACCURACY_IN_RADIANS), "TestllAngleBetween check fail");
103 Assert.Less(deducedAngle, ToRadians(originalAngle) + ANGLE_ACCURACY_IN_RADIANS);
104 } 121 }
105 122
106 #region Conversions to and from LSL_Types 123 #region Conversions to and from LSL_Types
@@ -201,20 +218,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
201 CheckllRot2Euler(new LSL_Types.Quaternion(-0.092302, -0.701059, -0.092302, -0.701059)); 218 CheckllRot2Euler(new LSL_Types.Quaternion(-0.092302, -0.701059, -0.092302, -0.701059));
202 } 219 }
203 220
204 // Testing Rot2Euler this way instead of comparing against expected angles because 221 /// <summary>
205 // 1. There are several ways to get to the original Quaternion. For example a rotation 222 /// Check an llRot2Euler conversion.
206 // of PI and -PI will give the same result. But PI and -PI aren't equal. 223 /// </summary>
207 // 2. This method checks to see if the calculated angles from a quaternion can be used 224 /// <remarks>
208 // to create a new quaternion to produce the same rotation. 225 /// Testing Rot2Euler this way instead of comparing against expected angles because
209 // However, can't compare the newly calculated quaternion against the original because 226 /// 1. There are several ways to get to the original Quaternion. For example a rotation
210 // once again, there are multiple quaternions that give the same result. For instance 227 /// of PI and -PI will give the same result. But PI and -PI aren't equal.
211 // <X, Y, Z, S> == <-X, -Y, -Z, -S>. Additionally, the magnitude of S can be changed 228 /// 2. This method checks to see if the calculated angles from a quaternion can be used
212 // and will still result in the same rotation if the values for X, Y, Z are also changed 229 /// to create a new quaternion to produce the same rotation.
213 // to compensate. 230 /// However, can't compare the newly calculated quaternion against the original because
214 // However, if two quaternions represent the same rotation, then multiplying the first 231 /// once again, there are multiple quaternions that give the same result. For instance
215 // quaternion by the conjugate of the second, will give a third quaternion representing 232 /// <X, Y, Z, S> == <-X, -Y, -Z, -S>. Additionally, the magnitude of S can be changed
216 // a zero rotation. This can be tested for by looking at the X, Y, Z values which should 233 /// and will still result in the same rotation if the values for X, Y, Z are also changed
217 // be zero. 234 /// to compensate.
235 /// However, if two quaternions represent the same rotation, then multiplying the first
236 /// quaternion by the conjugate of the second, will give a third quaternion representing
237 /// a zero rotation. This can be tested for by looking at the X, Y, Z values which should
238 /// be zero.
239 /// </remarks>
240 /// <param name="rot"></param>
218 private void CheckllRot2Euler(LSL_Types.Quaternion rot) 241 private void CheckllRot2Euler(LSL_Types.Quaternion rot)
219 { 242 {
220 // Call LSL function to convert quaternion rotaion to euler radians. 243 // Call LSL function to convert quaternion rotaion to euler radians.