# DirectX Quaternion SLERP Wrong Answer?

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

## 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:

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 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 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 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.

1. 1
2. 2
3. 3
4. 4
5. 5

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632911
• Total Posts
3009187
• ### Who's Online (See full list)

There are no registered users currently online

×