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