# Strange quaternion rotation

I was implementing some quaternion rotations in too my infant 3d game engine and the rotations were really strange? Excuses my cluelessness.

Anyways this is what I have:

static XMVECTOR XMConvertToQuaternion(XMFLOAT3 axis, float radian)
{
axis = XMNormalize3(axis);
XMVECTOR tempAxis = XMVectorSet(axis.x, axis.y, axis.z, 1);
return q;
}


Then later on down when I apply the quaternion to the world matrix I have:

XMMATRIX scaling = XMMatrixScaling(scale.x, scale.y, scale.z);

XMMATRIX translate = XMMatrixTranslation(translation.x, translation.y, translation.z);
XMStoreFloat4x4(&mWorld, scaling*rotateQX*rotateQY*rotateQZ*translate);


I did get a rotation. However, the character is rotating very strangely.

the way to create your Quaternion rotations matrices (I assume from euler angles) look funny, I would expect you use unit vectors of each axis rather than axis

XMMATRIX rotateQX = XMMatrixRotationQuaternion(MathHelper::XMConvertToQuaternion(XMFLOAT3(1, 0, 0), radianRotation.x));
XMMATRIX rotateQY = XMMatrixRotationQuaternion(MathHelper::XMConvertToQuaternion(XMFLOAT3(0, 1, 0), radianRotation.y));
XMMATRIX rotateQZ = XMMatrixRotationQuaternion(MathHelper::XMConvertToQuaternion(XMFLOAT3(0, 0, 1), radianRotation.z));


On this line:

XMStoreFloat4x4(&mWorld, scaling*rotateQX*rotateQY*rotateQZ*translate);


does changing the order to:

XMStoreFloat4x4(&mWorld, translate*rotateQX*rotateQY*rotateQZ*scaling);


make a difference? If you meant to rotate about the origin then translate outwards then you need to be careful with your ordering, though I'm making assumptions about the XM library.

• No, that just made it worse. Haha Sep 30, 2014 at 18:36
• Try taking out the translation and scaling completely. Then test each axis separately if necessary. Results? Sep 30, 2014 at 19:27
• I just got the same results. Must be how I got the quaternion. Sep 30, 2014 at 21:57
• I don't know if you just copied your code wrong, but you are currently using the same axis for each quaternion rotation, which is not what you want to do. Oct 1, 2014 at 7:26