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.
parent
bedd28e02e
commit
08f3d212ce
|
@ -427,32 +427,41 @@ namespace OpenSim.Region.ScriptEngine.Common
|
|||
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));
|
||||
|
||||
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);
|
||||
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; }
|
||||
|
||||
LSL_Types.Quaternion result = new LSL_Types.Quaternion(x, y, z, s);
|
||||
|
||||
// a hack to correct a few questionable angles :(
|
||||
LSL_Types.Vector3 fwdTest = new LSL_Types.Vector3(1, 0, 0);
|
||||
LSL_Types.Vector3 leftTest = new LSL_Types.Vector3(0, 1, 0);
|
||||
if (llVecDist(fwdTest * result, fwd) > 0.001 || llVecDist(leftTest * result, left) > 0.001)
|
||||
result.s = -s;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
|
||||
|
|
|
@ -406,41 +406,49 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
|
||||
return new LSL_Types.Quaternion(x, y, z, s);
|
||||
}
|
||||
|
||||
|
||||
public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up)
|
||||
{
|
||||
m_host.AddScriptLPS(1);
|
||||
double x,y,z,s;
|
||||
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);
|
||||
double x, y, z, s;
|
||||
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; }
|
||||
|
||||
LSL_Types.Quaternion result = new LSL_Types.Quaternion(x, y, z, s);
|
||||
|
||||
// a hack to correct a few questionable angles :(
|
||||
LSL_Types.Vector3 fwdTest = new LSL_Types.Vector3(1, 0, 0);
|
||||
LSL_Types.Vector3 leftTest = new LSL_Types.Vector3(0, 1, 0);
|
||||
if (llVecDist(fwdTest * result, fwd) > 0.001 || llVecDist(leftTest * result, left) > 0.001)
|
||||
result.s = -s;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
|
||||
|
|
Loading…
Reference in New Issue