Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 27, 2011, 7:43:24 AM (14 years ago)
Author:
rgrieder
Message:

Updated Bullet Physics Engine from v2.74 to v2.77

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib/src/external/bullet/LinearMath/btQuaternion.h

    r5781 r7983  
    210210        }
    211211
    212 
    213   /**@brief Return the inverse of this quaternion */
     212        /**@brief Return the axis of the rotation represented by this quaternion */
     213        btVector3 getAxis() const
     214        {
     215                btScalar s_squared = btScalar(1.) - btPow(m_floats[3], btScalar(2.));
     216                if (s_squared < btScalar(10.) * SIMD_EPSILON) //Check for divide by zero
     217                        return btVector3(1.0, 0.0, 0.0);  // Arbitrary
     218                btScalar s = btSqrt(s_squared);
     219                return btVector3(m_floats[0] / s, m_floats[1] / s, m_floats[2] / s);
     220        }
     221
     222        /**@brief Return the inverse of this quaternion */
    214223        btQuaternion inverse() const
    215224        {
     
    253262        }
    254263
     264        /**@todo document this and it's use */
     265        SIMD_FORCE_INLINE btQuaternion nearest( const btQuaternion& qd) const
     266        {
     267                btQuaternion diff,sum;
     268                diff = *this - qd;
     269                sum = *this + qd;
     270                if( diff.dot(diff) < sum.dot(sum) )
     271                        return qd;
     272                return (-qd);
     273        }
     274
     275
    255276  /**@brief Return the quaternion which is the result of Spherical Linear Interpolation between this and the other quaternion
    256277   * @param q The other quaternion to interpolate with
     
    265286                        btScalar s0 = btSin((btScalar(1.0) - t) * theta);
    266287                        btScalar s1 = btSin(t * theta);   
    267                         return btQuaternion((m_floats[0] * s0 + q.x() * s1) * d,
    268                                 (m_floats[1] * s0 + q.y() * s1) * d,
    269                                 (m_floats[2] * s0 + q.z() * s1) * d,
    270                                 (m_floats[3] * s0 + q.m_floats[3] * s1) * d);
     288                        if (dot(q) < 0) // Take care of long angle case see http://en.wikipedia.org/wiki/Slerp
     289                          return btQuaternion((m_floats[0] * s0 + -q.x() * s1) * d,
     290                                              (m_floats[1] * s0 + -q.y() * s1) * d,
     291                                              (m_floats[2] * s0 + -q.z() * s1) * d,
     292                                              (m_floats[3] * s0 + -q.m_floats[3] * s1) * d);
     293                        else
     294                          return btQuaternion((m_floats[0] * s0 + q.x() * s1) * d,
     295                                              (m_floats[1] * s0 + q.y() * s1) * d,
     296                                              (m_floats[2] * s0 + q.z() * s1) * d,
     297                                              (m_floats[3] * s0 + q.m_floats[3] * s1) * d);
     298                       
    271299                }
    272300                else
     
    379407
    380408        if (d < -1.0 + SIMD_EPSILON)
    381                 return btQuaternion(0.0f,1.0f,0.0f,0.0f); // just pick any vector
     409        {
     410                btVector3 n,unused;
     411                btPlaneSpace1(v0,n,unused);
     412                return btQuaternion(n.x(),n.y(),n.z(),0.0f); // just pick any vector that is orthogonal to v0
     413        }
    382414
    383415        btScalar  s = btSqrt((1.0f + d) * 2.0f);
Note: See TracChangeset for help on using the changeset viewer.