harrison-lucas / bullet

Automatically exported from code.google.com/p/bullet
Other
0 stars 0 forks source link

btQuaternion slerp() creates NaN in single pression #686

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
File src/LinearMath/btQuaternion.h

If quaternion are close and "product" is for eg. 1.000000001(not exactly 1) it 
pass first condition, BUT "theta" is zero, so after division by "btSin(theta)", 
then "d" is NaN.

Solution:

btQuaternion slerp(const btQuaternion& q, const btScalar& t) const
{
    btScalar magnitude = btSqrt(length2() * q.length2()); 
    btAssert(magnitude > btScalar(0));

    btScalar product = dot(q) / magnitude;
    if(btFabs(product) != btScalar(1))
    {
        // Take care of long angle case see http://en.wikipedia.org/wiki/Slerp
        const btScalar sign = (product < 0) ? btScalar(-1) : btScalar(1);
        const btScalar theta = btAcos(sign * product);
        const btScalar sinTheta = btSin(theta);
        if(sinTheta)                
        {
            const btScalar s1 = btSin(sign * t * theta); 
            const btScalar d = btScalar(1.0) / sinTheta;
            const btScalar s0 = btSin((btScalar(1.0) - t) * theta);

            return btQuaternion(
            (m_floats[0] * s0 + q.x() * s1) * d,
            (m_floats[1] * s0 + q.y() * s1) * d,
            (m_floats[2] * s0 + q.z() * s1) * d,
            (m_floats[3] * s0 + q.m_floats[3] * s1) * d);
        }
        else
            return *this;
    }
    else
        return *this;
}

Original issue reported on code.google.com by MilanSu...@gmail.com on 3 Jan 2013 at 3:07

GoogleCodeExporter commented 9 years ago
This issue should have been solved in a recent commit:
https://code.google.com/p/bullet/source/detail?r=2623

Can you re-open an issue if there are still issues with current trunk?
Thanks!
Erwin

Original comment by erwin.coumans on 3 Jan 2013 at 6:46

GoogleCodeExporter commented 9 years ago
yes, It`s working fine! Sorry for duplication.
Milan

Original comment by MilanSu...@gmail.com on 3 Jan 2013 at 10:26