aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2010-07-17 00:26:26 +0100
committerDiva Canto2010-07-17 06:02:07 -0700
commit4a898fdf8dfb93e464d677c281e732ac0cc2c469 (patch)
treefea0fec5c60c5fe741f13d8d5ebebefc288a860e /OpenSim/Region
parentFixes mantis #4872. Port for GridInfo was wrong in Robust.HG.ini.example (diff)
downloadopensim-SC_OLD-4a898fdf8dfb93e464d677c281e732ac0cc2c469.zip
opensim-SC_OLD-4a898fdf8dfb93e464d677c281e732ac0cc2c469.tar.gz
opensim-SC_OLD-4a898fdf8dfb93e464d677c281e732ac0cc2c469.tar.bz2
opensim-SC_OLD-4a898fdf8dfb93e464d677c281e732ac0cc2c469.tar.xz
Fix bugs in llRot2Euler()
Applies patch in http://opensimulator.org/mantis/view.php?id=4482. Thanks Micheil Merlin!
Diffstat (limited to 'OpenSim/Region')
-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 c5226ba..41e1a33 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: