P. Avery
P. Avery

Reputation: 809

DirectX - Matrix to Quaternion

I'm trying to use directX's D3DXQuaternionRotationMatrix() function to retrieve the rotation quaternion from a matrix. The matrix was generated by Blender (an open-source 3D graphics environment ) and is used to reorient a mesh object for use in DirectX. The problem is that the above function only returns a "w" value in the quaternion. Here is matrix followed by function:

D3DXMATRIX mA;
._11 = 1;
._12 = 0;
._13 = 0;
._14 = 0;
._21 = 0;
._22 = 0;
._23 = 1;
._24 = 0;
._31 = 0;
._32 = 1;
._33 = 0;
._34 = 0;
._41 = 0;
._42 = 0;
._43 = 0;
._44 = 1;

D3DXQUATERNION qA;
D3DXQuaternionRotationMatrix( &qA, &mA );
D3DXQuaternionConjugate( &qA, &qA );

result:

qA.x = 
qA.y = 
qA.z = 0;
qA.w = 0.707

This quaternion doesn't represent any rotation...the matrix, however, does have rotation...what is this rotation? why doesn't the function provide an accurate result?

Upvotes: 1

Views: 2220

Answers (2)

dehersh
dehersh

Reputation: 43

The W of a quaternion represents the rotation in radians. The X, Y and Z portions represent the axis the rotation is about. In your example the Matrix is rotating around (0,0,0) by .707 radians or ~40.5 degrees.

Edit:

If you are looking for the Yaw, Pitch and Roll you can extract it from the quaternion: http://sunday-lab.blogspot.com/2008/04/get-pitch-yaw-roll-from-quaternion.html

Upvotes: 2

Ruan Caiman
Ruan Caiman

Reputation: 881

Your matrix:

1; 0; 0; 0;
0; 0; 1; 0;
0; 1; 0; 0;
0; 0; 0; 1;

This is identity matrix with y and z swapped: Your scene is either Y-Up or Z-Up, and Blender expects D3D to be the opposite, so it uses this matrix to swap y and z. You can think of it as a rotation if you want to, but end result is the same.

Upvotes: 1

Related Questions