Sign in to follow this  

DirectX Quaternion SLERP Wrong Answer?

This topic is 1117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have some code that looks like this:

DirectX::XMVECTOR a, b, c;
a = DirectX::XMQuaternionIdentity();
b = DirectX::XMQuaternionRotationAxis(DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f), 3.1415f);
c = DirectX::XMQuaternionRotationAxis(DirectX::XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f), (3.1415f * 3.0f) / 2.0f);

DirectX::XMVECTOR slerpAB = DirectX::XMQuaternionSlerp(a, b, 0.4f);
DirectX::XMVECTOR slerpBC = DirectX::XMQuaternionSlerp(b, c, 0.85f);
DirectX::XMVECTOR slerpCA = DirectX::XMQuaternionSlerp(c, a, 1.0f);

The thing is, I'm sure that slerpBC is wrong. Here's what I'm getting:

 

h057K.png

 

If I understand it right, slerpBC should be 85% of the way towards a 3-quater turn around the Z axis. But when I plug that value in to Wolfram Alpha, it looks totally wrong.

 

Furthermore, when I run the code through my own Slerp code I get a totally different answer that looks more correct, to me.

 

So... What am I doing wrong?

Share this post


Link to post
Share on other sites

I get your result in a different order when I cut and paste your code. I.e., no reason to think the calculation is incorrect.

 

[attachment=24770:slerp.png]

 

So, how are you determining that the quaternion values look correct or not?

Edited by Buckeye

Share this post


Link to post
Share on other sites

Interesting, if I expand the debugger view to see the variable as an m128_f32 I get a similar result to you (by the way, are Quaternions layed out in memory as XYZW?).

 

I thought __m128 would show me a 4x 32-bit-float view in the debugger... What is it actually showing?

 

EDIT: Oh, is it just showing the values as they were put on the registers?

Edited by EscapeLizard

Share this post


Link to post
Share on other sites


is it just showing the values as they were put on the registers?

 

Yep. You can look at values "extracted" from the registers by:

    float sx = XMVectorGetX(slerpBC);
    float sy = XMVectorGetY(slerpBC);
    float sz = XMVectorGetZ(slerpBC);
    float sw = XMVectorGetW(slerpBC);

If you do that, I think you'll see values a bit more like what you're expecting.

Share this post


Link to post
Share on other sites

This topic is 1117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this