LSL_ApiTest.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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 float FLOAT_ACCURACY = 0.00005f;
  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.80f, // 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.80f); // 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.90f, // 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.90f); // 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.95f, // 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.95f); // 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.00f, // Prim hollow
  204. new LSL_Types.Vector3(1.0d, -1.0d, 0.0d), // Prim twist
  205. new LSL_Types.Vector3(1.0d, 0.05d, 0.0d), // Prim hole size
  206. // Expression for y selected to test precision problems during byte
  207. // cast in SetPrimitiveShapeParams.
  208. new LSL_Types.Vector3(0.0d, 0.35d + 0.1d, 0.0d), // Prim shear
  209. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim profile cut
  210. // Expression for y selected to test precision problems during sbyte
  211. // cast in SetPrimitiveShapeParams.
  212. new LSL_Types.Vector3(-1.0d, 0.70d + 0.1d + 0.1d, 0.0d), // Prim taper
  213. 1.11f, // Prim revolutions
  214. 0.88f, // Prim radius
  215. 0.95f, // Prim skew
  216. 0.00f); // Prim hollow check
  217. // Test a prism.
  218. CheckllSetPrimitiveParams(
  219. "test 5", // Prim test identification string
  220. new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
  221. ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
  222. ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
  223. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
  224. 0.95f, // Prim hollow
  225. // Expression for x selected to test precision problems during sbyte
  226. // cast in SetPrimitiveShapeBlockParams.
  227. new LSL_Types.Vector3(0.7d + 0.2d, 0.0d, 0.0d), // Prim twist
  228. // Expression for y selected to test precision problems during sbyte
  229. // cast in SetPrimitiveShapeParams.
  230. new LSL_Types.Vector3(2.0d, (1.3d + 0.1d), 0.0d), // Prim taper
  231. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
  232. 0.70f); // Prim hollow check
  233. // Test a sculpted prim.
  234. CheckllSetPrimitiveParams(
  235. "test 6", // Prim test identification string
  236. new LSL_Types.Vector3(2.0d, 2.0d, 2.0d), // Prim size
  237. ScriptBaseClass.PRIM_TYPE_SCULPT, // Prim type
  238. "be293869-d0d9-0a69-5989-ad27f1946fd4", // Prim map
  239. ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE); // Prim sculpt type
  240. }
  241. // Set prim params for a box, cylinder or prism and check results.
  242. public void CheckllSetPrimitiveParams(string primTest,
  243. LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
  244. float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primTaper, LSL_Types.Vector3 primShear,
  245. float primHollowCheck)
  246. {
  247. // Set the prim params.
  248. m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  249. ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
  250. primCut, primHollow, primTwist, primTaper, primShear));
  251. // Get params for prim to validate settings.
  252. LSL_Types.list primParams =
  253. m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  254. // Validate settings.
  255. CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
  256. Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
  257. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  258. Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
  259. "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
  260. CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
  261. Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
  262. "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
  263. CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
  264. CheckllSetPrimitiveParamsVector(primTaper, m_lslApi.llList2Vector(primParams, 6), primTest + " prim taper");
  265. CheckllSetPrimitiveParamsVector(primShear, m_lslApi.llList2Vector(primParams, 7), primTest + " prim shear");
  266. }
  267. // Set prim params for a sphere and check results.
  268. public void CheckllSetPrimitiveParams(string primTest,
  269. LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
  270. float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primDimple, float primHollowCheck)
  271. {
  272. // Set the prim params.
  273. m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  274. ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
  275. primCut, primHollow, primTwist, primDimple));
  276. // Get params for prim to validate settings.
  277. LSL_Types.list primParams =
  278. m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  279. // Validate settings.
  280. CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
  281. Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
  282. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  283. Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
  284. "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
  285. CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
  286. Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
  287. "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
  288. CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
  289. CheckllSetPrimitiveParamsVector(primDimple, m_lslApi.llList2Vector(primParams, 6), primTest + " prim dimple");
  290. }
  291. // Set prim params for a torus, tube or ring and check results.
  292. public void CheckllSetPrimitiveParams(string primTest,
  293. LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
  294. float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primHoleSize,
  295. LSL_Types.Vector3 primShear, LSL_Types.Vector3 primProfCut, LSL_Types.Vector3 primTaper,
  296. float primRev, float primRadius, float primSkew, float primHollowCheck)
  297. {
  298. // Set the prim params.
  299. m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  300. ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
  301. primCut, primHollow, primTwist, primHoleSize, primShear, primProfCut,
  302. primTaper, primRev, primRadius, primSkew));
  303. // Get params for prim to validate settings.
  304. LSL_Types.list primParams =
  305. m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  306. // Valdate settings.
  307. CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
  308. Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
  309. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  310. Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
  311. "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
  312. CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
  313. Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
  314. "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
  315. CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
  316. CheckllSetPrimitiveParamsVector(primHoleSize, m_lslApi.llList2Vector(primParams, 6), primTest + " prim hole size");
  317. CheckllSetPrimitiveParamsVector(primShear, m_lslApi.llList2Vector(primParams, 7), primTest + " prim shear");
  318. CheckllSetPrimitiveParamsVector(primProfCut, m_lslApi.llList2Vector(primParams, 8), primTest + " prim profile cut");
  319. CheckllSetPrimitiveParamsVector(primTaper, m_lslApi.llList2Vector(primParams, 9), primTest + " prim taper");
  320. Assert.AreEqual(primRev, m_lslApi.llList2Float(primParams, 10), FLOAT_ACCURACY,
  321. "TestllSetPrimitiveParams " + primTest + " prim revolutions fail");
  322. Assert.AreEqual(primRadius, m_lslApi.llList2Float(primParams, 11), FLOAT_ACCURACY,
  323. "TestllSetPrimitiveParams " + primTest + " prim radius fail");
  324. Assert.AreEqual(primSkew, m_lslApi.llList2Float(primParams, 12), FLOAT_ACCURACY,
  325. "TestllSetPrimitiveParams " + primTest + " prim skew fail");
  326. }
  327. // Set prim params for a sculpted prim and check results.
  328. public void CheckllSetPrimitiveParams(string primTest,
  329. LSL_Types.Vector3 primSize, int primType, string primMap, int primSculptType)
  330. {
  331. // Set the prim params.
  332. m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  333. ScriptBaseClass.PRIM_TYPE, primType, primMap, primSculptType));
  334. // Get params for prim to validate settings.
  335. LSL_Types.list primParams =
  336. m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  337. // Validate settings.
  338. CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
  339. Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
  340. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  341. Assert.AreEqual(primMap, (string)m_lslApi.llList2String(primParams, 2),
  342. "TestllSetPrimitiveParams " + primTest + " prim map check fail");
  343. Assert.AreEqual(primSculptType, m_lslApi.llList2Integer(primParams, 3),
  344. "TestllSetPrimitiveParams " + primTest + " prim type scuplt check fail");
  345. }
  346. public void CheckllSetPrimitiveParamsVector(LSL_Types.Vector3 vecCheck, LSL_Types.Vector3 vecReturned, string msg)
  347. {
  348. // Check each vector component against expected result.
  349. Assert.AreEqual(vecCheck.x, vecReturned.x, VECTOR_COMPONENT_ACCURACY,
  350. "TestllSetPrimitiveParams " + msg + " vector check fail on x component");
  351. Assert.AreEqual(vecCheck.y, vecReturned.y, VECTOR_COMPONENT_ACCURACY,
  352. "TestllSetPrimitiveParams " + msg + " vector check fail on y component");
  353. Assert.AreEqual(vecCheck.z, vecReturned.z, VECTOR_COMPONENT_ACCURACY,
  354. "TestllSetPrimitiveParams " + msg + " vector check fail on z component");
  355. }
  356. [Test]
  357. // llVecNorm test.
  358. public void TestllVecNorm()
  359. {
  360. // Check special case for normalizing zero vector.
  361. CheckllVecNorm(new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), new LSL_Types.Vector3(0.0d, 0.0d, 0.0d));
  362. // Check various vectors.
  363. CheckllVecNorm(new LSL_Types.Vector3(10.0d, 25.0d, 0.0d), new LSL_Types.Vector3(0.371391d, 0.928477d, 0.0d));
  364. CheckllVecNorm(new LSL_Types.Vector3(1.0d, 0.0d, 0.0d), new LSL_Types.Vector3(1.0d, 0.0d, 0.0d));
  365. CheckllVecNorm(new LSL_Types.Vector3(-90.0d, 55.0d, 2.0d), new LSL_Types.Vector3(-0.853128d, 0.521356d, 0.018958d));
  366. CheckllVecNorm(new LSL_Types.Vector3(255.0d, 255.0d, 255.0d), new LSL_Types.Vector3(0.577350d, 0.577350d, 0.577350d));
  367. }
  368. public void CheckllVecNorm(LSL_Types.Vector3 vec, LSL_Types.Vector3 vecNormCheck)
  369. {
  370. // Call LSL function to normalize the vector.
  371. LSL_Types.Vector3 vecNorm = m_lslApi.llVecNorm(vec);
  372. // Check each vector component against expected result.
  373. Assert.AreEqual(vecNorm.x, vecNormCheck.x, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on x component");
  374. Assert.AreEqual(vecNorm.y, vecNormCheck.y, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on y component");
  375. Assert.AreEqual(vecNorm.z, vecNormCheck.z, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on z component");
  376. }
  377. }
  378. }