Original code (current trunk) - it's much worse code bugged same way in stable branch 1.7.2
Code: Select all
inline quaternion& quaternion::slerp(quaternion q1, quaternion q2, f32 time)
{
f32 angle = q1.dotProduct(q2);
// make sure we use the short rotation
if (angle < 0.0f)
{
q1 *= -1.0f;
angle *= -1.0f;
}
if (angle <= 0.95f) // spherical interpolation
{
const f32 theta = acosf(angle);
const f32 invsintheta = reciprocal(sinf(theta));
const f32 scale = sinf(theta * (1.0f-time)) * invsintheta;
const f32 invscale = sinf(theta * time) * invsintheta;
return (*this = (q1*scale) + (q2*invscale));
}
else // linear interploation
return lerp(q1,q2,time);
}
Code: Select all
inline quaternion& quaternion::slerp(quaternion q1, quaternion q2, f32 time)
{
f32 angle = q1.dotProduct(q2);
// make sure we use the short rotation
if (angle < 0.0f)
{
q1 *= -1.0f;
angle *= -1.0f;
}
if (angle <= 1.0 - core::ROUNDING_ERROR_f32) // spherical interpolation
{
const f32 theta = acosf(angle);
const f32 invsintheta = reciprocal(sinf(theta));
const f32 scale = sinf(theta * (1.0f-time)) * invsintheta;
const f32 invscale = sinf(theta * time) * invsintheta;
return (*this = (q1*scale) + (q2*invscale));
}
else // linear interploation
return lerp(q1,q2,time);
}
This way it does not product quaternions with size > 1.