Add script instruction count back to llRot2Euler. Other minor formatting/doc changes.
parent
eb9bf71726
commit
8c445dac67
|
@ -468,10 +468,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
|
|
||||||
//Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
|
//Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
|
||||||
|
|
||||||
// Using algorithm based off http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/quat_2_euler_paper_ver2-1.pdf
|
/// <summary>
|
||||||
// to avoid issues with singularity and rounding with Y rotation of +/- PI/2
|
/// Convert an LSL rotation to a Euler vector.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Using algorithm based off http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/quat_2_euler_paper_ver2-1.pdf
|
||||||
|
/// to avoid issues with singularity and rounding with Y rotation of +/- PI/2
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="r"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public LSL_Vector llRot2Euler(LSL_Rotation r)
|
public LSL_Vector llRot2Euler(LSL_Rotation r)
|
||||||
{
|
{
|
||||||
|
m_host.AddScriptLPS(1);
|
||||||
|
|
||||||
LSL_Vector v = new LSL_Vector(0.0, 0.0, 1.0) * r; // Z axis unit vector unaffected by Z rotation component of r.
|
LSL_Vector v = new LSL_Vector(0.0, 0.0, 1.0) * r; // Z axis unit vector unaffected by Z rotation component of r.
|
||||||
double m = LSL_Vector.Mag(v); // Just in case v isn't normalized, need magnitude for Asin() operation later.
|
double m = LSL_Vector.Mag(v); // Just in case v isn't normalized, need magnitude for Asin() operation later.
|
||||||
if (m == 0.0) return new LSL_Vector();
|
if (m == 0.0) return new LSL_Vector();
|
||||||
|
@ -482,6 +491,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
// Rotate X axis unit vector by r and unwind the X and Y rotations leaving only the Z rotation
|
// Rotate X axis unit vector by r and unwind the X and Y rotations leaving only the Z rotation
|
||||||
v = new LSL_Vector(1.0, 0.0, 0.0) * ((r * new LSL_Rotation(Math.Sin(-x / 2.0), 0.0, 0.0, Math.Cos(-x / 2.0))) * new LSL_Rotation(0.0, Math.Sin(-y / 2.0), 0.0, Math.Cos(-y / 2.0)));
|
v = new LSL_Vector(1.0, 0.0, 0.0) * ((r * new LSL_Rotation(Math.Sin(-x / 2.0), 0.0, 0.0, Math.Cos(-x / 2.0))) * new LSL_Rotation(0.0, Math.Sin(-y / 2.0), 0.0, Math.Cos(-y / 2.0)));
|
||||||
double z = Math.Atan2(v.y, v.x);
|
double z = Math.Atan2(v.y, v.x);
|
||||||
|
|
||||||
return new LSL_Vector(x, y, z);
|
return new LSL_Vector(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,20 +201,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
|
||||||
CheckllRot2Euler(new LSL_Types.Quaternion(-0.092302, -0.701059, -0.092302, -0.701059));
|
CheckllRot2Euler(new LSL_Types.Quaternion(-0.092302, -0.701059, -0.092302, -0.701059));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing Rot2Euler this way instead of comparing against expected angles because
|
/// <summary>
|
||||||
// 1. There are several ways to get to the original Quaternion. For example a rotation
|
/// Check an llRot2Euler conversion.
|
||||||
// of PI and -PI will give the same result. But PI and -PI aren't equal.
|
/// </summary>
|
||||||
// 2. This method checks to see if the calculated angles from a quaternion can be used
|
/// <remarks>
|
||||||
// to create a new quaternion to produce the same rotation.
|
/// Testing Rot2Euler this way instead of comparing against expected angles because
|
||||||
// However, can't compare the newly calculated quaternion against the original because
|
/// 1. There are several ways to get to the original Quaternion. For example a rotation
|
||||||
// once again, there are multiple quaternions that give the same result. For instance
|
/// of PI and -PI will give the same result. But PI and -PI aren't equal.
|
||||||
// <X, Y, Z, S> == <-X, -Y, -Z, -S>. Additionally, the magnitude of S can be changed
|
/// 2. This method checks to see if the calculated angles from a quaternion can be used
|
||||||
// and will still result in the same rotation if the values for X, Y, Z are also changed
|
/// to create a new quaternion to produce the same rotation.
|
||||||
// to compensate.
|
/// However, can't compare the newly calculated quaternion against the original because
|
||||||
// However, if two quaternions represent the same rotation, then multiplying the first
|
/// once again, there are multiple quaternions that give the same result. For instance
|
||||||
// quaternion by the conjugate of the second, will give a third quaternion representing
|
/// <X, Y, Z, S> == <-X, -Y, -Z, -S>. Additionally, the magnitude of S can be changed
|
||||||
// a zero rotation. This can be tested for by looking at the X, Y, Z values which should
|
/// and will still result in the same rotation if the values for X, Y, Z are also changed
|
||||||
// be zero.
|
/// to compensate.
|
||||||
|
/// However, if two quaternions represent the same rotation, then multiplying the first
|
||||||
|
/// quaternion by the conjugate of the second, will give a third quaternion representing
|
||||||
|
/// a zero rotation. This can be tested for by looking at the X, Y, Z values which should
|
||||||
|
/// be zero.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="rot"></param>
|
||||||
private void CheckllRot2Euler(LSL_Types.Quaternion rot)
|
private void CheckllRot2Euler(LSL_Types.Quaternion rot)
|
||||||
{
|
{
|
||||||
// Call LSL function to convert quaternion rotaion to euler radians.
|
// Call LSL function to convert quaternion rotaion to euler radians.
|
||||||
|
|
Loading…
Reference in New Issue