aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDahlia Trimble2008-07-21 09:36:22 +0000
committerDahlia Trimble2008-07-21 09:36:22 +0000
commitce90e2ecce1426cfcb991848d5214a53833e9f8e (patch)
tree00735d38e8ce085ea1a36f41405372421dcac98a
parentdoes some verification of the quaternion returned by llAxes2Rot and modifies ... (diff)
downloadopensim-SC-ce90e2ecce1426cfcb991848d5214a53833e9f8e.zip
opensim-SC-ce90e2ecce1426cfcb991848d5214a53833e9f8e.tar.gz
opensim-SC-ce90e2ecce1426cfcb991848d5214a53833e9f8e.tar.bz2
opensim-SC-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.
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs87
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs84
2 files changed, 98 insertions, 73 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
index bea805e..68e7425 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
@@ -456,72 +456,84 @@ namespace OpenSim.Region.ScriptEngine.Common
456 LSL_Types.Quaternion result = new LSL_Types.Quaternion(x, y, z, s); 456 LSL_Types.Quaternion result = new LSL_Types.Quaternion(x, y, z, s);
457 457
458 // a hack to correct a few questionable angles :( 458 // a hack to correct a few questionable angles :(
459 LSL_Types.Vector3 fwdTest = new LSL_Types.Vector3(1, 0, 0); 459 if (llVecDist(llRot2Fwd(result), fwd) > 0.001 || llVecDist(llRot2Left(result), left) > 0.001)
460 LSL_Types.Vector3 leftTest = new LSL_Types.Vector3(0, 1, 0);
461 if (llVecDist(fwdTest * result, fwd) > 0.001 || llVecDist(leftTest * result, left) > 0.001)
462 result.s = -s; 460 result.s = -s;
463 461
464 return result; 462 return result;
465 } 463 }
466 464
467 public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r) 465 public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
468 { 466 {
469 m_host.AddScriptLPS(1); 467 m_host.AddScriptLPS(1);
470 double x,y,z,m; 468
471 m = Math.Sqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.s*r.s); 469 double x, y, z, m;
470
471 m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
472 // m is always greater than zero 472 // m is always greater than zero
473 if (m!=1) // if m is not equal to 1 then Rotation needs to be normalized 473 // if m is not equal to 1 then Rotation needs to be normalized
474 if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
474 { 475 {
475 r.x/=m; 476 m = 1.0 / Math.Sqrt(m);
476 r.y/=m; 477 r.x *= m;
477 r.z/=m; 478 r.y *= m;
478 r.s/=m; 479 r.z *= m;
480 r.s *= m;
479 } 481 }
482
480 // Fast Algebric Calculations instead of Vectors & Quaternions Product 483 // Fast Algebric Calculations instead of Vectors & Quaternions Product
481 x = r.x*r.x-r.y*r.y-r.z*r.z+r.s*r.s; 484 x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
482 y = 2*(r.x*r.y+r.z*r.s); 485 y = 2 * (r.x * r.y + r.z * r.s);
483 z = 2*(r.x*r.z-r.y*r.s); 486 z = 2 * (r.x * r.z - r.y * r.s);
484 return (new LSL_Types.Vector3(x,y,z)); 487 return (new LSL_Types.Vector3(x, y, z));
485 } 488 }
486 489
487 public LSL_Types.Vector3 llRot2Left(LSL_Types.Quaternion r) 490 public LSL_Types.Vector3 llRot2Left(LSL_Types.Quaternion r)
488 { 491 {
489 m_host.AddScriptLPS(1); 492 m_host.AddScriptLPS(1);
490 double x,y,z,m; 493
491 m = Math.Sqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.s*r.s); 494 double x, y, z, m;
495
496 m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
492 // m is always greater than zero 497 // m is always greater than zero
493 if (m!=1) // if m is not equal to 1 then Rotation needs to be normalized 498 // if m is not equal to 1 then Rotation needs to be normalized
499 if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
494 { 500 {
495 r.x/=m; 501 m = 1.0 / Math.Sqrt(m);
496 r.y/=m; 502 r.x *= m;
497 r.z/=m; 503 r.y *= m;
498 r.s/=m; 504 r.z *= m;
505 r.s *= m;
499 } 506 }
507
500 // Fast Algebric Calculations instead of Vectors & Quaternions Product 508 // Fast Algebric Calculations instead of Vectors & Quaternions Product
501 x = 2*(r.x*r.y-r.z*r.s); 509 x = 2 * (r.x * r.y - r.z * r.s);
502 y = -r.x*r.x+r.y*r.y-r.z*r.z+r.s*r.s; 510 y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
503 z = 2*(r.x*r.s+r.y*r.z); 511 z = 2 * (r.x * r.s + r.y * r.z);
504 return (new LSL_Types.Vector3(x,y,z)); 512 return (new LSL_Types.Vector3(x, y, z));
505 } 513 }
506 514
507 public LSL_Types.Vector3 llRot2Up(LSL_Types.Quaternion r) 515 public LSL_Types.Vector3 llRot2Up(LSL_Types.Quaternion r)
508 { 516 {
509 m_host.AddScriptLPS(1); 517 m_host.AddScriptLPS(1);
510 double x,y,z,m; 518 double x, y, z, m;
511 m = Math.Sqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.s*r.s); 519
520 m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
512 // m is always greater than zero 521 // m is always greater than zero
513 if (m!=1) // if m is not equal to 1 then Rotation needs to be normalized 522 // if m is not equal to 1 then Rotation needs to be normalized
523 if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
514 { 524 {
515 r.x/=m; 525 m = 1.0 / Math.Sqrt(m);
516 r.y/=m; 526 r.x *= m;
517 r.z/=m; 527 r.y *= m;
518 r.s/=m; 528 r.z *= m;
529 r.s *= m;
519 } 530 }
531
520 // Fast Algebric Calculations instead of Vectors & Quaternions Product 532 // Fast Algebric Calculations instead of Vectors & Quaternions Product
521 x = 2*(r.x*r.z+r.y*r.s); 533 x = 2 * (r.x * r.z + r.y * r.s);
522 y = 2*(-r.x*r.s+r.y*r.z); 534 y = 2*(-r.x * r.s + r.y * r.z);
523 z = -r.x*r.x-r.y*r.y+r.z*r.z+r.s*r.s; 535 z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
524 return (new LSL_Types.Vector3(x,y,z)); 536 return (new LSL_Types.Vector3(x, y, z));
525 } 537 }
526 538
527 public LSL_Types.Quaternion llRotBetween(LSL_Types.Vector3 a, LSL_Types.Vector3 b) 539 public LSL_Types.Quaternion llRotBetween(LSL_Types.Vector3 a, LSL_Types.Vector3 b)
@@ -537,6 +549,7 @@ namespace OpenSim.Region.ScriptEngine.Common
537 549
538 return new LSL_Types.Quaternion(axis.x * s, axis.y * s, axis.z * s, (float)Math.Cos(angle / 2)); 550 return new LSL_Types.Quaternion(axis.x * s, axis.y * s, axis.z * s, (float)Math.Cos(angle / 2));
539 } 551 }
552
540 public void llWhisper(int channelID, string text) 553 public void llWhisper(int channelID, string text)
541 { 554 {
542 m_host.AddScriptLPS(1); 555 m_host.AddScriptLPS(1);
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)