Closed mbj2011 closed 10 years ago
This looks another Dlang bug to me...
writefln("---------> %s | %s", a.w * b.w + a.x * b.x + a.y * b.y + a.z * b.z, acos(a.w * b.w + a.x * b.x + a.y * b.y + a.z * b.z));
real theta = acos(a.w * b.w + a.x * b.x + a.y * b.y + a.z * b.z);
writefln("---------> %s", theta);
produces:
---------> 1 | -nan
---------> -nan
Which should obviously be 0
not -nan
. No matter what I change, the outcome doesn't change!
Your version looks fine, I added it to the interpolation-module, thanks!
Ok I think I figured it out, the result of the dot product is probably ever so slightly smaller than -1
or bigger than 1
, making acos
return nan
(floating point errors). Clamping the values to -1
and 1
seems to fix it. Please report back, if the issue still exists.
I have absolutely no idea why this is happening, but apprantly there are certain magical quaternions that cannot be interpolated between.
Having done a bit of research on slerp it turns out that its "bad practice" anyway: http://physicsforgames.blogspot.com/2010/02/quaternions.html http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/
If it is not too much trouble, I'd like to see nlerp along with a fixed version of slerp in the interpolate module. My version looks like this:
, but I guarrantee nothing as the bug above is completely blowing my mind.