diff options
author | Charles Krinke | 2008-07-19 14:45:10 +0000 |
---|---|---|
committer | Charles Krinke | 2008-07-19 14:45:10 +0000 |
commit | 9ff9279a7cd76a6a5aaf84ef759053d7bde4001a (patch) | |
tree | 3088a04210aabf2ae356ab56363265a55490239a /OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs | |
parent | Update svn properties. Fix some inconsistent newlines. (diff) | |
download | opensim-SC-9ff9279a7cd76a6a5aaf84ef759053d7bde4001a.zip opensim-SC-9ff9279a7cd76a6a5aaf84ef759053d7bde4001a.tar.gz opensim-SC-9ff9279a7cd76a6a5aaf84ef759053d7bde4001a.tar.bz2 opensim-SC-9ff9279a7cd76a6a5aaf84ef759053d7bde4001a.tar.xz |
Mantis#1785. Thank you kindly, Junta_Kohime for a patch that"
llAxes2Rot now implemented. Important note: quaternion <x,y,z,s>
is equal to <-x,-y,-z,-s>. The result may be different from LSL
output, but it is correct. A problem of rounding caused an error
of square rooting of zero as negative number, corrected by squaring
again. Function tested 360° along 3 axes. Vector fwd, left and up
have to be normalized.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index 682d566..40e225d 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs | |||
@@ -423,10 +423,38 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
423 | public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up) | 423 | public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up) |
424 | { | 424 | { |
425 | m_host.AddScriptLPS(1); | 425 | m_host.AddScriptLPS(1); |
426 | NotImplemented("llAxes2Rot"); | 426 | double x,y,z,s; |
427 | return new LSL_Types.Quaternion(); | 427 | int f=0; |
428 | // Important Note: q1=<x,y,z,s> is equal to q2=<-x,-y,-z,-s> | ||
429 | // Computing quaternion x,y,z,s values | ||
430 | x=((fwd.x-left.y-up.z+1)/4); | ||
431 | x*=x; | ||
432 | x=Math.Sqrt(Math.Sqrt(x)); | ||
433 | y=((1-up.z)/2-x*x); | ||
434 | y*=y; | ||
435 | y=Math.Sqrt(Math.Sqrt(y)); | ||
436 | z=((1-left.y)/2-x*x); | ||
437 | z*=z; | ||
438 | z=Math.Sqrt(Math.Sqrt(z)); | ||
439 | s=(1-x*x-y*y-z*z); | ||
440 | s*=s; | ||
441 | s=Math.Sqrt(Math.Sqrt(s)); | ||
442 | |||
443 | // Set f for signs detection | ||
444 | if (fwd.y+left.x >= 0){f+=1;} | ||
445 | if (fwd.z+up.x >= 0){f+=2;} | ||
446 | if (left.z-up.y >= 0){f+=4;} | ||
447 | // Set correct quaternion signs based on f value | ||
448 | if (f==0){x=-x;} | ||
449 | if (f==1){x=-x;y=-y;} | ||
450 | if (f==2){x=-x;z=-z;} | ||
451 | if (f==3){s=-s;} | ||
452 | if (f==4){x=-x;s=-s;} | ||
453 | if (f==5){z=-z;} | ||
454 | if (f==6){y=-y;} | ||
455 | return new LSL_Types.Quaternion(x, y, z, s); | ||
428 | } | 456 | } |
429 | 457 | ||
430 | public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r) | 458 | public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r) |
431 | { | 459 | { |
432 | m_host.AddScriptLPS(1); | 460 | m_host.AddScriptLPS(1); |