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.0.6.0-stable
parent
19fd2230bf
commit
9ff9279a7c
|
@ -423,8 +423,36 @@ namespace OpenSim.Region.ScriptEngine.Common
|
||||||
public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up)
|
public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up)
|
||||||
{
|
{
|
||||||
m_host.AddScriptLPS(1);
|
m_host.AddScriptLPS(1);
|
||||||
NotImplemented("llAxes2Rot");
|
double x,y,z,s;
|
||||||
return new LSL_Types.Quaternion();
|
int f=0;
|
||||||
|
// Important Note: q1=<x,y,z,s> is equal to q2=<-x,-y,-z,-s>
|
||||||
|
// Computing quaternion x,y,z,s values
|
||||||
|
x=((fwd.x-left.y-up.z+1)/4);
|
||||||
|
x*=x;
|
||||||
|
x=Math.Sqrt(Math.Sqrt(x));
|
||||||
|
y=((1-up.z)/2-x*x);
|
||||||
|
y*=y;
|
||||||
|
y=Math.Sqrt(Math.Sqrt(y));
|
||||||
|
z=((1-left.y)/2-x*x);
|
||||||
|
z*=z;
|
||||||
|
z=Math.Sqrt(Math.Sqrt(z));
|
||||||
|
s=(1-x*x-y*y-z*z);
|
||||||
|
s*=s;
|
||||||
|
s=Math.Sqrt(Math.Sqrt(s));
|
||||||
|
|
||||||
|
// Set f for signs detection
|
||||||
|
if (fwd.y+left.x >= 0){f+=1;}
|
||||||
|
if (fwd.z+up.x >= 0){f+=2;}
|
||||||
|
if (left.z-up.y >= 0){f+=4;}
|
||||||
|
// Set correct quaternion signs based on f value
|
||||||
|
if (f==0){x=-x;}
|
||||||
|
if (f==1){x=-x;y=-y;}
|
||||||
|
if (f==2){x=-x;z=-z;}
|
||||||
|
if (f==3){s=-s;}
|
||||||
|
if (f==4){x=-x;s=-s;}
|
||||||
|
if (f==5){z=-z;}
|
||||||
|
if (f==6){y=-y;}
|
||||||
|
return new LSL_Types.Quaternion(x, y, z, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
|
public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
|
||||||
|
|
|
@ -410,8 +410,37 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up)
|
public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up)
|
||||||
{
|
{
|
||||||
m_host.AddScriptLPS(1);
|
m_host.AddScriptLPS(1);
|
||||||
NotImplemented("llAxes2Rot");
|
double x,y,z,s;
|
||||||
return new LSL_Types.Quaternion();
|
int f=0;
|
||||||
|
// Important Note: q1=<x,y,z,s> is equal to q2=<-x,-y,-z,-s>
|
||||||
|
// Computing quaternion x,y,z,s values
|
||||||
|
x=((fwd.x-left.y-up.z+1)/4);
|
||||||
|
x*=x;
|
||||||
|
x=Math.Sqrt(Math.Sqrt(x));
|
||||||
|
y=((1-up.z)/2-x*x);
|
||||||
|
y*=y;
|
||||||
|
y=Math.Sqrt(Math.Sqrt(y));
|
||||||
|
z=((1-left.y)/2-x*x);
|
||||||
|
z*=z;
|
||||||
|
z=Math.Sqrt(Math.Sqrt(z));
|
||||||
|
s=(1-x*x-y*y-z*z);
|
||||||
|
s*=s;
|
||||||
|
s=Math.Sqrt(Math.Sqrt(s));
|
||||||
|
|
||||||
|
// Set f for signs detection
|
||||||
|
if (fwd.y+left.x >= 0){f+=1;}
|
||||||
|
if (fwd.z+up.x >= 0){f+=2;}
|
||||||
|
if (left.z-up.y >= 0){f+=4;}
|
||||||
|
// Set correct quaternion signs based on f value
|
||||||
|
if (f==0){x=-x;}
|
||||||
|
if (f==1){x=-x;y=-y;}
|
||||||
|
if (f==2){x=-x;z=-z;}
|
||||||
|
if (f==3){s=-s;}
|
||||||
|
if (f==4){x=-x;s=-s;}
|
||||||
|
if (f==5){z=-z;}
|
||||||
|
if (f==6){y=-y;}
|
||||||
|
return new LSL_Types.Quaternion(x, y, z, s);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
|
public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
|
||||||
|
|
Loading…
Reference in New Issue