LSL_ApiTest.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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. using System.Collections.Generic;
  28. using NUnit.Framework;
  29. using OpenSim.Framework;
  30. using OpenSim.Tests.Common;
  31. using OpenSim.Region.ScriptEngine.Shared;
  32. using OpenSim.Region.Framework.Scenes;
  33. using Nini.Config;
  34. using OpenSim.Region.ScriptEngine.Shared.Api;
  35. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  36. using OpenMetaverse;
  37. using System;
  38. using OpenSim.Tests.Common.Mock;
  39. namespace OpenSim.Region.ScriptEngine.Shared.Tests
  40. {
  41. /// <summary>
  42. /// Tests for LSL_Api
  43. /// </summary>
  44. [TestFixture, LongRunning]
  45. public class LSL_ApiTest
  46. {
  47. private const double ANGLE_ACCURACY_IN_RADIANS = 1E-6;
  48. private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d;
  49. private const double FLOAT_ACCURACY = 0.00005d;
  50. private LSL_Api m_lslApi;
  51. [SetUp]
  52. public void SetUp()
  53. {
  54. IConfigSource initConfigSource = new IniConfigSource();
  55. IConfig config = initConfigSource.AddConfig("XEngine");
  56. config.Set("Enabled", "true");
  57. Scene scene = SceneHelpers.SetupScene();
  58. SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
  59. XEngine.XEngine engine = new XEngine.XEngine();
  60. engine.Initialise(initConfigSource);
  61. engine.AddRegion(scene);
  62. m_lslApi = new LSL_Api();
  63. m_lslApi.Initialize(engine, part, part.LocalId, part.UUID);
  64. }
  65. [Test]
  66. public void TestllAngleBetween()
  67. {
  68. CheckllAngleBetween(new Vector3(1, 0, 0), 0);
  69. CheckllAngleBetween(new Vector3(1, 0, 0), 90);
  70. CheckllAngleBetween(new Vector3(1, 0, 0), 180);
  71. CheckllAngleBetween(new Vector3(0, 1, 0), 0);
  72. CheckllAngleBetween(new Vector3(0, 1, 0), 90);
  73. CheckllAngleBetween(new Vector3(0, 1, 0), 180);
  74. CheckllAngleBetween(new Vector3(0, 0, 1), 0);
  75. CheckllAngleBetween(new Vector3(0, 0, 1), 90);
  76. CheckllAngleBetween(new Vector3(0, 0, 1), 180);
  77. CheckllAngleBetween(new Vector3(1, 1, 1), 0);
  78. CheckllAngleBetween(new Vector3(1, 1, 1), 90);
  79. CheckllAngleBetween(new Vector3(1, 1, 1), 180);
  80. }
  81. private void CheckllAngleBetween(Vector3 axis,float originalAngle)
  82. {
  83. Quaternion rotation1 = Quaternion.CreateFromAxisAngle(axis, 0);
  84. Quaternion rotation2 = Quaternion.CreateFromAxisAngle(axis, ToRadians(originalAngle));
  85. double deducedAngle = FromLslFloat(m_lslApi.llAngleBetween(ToLslQuaternion(rotation2), ToLslQuaternion(rotation1)));
  86. Assert.Greater(deducedAngle, ToRadians(originalAngle) - ANGLE_ACCURACY_IN_RADIANS);
  87. Assert.Less(deducedAngle, ToRadians(originalAngle) + ANGLE_ACCURACY_IN_RADIANS);
  88. }
  89. #region Conversions to and from LSL_Types
  90. private float ToRadians(double degrees)
  91. {
  92. return (float)(Math.PI * degrees / 180);
  93. }
  94. // private double FromRadians(float radians)
  95. // {
  96. // return radians * 180 / Math.PI;
  97. // }
  98. private double FromLslFloat(LSL_Types.LSLFloat lslFloat)
  99. {
  100. return lslFloat.value;
  101. }
  102. // private LSL_Types.LSLFloat ToLslFloat(double value)
  103. // {
  104. // return new LSL_Types.LSLFloat(value);
  105. // }
  106. // private Quaternion FromLslQuaternion(LSL_Types.Quaternion lslQuaternion)
  107. // {
  108. // return new Quaternion((float)lslQuaternion.x, (float)lslQuaternion.y, (float)lslQuaternion.z, (float)lslQuaternion.s);
  109. // }
  110. private LSL_Types.Quaternion ToLslQuaternion(Quaternion quaternion)
  111. {
  112. return new LSL_Types.Quaternion(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
  113. }
  114. #endregion
  115. [Test]
  116. // llRot2Euler test.
  117. public void TestllRot2Euler()
  118. {
  119. // 180, 90 and zero degree rotations.
  120. CheckllRot2Euler(new LSL_Types.Quaternion(1.0f, 0.0f, 0.0f, 0.0f), new LSL_Types.Vector3(Math.PI, 0.0f, 0.0f));
  121. CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 1.0f, 0.0f, 0.0f), new LSL_Types.Vector3(Math.PI, 0.0f, Math.PI));
  122. CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 1.0f, 0.0f), new LSL_Types.Vector3(0.0f, 0.0f, Math.PI));
  123. CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 0.0f, 1.0f), new LSL_Types.Vector3(0.0f, 0.0f, 0.0f));
  124. CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, -0.5f, 0.5f, 0.5f), new LSL_Types.Vector3(0, -Math.PI / 2.0f, Math.PI / 2.0f));
  125. CheckllRot2Euler(new LSL_Types.Quaternion(-0.707107f, 0.0f, 0.0f, -0.707107f), new LSL_Types.Vector3(Math.PI / 2.0f, 0.0f, 0.0f));
  126. // A couple of messy rotations.
  127. CheckllRot2Euler(new LSL_Types.Quaternion(1.0f, 5.651f, -3.1f, 67.023f), new LSL_Types.Vector3(0.037818f, 0.166447f, -0.095595f));
  128. CheckllRot2Euler(new LSL_Types.Quaternion(0.719188f, -0.408934f, -0.363998f, -0.427841f), new LSL_Types.Vector3(-1.954769f, -0.174533f, 1.151917f));
  129. }
  130. private void CheckllRot2Euler(LSL_Types.Quaternion rot, LSL_Types.Vector3 eulerCheck)
  131. {
  132. // Call LSL function to convert quaternion rotaion to euler radians.
  133. LSL_Types.Vector3 eulerCalc = m_lslApi.llRot2Euler(rot);
  134. // Check upper and lower bounds of x, y and z.
  135. // This type of check is performed as opposed to comparing for equal numbers, in order to allow slight
  136. // differences in accuracy.
  137. Assert.Greater(eulerCalc.x, eulerCheck.x - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler X lower bounds check fail");
  138. Assert.Less(eulerCalc.x, eulerCheck.x + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler X upper bounds check fail");
  139. Assert.Greater(eulerCalc.y, eulerCheck.y - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Y lower bounds check fail");
  140. Assert.Less(eulerCalc.y, eulerCheck.y + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Y upper bounds check fail");
  141. Assert.Greater(eulerCalc.z, eulerCheck.z - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Z lower bounds check fail");
  142. Assert.Less(eulerCalc.z, eulerCheck.z + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Z upper bounds check fail");
  143. }
  144. [Test]
  145. // llSetPrimitiveParams and llGetPrimitiveParams test.
  146. public void TestllSetPrimitiveParams()
  147. {
  148. // Create Prim1.
  149. Scene scene = SceneHelpers.SetupScene();
  150. string obj1Name = "Prim1";
  151. UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
  152. SceneObjectPart part1 =
  153. new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default,
  154. Vector3.Zero, Quaternion.Identity,
  155. Vector3.Zero) { Name = obj1Name, UUID = objUuid };
  156. Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True);
  157. // Note that prim hollow check is passed with the other prim params in order to allow the
  158. // specification of a different check value from the prim param. A cylinder, prism, sphere,
  159. // torus or ring, with a hole shape of square, is limited to a hollow of 70%. Test 5 below
  160. // specifies a value of 95% and checks to see if 70% was properly returned.
  161. // Test a sphere.
  162. CheckllSetPrimitiveParams(
  163. "test 1", // Prim test identification string
  164. new LSL_Types.Vector3(6.0d, 9.9d, 9.9d), // Prim size
  165. ScriptBaseClass.PRIM_TYPE_SPHERE, // Prim type
  166. ScriptBaseClass.PRIM_HOLE_DEFAULT, // Prim hole type
  167. new LSL_Types.Vector3(0.0d, 0.075d, 0.0d), // Prim cut
  168. 0.80d, // Prim hollow
  169. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
  170. new LSL_Types.Vector3(0.32d, 0.76d, 0.0d), // Prim dimple
  171. 0.80d); // Prim hollow check
  172. // Test a prism.
  173. CheckllSetPrimitiveParams(
  174. "test 2", // Prim test identification string
  175. new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
  176. ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
  177. ScriptBaseClass.PRIM_HOLE_CIRCLE, // Prim hole type
  178. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
  179. 0.90d, // Prim hollow
  180. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
  181. new LSL_Types.Vector3(2.0d, 1.0d, 0.0d), // Prim taper
  182. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
  183. 0.90d); // Prim hollow check
  184. // Test a box.
  185. CheckllSetPrimitiveParams(
  186. "test 3", // Prim test identification string
  187. new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
  188. ScriptBaseClass.PRIM_TYPE_BOX, // Prim type
  189. ScriptBaseClass.PRIM_HOLE_TRIANGLE, // Prim hole type
  190. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
  191. 0.95d, // Prim hollow
  192. new LSL_Types.Vector3(1.0d, 0.0d, 0.0d), // Prim twist
  193. new LSL_Types.Vector3(1.0d, 1.0d, 0.0d), // Prim taper
  194. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
  195. 0.95d); // Prim hollow check
  196. // Test a tube.
  197. CheckllSetPrimitiveParams(
  198. "test 4", // Prim test identification string
  199. new LSL_Types.Vector3(4.2d, 4.2d, 4.2d), // Prim size
  200. ScriptBaseClass.PRIM_TYPE_TUBE, // Prim type
  201. ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
  202. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
  203. 0.00d, // Prim hollow
  204. new LSL_Types.Vector3(1.0d, -1.0d, 0.0d), // Prim twist
  205. new LSL_Types.Vector3(1.0d, 0.5d, 0.0d), // Prim hole size
  206. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
  207. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim profile cut
  208. new LSL_Types.Vector3(-1.0d, 1.0d, 0.0d), // Prim taper
  209. 1.0d, // Prim revolutions
  210. 1.0d, // Prim radius
  211. 0.0d, // Prim skew
  212. 0.00d); // Prim hollow check
  213. // Test a prism.
  214. CheckllSetPrimitiveParams(
  215. "test 5", // Prim test identification string
  216. new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
  217. ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
  218. ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
  219. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
  220. 0.95d, // Prim hollow
  221. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
  222. new LSL_Types.Vector3(2.0d, 1.0d, 0.0d), // Prim taper
  223. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
  224. 0.70d); // Prim hollow check
  225. // Test a sculpted prim.
  226. CheckllSetPrimitiveParams(
  227. "test 6", // Prim test identification string
  228. new LSL_Types.Vector3(2.0d, 2.0d, 2.0d), // Prim size
  229. ScriptBaseClass.PRIM_TYPE_SCULPT, // Prim type
  230. "be293869-d0d9-0a69-5989-ad27f1946fd4", // Prim map
  231. ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE); // Prim sculpt type
  232. }
  233. // Set prim params for a box, cylinder or prism and check results.
  234. public void CheckllSetPrimitiveParams(string primTest,
  235. LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
  236. double primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primTaper, LSL_Types.Vector3 primShear,
  237. double primHollowCheck)
  238. {
  239. // Set the prim params.
  240. m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  241. ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
  242. primCut, primHollow, primTwist, primTaper, primShear));
  243. // Get params for prim to validate settings.
  244. LSL_Types.list primParams =
  245. m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  246. // Validate settings.
  247. CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
  248. Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
  249. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  250. Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
  251. "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
  252. CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
  253. Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
  254. "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
  255. CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
  256. CheckllSetPrimitiveParamsVector(primTaper, m_lslApi.llList2Vector(primParams, 6), primTest + " prim taper");
  257. CheckllSetPrimitiveParamsVector(primShear, m_lslApi.llList2Vector(primParams, 7), primTest + " prim shear");
  258. }
  259. // Set prim params for a sphere and check results.
  260. public void CheckllSetPrimitiveParams(string primTest,
  261. LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
  262. double primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primDimple, double primHollowCheck)
  263. {
  264. // Set the prim params.
  265. m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  266. ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
  267. primCut, primHollow, primTwist, primDimple));
  268. // Get params for prim to validate settings.
  269. LSL_Types.list primParams =
  270. m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  271. // Validate settings.
  272. CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
  273. Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
  274. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  275. Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
  276. "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
  277. CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
  278. Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
  279. "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
  280. CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
  281. CheckllSetPrimitiveParamsVector(primDimple, m_lslApi.llList2Vector(primParams, 6), primTest + " prim dimple");
  282. }
  283. // Set prim params for a torus, tube or ring and check results.
  284. public void CheckllSetPrimitiveParams(string primTest,
  285. LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
  286. double primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primHoleSize,
  287. LSL_Types.Vector3 primShear, LSL_Types.Vector3 primProfCut, LSL_Types.Vector3 primTaper,
  288. double primRev, double primRadius, double primSkew, double primHollowCheck)
  289. {
  290. // Set the prim params.
  291. m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  292. ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
  293. primCut, primHollow, primTwist, primHoleSize, primShear, primProfCut,
  294. primTaper, primRev, primRadius, primSkew));
  295. // Get params for prim to validate settings.
  296. LSL_Types.list primParams =
  297. m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  298. // Valdate settings.
  299. CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
  300. Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
  301. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  302. Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
  303. "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
  304. CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
  305. Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
  306. "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
  307. CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
  308. CheckllSetPrimitiveParamsVector(primHoleSize, m_lslApi.llList2Vector(primParams, 6), primTest + " prim hole size");
  309. CheckllSetPrimitiveParamsVector(primShear, m_lslApi.llList2Vector(primParams, 7), primTest + " prim shear");
  310. CheckllSetPrimitiveParamsVector(primProfCut, m_lslApi.llList2Vector(primParams, 8), primTest + " prim profile cut");
  311. CheckllSetPrimitiveParamsVector(primTaper, m_lslApi.llList2Vector(primParams, 9), primTest + " prim taper");
  312. Assert.AreEqual(primRev, m_lslApi.llList2Float(primParams, 10), FLOAT_ACCURACY,
  313. "TestllSetPrimitiveParams " + primTest + " prim revolution fail");
  314. Assert.AreEqual(primRadius, m_lslApi.llList2Float(primParams, 11), FLOAT_ACCURACY,
  315. "TestllSetPrimitiveParams " + primTest + " prim radius fail");
  316. Assert.AreEqual(primSkew, m_lslApi.llList2Float(primParams, 12), FLOAT_ACCURACY,
  317. "TestllSetPrimitiveParams " + primTest + " prim skew fail");
  318. }
  319. // Set prim params for a sculpted prim and check results.
  320. public void CheckllSetPrimitiveParams(string primTest,
  321. LSL_Types.Vector3 primSize, int primType, string primMap, int primSculptType)
  322. {
  323. // Set the prim params.
  324. m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  325. ScriptBaseClass.PRIM_TYPE, primType, primMap, primSculptType));
  326. // Get params for prim to validate settings.
  327. LSL_Types.list primParams =
  328. m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  329. // Validate settings.
  330. CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
  331. Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
  332. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  333. Assert.AreEqual(primMap, (string)m_lslApi.llList2String(primParams, 2),
  334. "TestllSetPrimitiveParams " + primTest + " prim map check fail");
  335. Assert.AreEqual(primSculptType, m_lslApi.llList2Integer(primParams, 3),
  336. "TestllSetPrimitiveParams " + primTest + " prim type scuplt check fail");
  337. }
  338. public void CheckllSetPrimitiveParamsVector(LSL_Types.Vector3 vecCheck, LSL_Types.Vector3 vecReturned, string msg)
  339. {
  340. // Check each vector component against expected result.
  341. Assert.AreEqual(vecCheck.x, vecReturned.x, VECTOR_COMPONENT_ACCURACY,
  342. "TestllSetPrimitiveParams " + msg + " vector check fail on x component");
  343. Assert.AreEqual(vecCheck.y, vecReturned.y, VECTOR_COMPONENT_ACCURACY,
  344. "TestllSetPrimitiveParams " + msg + " vector check fail on y component");
  345. Assert.AreEqual(vecCheck.z, vecReturned.z, VECTOR_COMPONENT_ACCURACY,
  346. "TestllSetPrimitiveParams " + msg + " vector check fail on z component");
  347. }
  348. [Test]
  349. // llVecNorm test.
  350. public void TestllVecNorm()
  351. {
  352. // Check special case for normalizing zero vector.
  353. CheckllVecNorm(new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), new LSL_Types.Vector3(0.0d, 0.0d, 0.0d));
  354. // Check various vectors.
  355. CheckllVecNorm(new LSL_Types.Vector3(10.0d, 25.0d, 0.0d), new LSL_Types.Vector3(0.371391d, 0.928477d, 0.0d));
  356. CheckllVecNorm(new LSL_Types.Vector3(1.0d, 0.0d, 0.0d), new LSL_Types.Vector3(1.0d, 0.0d, 0.0d));
  357. CheckllVecNorm(new LSL_Types.Vector3(-90.0d, 55.0d, 2.0d), new LSL_Types.Vector3(-0.853128d, 0.521356d, 0.018958d));
  358. CheckllVecNorm(new LSL_Types.Vector3(255.0d, 255.0d, 255.0d), new LSL_Types.Vector3(0.577350d, 0.577350d, 0.577350d));
  359. }
  360. public void CheckllVecNorm(LSL_Types.Vector3 vec, LSL_Types.Vector3 vecNormCheck)
  361. {
  362. // Call LSL function to normalize the vector.
  363. LSL_Types.Vector3 vecNorm = m_lslApi.llVecNorm(vec);
  364. // Check each vector component against expected result.
  365. Assert.AreEqual(vecNorm.x, vecNormCheck.x, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on x component");
  366. Assert.AreEqual(vecNorm.y, vecNormCheck.y, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on y component");
  367. Assert.AreEqual(vecNorm.z, vecNormCheck.z, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on z component");
  368. }
  369. }
  370. }