aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
authorDahlia Trimble2008-07-21 09:36:22 +0000
committerDahlia Trimble2008-07-21 09:36:22 +0000
commitce90e2ecce1426cfcb991848d5214a53833e9f8e (patch)
tree00735d38e8ce085ea1a36f41405372421dcac98a /OpenSim/Region/ScriptEngine/Shared
parentdoes some verification of the quaternion returned by llAxes2Rot and modifies ... (diff)
downloadopensim-SC_OLD-ce90e2ecce1426cfcb991848d5214a53833e9f8e.zip
opensim-SC_OLD-ce90e2ecce1426cfcb991848d5214a53833e9f8e.tar.gz
opensim-SC_OLD-ce90e2ecce1426cfcb991848d5214a53833e9f8e.tar.bz2
opensim-SC_OLD-ce90e2ecce1426cfcb991848d5214a53833e9f8e.tar.xz
some optimizations in quaternion normalization in llRot2Fwd, llRot2Left, and llRot2Up. llAxes2Rot now uses these functions for sign error correction instead of vector*quat products.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs84
1 files changed, 48 insertions, 36 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 9b860f5..f3e9b09 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -443,9 +443,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
443 LSL_Types.Quaternion result = new LSL_Types.Quaternion(x, y, z, s); 443 LSL_Types.Quaternion result = new LSL_Types.Quaternion(x, y, z, s);
444 444
445 // a hack to correct a few questionable angles :( 445 // a hack to correct a few questionable angles :(
446 LSL_Types.Vector3 fwdTest = new LSL_Types.Vector3(1, 0, 0); 446 if (llVecDist(llRot2Fwd(result), fwd) > 0.001 || llVecDist(llRot2Left(result), left) > 0.001)
447 LSL_Types.Vector3 leftTest = new LSL_Types.Vector3(0, 1, 0);
448 if (llVecDist(fwdTest * result, fwd) > 0.001 || llVecDist(leftTest * result, left) > 0.001)
449 result.s = -s; 447 result.s = -s;
450 448
451 return result; 449 return result;
@@ -454,61 +452,75 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
454 public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r) 452 public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
455 { 453 {
456 m_host.AddScriptLPS(1); 454 m_host.AddScriptLPS(1);
457 double x,y,z,m; 455
458 m = Math.Sqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.s*r.s); 456 double x, y, z, m;
457
458 m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
459 // m is always greater than zero 459 // m is always greater than zero
460 if (m!=1) // if m is not equal to 1 then Rotation needs to be normalized 460 // if m is not equal to 1 then Rotation needs to be normalized
461 if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
461 { 462 {
462 r.x/=m; 463 m = 1.0 / Math.Sqrt(m);
463 r.y/=m; 464 r.x *= m;
464 r.z/=m; 465 r.y *= m;
465 r.s/=m; 466 r.z *= m;
467 r.s *= m;
466 } 468 }
469
467 // Fast Algebric Calculations instead of Vectors & Quaternions Product 470 // Fast Algebric Calculations instead of Vectors & Quaternions Product
468 x = r.x*r.x-r.y*r.y-r.z*r.z+r.s*r.s; 471 x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
469 y = 2*(r.x*r.y+r.z*r.s); 472 y = 2 * (r.x * r.y + r.z * r.s);
470 z = 2*(r.x*r.z-r.y*r.s); 473 z = 2 * (r.x * r.z - r.y * r.s);
471 return (new LSL_Types.Vector3(x,y,z)); 474 return (new LSL_Types.Vector3(x, y, z));
472 } 475 }
473 476
474 public LSL_Types.Vector3 llRot2Left(LSL_Types.Quaternion r) 477 public LSL_Types.Vector3 llRot2Left(LSL_Types.Quaternion r)
475 { 478 {
476 m_host.AddScriptLPS(1); 479 m_host.AddScriptLPS(1);
477 double x,y,z,m; 480
478 m = Math.Sqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.s*r.s); 481 double x, y, z, m;
482
483 m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
479 // m is always greater than zero 484 // m is always greater than zero
480 if (m!=1) // if m is not equal to 1 then Rotation needs to be normalized 485 // if m is not equal to 1 then Rotation needs to be normalized
486 if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
481 { 487 {
482 r.x/=m; 488 m = 1.0 / Math.Sqrt(m);
483 r.y/=m; 489 r.x *= m;
484 r.z/=m; 490 r.y *= m;
485 r.s/=m; 491 r.z *= m;
492 r.s *= m;
486 } 493 }
494
487 // Fast Algebric Calculations instead of Vectors & Quaternions Product 495 // Fast Algebric Calculations instead of Vectors & Quaternions Product
488 x = 2*(r.x*r.y-r.z*r.s); 496 x = 2 * (r.x * r.y - r.z * r.s);
489 y = -r.x*r.x+r.y*r.y-r.z*r.z+r.s*r.s; 497 y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
490 z = 2*(r.x*r.s+r.y*r.z); 498 z = 2 * (r.x * r.s + r.y * r.z);
491 return (new LSL_Types.Vector3(x,y,z)); 499 return (new LSL_Types.Vector3(x, y, z));
492 } 500 }
493 501
494 public LSL_Types.Vector3 llRot2Up(LSL_Types.Quaternion r) 502 public LSL_Types.Vector3 llRot2Up(LSL_Types.Quaternion r)
495 { 503 {
496 m_host.AddScriptLPS(1); 504 m_host.AddScriptLPS(1);
497 double x,y,z,m; 505 double x, y, z, m;
498 m = Math.Sqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.s*r.s); 506
507 m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
499 // m is always greater than zero 508 // m is always greater than zero
500 if (m!=1) // if m is not equal to 1 then Rotation needs to be normalized 509 // if m is not equal to 1 then Rotation needs to be normalized
510 if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
501 { 511 {
502 r.x/=m; 512 m = 1.0 / Math.Sqrt(m);
503 r.y/=m; 513 r.x *= m;
504 r.z/=m; 514 r.y *= m;
505 r.s/=m; 515 r.z *= m;
516 r.s *= m;
506 } 517 }
518
507 // Fast Algebric Calculations instead of Vectors & Quaternions Product 519 // Fast Algebric Calculations instead of Vectors & Quaternions Product
508 x = 2*(r.x*r.z+r.y*r.s); 520 x = 2 * (r.x * r.z + r.y * r.s);
509 y = 2*(-r.x*r.s+r.y*r.z); 521 y = 2 * (-r.x * r.s + r.y * r.z);
510 z = -r.x*r.x-r.y*r.y+r.z*r.z+r.s*r.s; 522 z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
511 return (new LSL_Types.Vector3(x,y,z)); 523 return (new LSL_Types.Vector3(x, y, z));
512 } 524 }
513 525
514 public LSL_Types.Quaternion llRotBetween(LSL_Types.Vector3 a, LSL_Types.Vector3 b) 526 public LSL_Types.Quaternion llRotBetween(LSL_Types.Vector3 a, LSL_Types.Vector3 b)