I seem to be having an issue with making a quaternion interpolate through the shortest path. I am making use of Bullet's math/phyiscs package and the quaternion slerp function it provides. My research tells me that when the dot product of two quaternions is negative you should negate one of them. Is my approach correct? It doesn't seem to be producing the correct result.
void vSlerp(btQuaternion& start, btQuaternion& end, float t, btQuaternion& result)
{
start = start.normalize();
end = end.normalize();
float dot = start.dot(end);
if (dot > 0.999995)
{
result=start;
}
else if (dot >= 0)
{
result = slerp(start,end,t); // Bullet quaternion slerp
}
else
{
result = slerp(start, -end, t); // avoid going the longer way around?
}
result.normalize();
}
Any idea or suggestion is greatly appreciated! Thanks!
↧