aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs87
1 files changed, 50 insertions, 37 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);