Fixed a problem of the JS command 'rotationTo' returning an illegal quaternion for some anti-parallel vectors

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4611 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Eric Walch 2011-10-02 08:49:03 +00:00
parent 73079a255d
commit bb0a795fe7

View File

@ -210,7 +210,7 @@ Quaternion quaternion_rotation_between(Vector v0, Vector v1)
{
q = kIdentityQuaternion;
}
// yes, we arrive here for perpendicular vectors. Rotation axis is than undefined, but not rotating is
// We arrive here for antiparalel vectors. Rotation axis is than undefined, but not rotating is
// also wrong. Probably should the calling function exclude this situation. For current
// in-game use of this function would returning (0,1,0,0) be a solution, but generally that is also wrong.
}
@ -223,7 +223,8 @@ Quaternion quaternion_limited_rotation_between(Vector v0, Vector v1, float maxAr
Quaternion q;
OOScalar min_s = 2.0f * cosf(0.5f * maxArc);
OOScalar s = sqrtf((1.0f + v0.x * v1.x + v0.y * v1.y + v0.z * v1.z) * 2.0f);
if (EXPECT(s != 0))
// for some anti paralel vectors, s returns a NaN instead of 0. Testing s > 0 catches both.
if (EXPECT(s > 0.0f))
{
if (s < min_s) // larger angle => smaller cos
{