aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2010-07-17 00:26:26 +0100
committerJustin Clark-Casey (justincc)2010-07-17 00:26:26 +0100
commitf5bdf0d9b9538b9f2ac612fcb8bce4442794fb4d (patch)
tree033a046d7c98c00df8e9464aba8f85edf22b8e9d
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-f5bdf0d9b9538b9f2ac612fcb8bce4442794fb4d.zip
opensim-SC_OLD-f5bdf0d9b9538b9f2ac612fcb8bce4442794fb4d.tar.gz
opensim-SC_OLD-f5bdf0d9b9538b9f2ac612fcb8bce4442794fb4d.tar.bz2
opensim-SC_OLD-f5bdf0d9b9538b9f2ac612fcb8bce4442794fb4d.tar.xz
Fix bugs in llRot2Euler()
Applies patch in http://opensimulator.org/mantis/view.php?id=4482. Thanks Micheil Merlin!
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs28
1 files changed, 7 insertions, 21 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index dbea6ef..789bbb2 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -465,22 +465,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
465 465
466 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke 466 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
467 467
468 // Utility function for llRot2Euler 468 // Old implementation of llRot2Euler. Normalization not required as Atan2 function will
469 469 // only return values >= -PI (-180 degrees) and <= PI (180 degrees).
470 // normalize an angle between -PI and PI (-180 to +180 degrees)
471 protected double NormalizeAngle(double angle)
472 {
473 if (angle > -Math.PI && angle < Math.PI)
474 return angle;
475
476 int numPis = (int)(Math.PI / angle);
477 double remainder = angle - Math.PI * numPis;
478 if (numPis % 2 == 1)
479 return Math.PI - angle;
480 return remainder;
481 }
482
483 // Old implementation of llRot2Euler, now normalized
484 470
485 public LSL_Vector llRot2Euler(LSL_Rotation r) 471 public LSL_Vector llRot2Euler(LSL_Rotation r)
486 { 472 {
@@ -492,13 +478,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
492 double n = 2 * (r.y * r.s + r.x * r.z); 478 double n = 2 * (r.y * r.s + r.x * r.z);
493 double p = m * m - n * n; 479 double p = m * m - n * n;
494 if (p > 0) 480 if (p > 0)
495 return new LSL_Vector(NormalizeAngle(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s))), 481 return new LSL_Vector(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s)),
496 NormalizeAngle(Math.Atan2(n, Math.Sqrt(p))), 482 Math.Atan2(n, Math.Sqrt(p)),
497 NormalizeAngle(Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s)))); 483 Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s)));
498 else if (n > 0) 484 else if (n > 0)
499 return new LSL_Vector(0.0, Math.PI * 0.5, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z))); 485 return new LSL_Vector(0.0, Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
500 else 486 else
501 return new LSL_Vector(0.0, -Math.PI * 0.5, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z))); 487 return new LSL_Vector(0.0, -Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
502 } 488 }
503 489
504 /* From wiki: 490 /* From wiki: