Thanks to M. Igarashi and nlin for a patch that improves conformance of the funcion llAxes2Rot()

0.6.2-post-fixes
Dahlia Trimble 2008-12-22 03:08:39 +00:00
parent a973825db6
commit d83d665186
1 changed files with 48 additions and 35 deletions

View File

@ -535,43 +535,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up) public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
double x, y, z, s; double s;
int f = 0; double tr = fwd.x + left.y + up.z + 1.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 (tr >= 1.0)
if (fwd.y + left.x >= 0) { f += 1; } {
if (fwd.z + up.x >= 0) { f += 2; } s = 0.5 / Math.Sqrt(tr);
if (left.z - up.y >= 0) { f += 4; } return new LSL_Rotation(
// Set correct quaternion signs based on f value (left.z - up.y) * s,
if (f == 0) { x = -x; } (up.x - fwd.z) * s,
if (f == 1) { x = -x; y = -y; } (fwd.y - left.x) * s,
if (f == 2) { x = -x; z = -z; } 0.25 / s);
if (f == 3) { s = -s; } }
if (f == 4) { x = -x; s = -s; } else
if (f == 5) { z = -z; } {
if (f == 6) { y = -y; } double max = (left.y > up.z) ? left.y : up.z;
LSL_Rotation result = new LSL_Rotation(x, y, z, s); if (max < fwd.x)
{
// a hack to correct a few questionable angles :( s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
if (llVecDist(llRot2Fwd(result), fwd) > 0.001 || llVecDist(llRot2Left(result), left) > 0.001) double x = s * 0.5;
result.s = -s; s = 0.5 / s;
return new LSL_Rotation(
return result; x,
(fwd.y + left.x) * s,
(up.x + fwd.z) * s,
(left.z - up.y) * s);
}
else if (max == left.y)
{
s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
double y = s * 0.5;
s = 0.5 / s;
return new LSL_Rotation(
(fwd.y + left.x) * s,
y,
(left.z + up.y) * s,
(up.x - fwd.z) * s);
}
else
{
s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
double z = s * 0.5;
s = 0.5 / s;
return new LSL_Rotation(
(up.x + fwd.z) * s,
(left.z + up.y) * s,
z,
(fwd.y - left.x) * s);
}
}
} }
public LSL_Vector llRot2Fwd(LSL_Rotation r) public LSL_Vector llRot2Fwd(LSL_Rotation r)