28 using System.Collections.Generic;
29 using NUnit.Framework;
30 using OpenSim.Framework;
31 using OpenSim.Tests.Common;
32 using OpenSim.Region.ScriptEngine.Shared;
33 using OpenSim.Region.Framework.Scenes;
35 using OpenSim.Region.ScriptEngine.Shared.Api;
36 using OpenSim.Region.ScriptEngine.Shared.Instance;
37 using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
41 namespace OpenSim.
Region.ScriptEngine.Shared.Tests
46 [TestFixture, LongRunning]
49 private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d;
50 private const double ANGLE_ACCURACY_IN_RADIANS = 1
E-6;
56 IConfigSource initConfigSource =
new IniConfigSource();
57 IConfig config = initConfigSource.AddConfig(
"XEngine");
58 config.Set(
"Enabled",
"true");
64 engine.Initialise(initConfigSource);
65 engine.AddRegion(scene);
68 m_lslApi.Initialize(engine, part, null);
74 TestHelpers.InMethod();
76 CheckllAngleBetween(
new Vector3(1, 0, 0), 0, 1, 1);
77 CheckllAngleBetween(
new Vector3(1, 0, 0), 90, 1, 1);
78 CheckllAngleBetween(
new Vector3(1, 0, 0), 180, 1, 1);
80 CheckllAngleBetween(
new Vector3(0, 1, 0), 0, 1, 1);
81 CheckllAngleBetween(
new Vector3(0, 1, 0), 90, 1, 1);
82 CheckllAngleBetween(
new Vector3(0, 1, 0), 180, 1, 1);
84 CheckllAngleBetween(
new Vector3(0, 0, 1), 0, 1, 1);
85 CheckllAngleBetween(
new Vector3(0, 0, 1), 90, 1, 1);
86 CheckllAngleBetween(
new Vector3(0, 0, 1), 180, 1, 1);
88 CheckllAngleBetween(
new Vector3(1, 1, 1), 0, 1, 1);
89 CheckllAngleBetween(
new Vector3(1, 1, 1), 90, 1, 1);
90 CheckllAngleBetween(
new Vector3(1, 1, 1), 180, 1, 1);
92 CheckllAngleBetween(
new Vector3(1, 0, 0), 0, 1.6f, 1.8f);
93 CheckllAngleBetween(
new Vector3(1, 0, 0), 90, 0.3f, 3.9f);
94 CheckllAngleBetween(
new Vector3(1, 0, 0), 180, 8.8f, 7.4f);
96 CheckllAngleBetween(
new Vector3(0, 1, 0), 0, 9.8f, -9.4f);
97 CheckllAngleBetween(
new Vector3(0, 1, 0), 90, 8.4f, -8.2f);
98 CheckllAngleBetween(
new Vector3(0, 1, 0), 180, 0.4f, -5.8f);
100 CheckllAngleBetween(
new Vector3(0, 0, 1), 0, -6.8f, 3.4f);
101 CheckllAngleBetween(
new Vector3(0, 0, 1), 90, -3.6f, 5.6f);
102 CheckllAngleBetween(
new Vector3(0, 0, 1), 180, -3.8f, 1.1f);
104 CheckllAngleBetween(
new Vector3(1, 1, 1), 0, -7.7f, -2.0f);
105 CheckllAngleBetween(
new Vector3(1, 1, 1), 90, -3.0f, -9.1f);
106 CheckllAngleBetween(
new Vector3(1, 1, 1), 180, -7.9f, -8.0f);
109 private void CheckllAngleBetween(Vector3 axis,
float originalAngle,
float denorm1,
float denorm2)
111 Quaternion rotation1 = Quaternion.CreateFromAxisAngle(axis, 0);
112 Quaternion rotation2 = Quaternion.CreateFromAxisAngle(axis, ToRadians(originalAngle));
113 rotation1 *= denorm1;
114 rotation2 *= denorm2;
116 double deducedAngle = FromLslFloat(m_lslApi.llAngleBetween(ToLslQuaternion(rotation2), ToLslQuaternion(rotation1)));
118 Assert.That(deducedAngle, Is.EqualTo(ToRadians(originalAngle)).Within(ANGLE_ACCURACY_IN_RADIANS),
"TestllAngleBetween check fail");
121 #region Conversions to and from LSL_Types
123 private float ToRadians(
double degrees)
125 return (
float)(Math.PI * degrees / 180);
133 private double FromLslFloat(
LSL_Types.LSLFloat lslFloat)
135 return lslFloat.value;
159 TestHelpers.InMethod();
162 CheckllRot2Euler(
new LSL_Types.Quaternion(0.0f, 0.0f, 0.0f, 1.0f));
163 CheckllRot2Euler(
new LSL_Types.Quaternion(0.0f, 0.0f, 0.707107f, 0.707107f));
164 CheckllRot2Euler(
new LSL_Types.Quaternion(0.0f, 0.0f, 1.0f, 0.0f));
165 CheckllRot2Euler(
new LSL_Types.Quaternion(0.0f, 0.0f, 0.707107f, -0.707107f));
166 CheckllRot2Euler(
new LSL_Types.Quaternion(0.707107f, 0.0f, 0.0f, 0.707107f));
167 CheckllRot2Euler(
new LSL_Types.Quaternion(0.5f, -0.5f, 0.5f, 0.5f));
168 CheckllRot2Euler(
new LSL_Types.Quaternion(0.0f, -0.707107f, 0.707107f, 0.0f));
169 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.5f, -0.5f, 0.5f, -0.5f));
170 CheckllRot2Euler(
new LSL_Types.Quaternion(1.0f, 0.0f, 0.0f, 0.0f));
171 CheckllRot2Euler(
new LSL_Types.Quaternion(0.707107f, -0.707107f, 0.0f, 0.0f));
172 CheckllRot2Euler(
new LSL_Types.Quaternion(0.0f, -1.0f, 0.0f, 0.0f));
173 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.707107f, -0.707107f, 0.0f, 0.0f));
174 CheckllRot2Euler(
new LSL_Types.Quaternion(0.707107f, 0.0f, 0.0f, -0.707107f));
175 CheckllRot2Euler(
new LSL_Types.Quaternion(0.5f, -0.5f, -0.5f, -0.5f));
176 CheckllRot2Euler(
new LSL_Types.Quaternion(0.0f, -0.707107f, -0.707107f, 0.0f));
177 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.5f, -0.5f, -0.5f, 0.5f));
178 CheckllRot2Euler(
new LSL_Types.Quaternion(0.0f, -0.707107f, 0.0f, 0.707107f));
179 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.5f, -0.5f, 0.5f, 0.5f));
180 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.707107f, 0.0f, 0.707107f, 0.0f));
181 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.5f, 0.5f, 0.5f, -0.5f));
182 CheckllRot2Euler(
new LSL_Types.Quaternion(0.0f, -0.707107f, 0.0f, -0.707107f));
183 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.5f, -0.5f, -0.5f, -0.5f));
184 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.707107f, 0.0f, -0.707107f, 0.0f));
185 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.5f, 0.5f, -0.5f, 0.5f));
188 CheckllRot2Euler(
new LSL_Types.Quaternion(1.0f, 5.651f, -3.1f, 67.023f));
189 CheckllRot2Euler(
new LSL_Types.Quaternion(0.719188f, -0.408934f, -0.363998f, -0.427841f));
193 CheckllRot2Euler(
new LSL_Types.Quaternion(0.50001f, 0.50001f, 0.50001f, 0.50001f));
195 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.701055, 0.092296, 0.701055, -0.092296));
196 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.183005, -0.683010, 0.183005, 0.683010));
197 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.430460, -0.560982, 0.430460, 0.560982));
198 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.701066, 0.092301, -0.701066, 0.092301));
199 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.183013, -0.683010, 0.183013, 0.683010));
200 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.183005, -0.683014, -0.183005, -0.683014));
201 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.353556, 0.612375, 0.353556, -0.612375));
202 CheckllRot2Euler(
new LSL_Types.Quaternion(0.353554, -0.612385, -0.353554, 0.612385));
203 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.560989, 0.430450, 0.560989, -0.430450));
204 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.183013, 0.683009, -0.183013, 0.683009));
205 CheckllRot2Euler(
new LSL_Types.Quaternion(0.430457, -0.560985, -0.430457, 0.560985));
206 CheckllRot2Euler(
new LSL_Types.Quaternion(0.353552, 0.612360, -0.353552, -0.612360));
207 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.499991, 0.500003, 0.499991, -0.500003));
208 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.353555, -0.612385, -0.353555, -0.612385));
209 CheckllRot2Euler(
new LSL_Types.Quaternion(0.701066, -0.092301, -0.701066, 0.092301));
210 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.499991, 0.500007, 0.499991, -0.500007));
211 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.683002, 0.183016, -0.683002, 0.183016));
212 CheckllRot2Euler(
new LSL_Types.Quaternion(0.430458, 0.560982, 0.430458, 0.560982));
213 CheckllRot2Euler(
new LSL_Types.Quaternion(0.499991, -0.500003, -0.499991, 0.500003));
214 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.183009, 0.683011, -0.183009, 0.683011));
215 CheckllRot2Euler(
new LSL_Types.Quaternion(0.560975, -0.430457, 0.560975, -0.430457));
216 CheckllRot2Euler(
new LSL_Types.Quaternion(0.701055, 0.092300, 0.701055, 0.092300));
217 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.560990, 0.430459, -0.560990, 0.430459));
218 CheckllRot2Euler(
new LSL_Types.Quaternion(-0.092302, -0.701059, -0.092302, -0.701059));
241 private void CheckllRot2Euler(
LSL_Types.Quaternion rot)
250 Assert.AreEqual(0.0, check.x, VECTOR_COMPONENT_ACCURACY,
"TestllRot2Euler X bounds check fail");
251 Assert.AreEqual(0.0, check.y, VECTOR_COMPONENT_ACCURACY,
"TestllRot2Euler Y bounds check fail");
252 Assert.AreEqual(0.0, check.z, VECTOR_COMPONENT_ACCURACY,
"TestllRot2Euler Z bounds check fail");
258 TestHelpers.InMethod();
274 Assert.AreEqual(vecNorm.x, vecNormCheck.x, VECTOR_COMPONENT_ACCURACY,
"TestllVecNorm vector check fail on x component");
275 Assert.AreEqual(vecNorm.y, vecNormCheck.y, VECTOR_COMPONENT_ACCURACY,
"TestllVecNorm vector check fail on y component");
276 Assert.AreEqual(vecNorm.z, vecNormCheck.z, VECTOR_COMPONENT_ACCURACY,
"TestllVecNorm vector check fail on z component");
Contains all LSL ll-functions. This class will be in Default AppDomain.
void CheckllVecNorm(LSL_Types.Vector3 vec, LSL_Types.Vector3 vecNormCheck)
void TestllAngleBetween()
Helpers for setting up scenes.