aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJohn Cochran2012-01-05 07:37:08 -0600
committerJustin Clark-Casey (justincc)2012-01-06 21:14:42 +0000
commitff5a83d192105e4674cff261b13a447ff0d1e478 (patch)
treefe81ac25a73ca3e26ae2f1e4225dd17d9c5d8753 /OpenSim
parentAdd script instruction count back to llRot2Euler. Other minor formatting/doc... (diff)
downloadopensim-SC-ff5a83d192105e4674cff261b13a447ff0d1e478.zip
opensim-SC-ff5a83d192105e4674cff261b13a447ff0d1e478.tar.gz
opensim-SC-ff5a83d192105e4674cff261b13a447ff0d1e478.tar.bz2
opensim-SC-ff5a83d192105e4674cff261b13a447ff0d1e478.tar.xz
Fixed llAngleBetween() to allow denormal rotations
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs14
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs47
2 files changed, 41 insertions, 20 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index a35e75f..d6de39f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -4698,15 +4698,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4698 return (double)Math.Asin(val); 4698 return (double)Math.Asin(val);
4699 } 4699 }
4700 4700
4701 // Xantor 30/apr/2008 4701 // jcochran 5/jan/2012
4702 public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b) 4702 public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
4703 { 4703 {
4704 m_host.AddScriptLPS(1); 4704 m_host.AddScriptLPS(1);
4705 4705
4706 double angle = Math.Acos(a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s) * 2; 4706 double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s);
4707 if (angle < 0) angle = -angle; 4707 double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s);
4708 if (angle > Math.PI) return (Math.PI * 2 - angle); 4708 double aa_bb = aa * bb;
4709 return angle; 4709 if (aa_bb == 0) return 0.0;
4710 double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s);
4711 double quotient = (ab * ab) / aa_bb;
4712 if (quotient >= 1.0) return 0.0;
4713 return Math.Acos(2 * quotient - 1);
4710 } 4714 }
4711 4715
4712 public LSL_String llGetInventoryKey(string name) 4716 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 99c1cf4..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