aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
authorDahlia Trimble2008-07-21 05:34:31 +0000
committerDahlia Trimble2008-07-21 05:34:31 +0000
commit08f3d212ce71de0b3bbedcc57bd6c60644bd445c (patch)
treeb98fc3434938e3a2282512a97fc4dea23dd57e5f /OpenSim/Region/ScriptEngine
parentMantis#1797. Thank you kindly, StrawberryFride for a patch that solves: (diff)
downloadopensim-SC-08f3d212ce71de0b3bbedcc57bd6c60644bd445c.zip
opensim-SC-08f3d212ce71de0b3bbedcc57bd6c60644bd445c.tar.gz
opensim-SC-08f3d212ce71de0b3bbedcc57bd6c60644bd445c.tar.bz2
opensim-SC-08f3d212ce71de0b3bbedcc57bd6c60644bd445c.tar.xz
does some verification of the quaternion returned by llAxes2Rot and modifies the sign of the s term if a discrepency is found. This helps llAxes2Rot more closely match the Linden implementation.
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs51
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs70
2 files changed, 69 insertions, 52 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
index 7745d95..bea805e 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
@@ -427,32 +427,41 @@ namespace OpenSim.Region.ScriptEngine.Common
427 int f=0; 427 int f=0;
428 // Important Note: q1=<x,y,z,s> is equal to q2=<-x,-y,-z,-s> 428 // Important Note: q1=<x,y,z,s> is equal to q2=<-x,-y,-z,-s>
429 // Computing quaternion x,y,z,s values 429 // Computing quaternion x,y,z,s values
430 x=((fwd.x-left.y-up.z+1)/4); 430 x = ((fwd.x - left.y - up.z + 1) / 4);
431 x*=x; 431 x *= x;
432 x=Math.Sqrt(Math.Sqrt(x)); 432 x = Math.Sqrt(Math.Sqrt(x));
433 y=((1-up.z)/2-x*x); 433 y = ((1 - up.z) / 2 - x * x);
434 y*=y; 434 y *= y;
435 y=Math.Sqrt(Math.Sqrt(y)); 435 y = Math.Sqrt(Math.Sqrt(y));
436 z=((1-left.y)/2-x*x); 436 z = ((1 - left.y) / 2 - x * x);
437 z*=z; 437 z *= z;
438 z=Math.Sqrt(Math.Sqrt(z)); 438 z = Math.Sqrt(Math.Sqrt(z));
439 s=(1-x*x-y*y-z*z); 439 s = (1 - x * x - y * y - z * z);
440 s*=s; 440 s *= s;
441 s=Math.Sqrt(Math.Sqrt(s)); 441 s = Math.Sqrt(Math.Sqrt(s));
442 442
443 // Set f for signs detection 443 // Set f for signs detection
444 if (fwd.y+left.x >= 0){f+=1;} 444 if (fwd.y+left.x >= 0){f+=1;}
445 if (fwd.z+up.x >= 0){f+=2;} 445 if (fwd.z+up.x >= 0){f+=2;}
446 if (left.z-up.y >= 0){f+=4;} 446 if (left.z-up.y >= 0){f+=4;}
447 // Set correct quaternion signs based on f value 447 // Set correct quaternion signs based on f value
448 if (f==0){x=-x;} 448 if (f == 0) { x = -x; }
449 if (f==1){x=-x;y=-y;} 449 if (f == 1) { x = -x; y = -y; }
450 if (f==2){x=-x;z=-z;} 450 if (f == 2) { x = -x; z = -z; }
451 if (f==3){s=-s;} 451 if (f == 3) { s = -s; }
452 if (f==4){x=-x;s=-s;} 452 if (f == 4) { x = -x; s = -s; }
453 if (f==5){z=-z;} 453 if (f == 5) { z = -z; }
454 if (f==6){y=-y;} 454 if (f == 6) { y = -y; }
455 return new LSL_Types.Quaternion(x, y, z, s); 455
456 LSL_Types.Quaternion result = new LSL_Types.Quaternion(x, y, z, s);
457
458 // a hack to correct a few questionable angles :(
459 LSL_Types.Vector3 fwdTest = new LSL_Types.Vector3(1, 0, 0);
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;
463
464 return result;
456 } 465 }
457 466
458 public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r) 467 public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 79bd6fe..9b860f5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -406,41 +406,49 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
406 406
407 return new LSL_Types.Quaternion(x, y, z, s); 407 return new LSL_Types.Quaternion(x, y, z, s);
408 } 408 }
409 409
410 public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up) 410 public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up)
411 { 411 {
412 m_host.AddScriptLPS(1); 412 m_host.AddScriptLPS(1);
413 double x,y,z,s; 413 double x, y, z, s;
414 int f=0; 414 int f = 0;
415 // Important Note: q1=<x,y,z,s> is equal to q2=<-x,-y,-z,-s> 415 // Important Note: q1=<x,y,z,s> is equal to q2=<-x,-y,-z,-s>
416 // Computing quaternion x,y,z,s values 416 // Computing quaternion x,y,z,s values
417 x=((fwd.x-left.y-up.z+1)/4); 417 x = ((fwd.x - left.y - up.z + 1) / 4);
418 x*=x; 418 x *= x;
419 x=Math.Sqrt(Math.Sqrt(x)); 419 x = Math.Sqrt(Math.Sqrt(x));
420 y=((1-up.z)/2-x*x); 420 y = ((1 - up.z) / 2 - x * x);
421 y*=y; 421 y *= y;
422 y=Math.Sqrt(Math.Sqrt(y)); 422 y = Math.Sqrt(Math.Sqrt(y));
423 z=((1-left.y)/2-x*x); 423 z = ((1 - left.y) / 2 - x * x);
424 z*=z; 424 z *= z;
425 z=Math.Sqrt(Math.Sqrt(z)); 425 z = Math.Sqrt(Math.Sqrt(z));
426 s=(1-x*x-y*y-z*z); 426 s = (1 - x * x - y * y - z * z);
427 s*=s; 427 s *= s;
428 s=Math.Sqrt(Math.Sqrt(s)); 428 s = Math.Sqrt(Math.Sqrt(s));
429 429
430 // Set f for signs detection 430 // Set f for signs detection
431 if (fwd.y+left.x >= 0){f+=1;} 431 if (fwd.y + left.x >= 0) { f += 1; }
432 if (fwd.z+up.x >= 0){f+=2;} 432 if (fwd.z + up.x >= 0) { f += 2; }
433 if (left.z-up.y >= 0){f+=4;} 433 if (left.z - up.y >= 0) { f += 4; }
434 // Set correct quaternion signs based on f value 434 // Set correct quaternion signs based on f value
435 if (f==0){x=-x;} 435 if (f == 0) { x = -x; }
436 if (f==1){x=-x;y=-y;} 436 if (f == 1) { x = -x; y = -y; }
437 if (f==2){x=-x;z=-z;} 437 if (f == 2) { x = -x; z = -z; }
438 if (f==3){s=-s;} 438 if (f == 3) { s = -s; }
439 if (f==4){x=-x;s=-s;} 439 if (f == 4) { x = -x; s = -s; }
440 if (f==5){z=-z;} 440 if (f == 5) { z = -z; }
441 if (f==6){y=-y;} 441 if (f == 6) { y = -y; }
442 return new LSL_Types.Quaternion(x, y, z, s); 442
443 LSL_Types.Quaternion result = new LSL_Types.Quaternion(x, y, z, s);
444
445 // a hack to correct a few questionable angles :(
446 LSL_Types.Vector3 fwdTest = new LSL_Types.Vector3(1, 0, 0);
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;
443 450
451 return result;
444 } 452 }
445 453
446 public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r) 454 public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)