Question

Is there a any good way to dump XMMATRIX and XMVECTOR ?

XMMATRIX mx = XMMatrixScaling(...) * XMMatrixTranslation(...);

DumpMatrix(mx); // printf the 4x4 matrix member

I want DumpMatrix like function.

I checked DirectMath.h. And found

typedef __m128 XMVECTOR;

How to extract (x, y, z, w) from __m128 ?

Was it helpful?

Solution

DirectX Math library design doesn't allow direct access to XMMATRIX and XMVECTOR members. It is likely because they store values in special SIMD data types.

To read the components of an XMVECTOR you can use XMVectorGet* acces functions, for example:

XMVECTOR V;
float x = XMVectorGetX(V);
float w;
XMVectorGetWPtr(&w, V);

or XMStore* functions to store it into a XMFLOAT4, which has scalar members with direct access:

XMVECTOR vPosition;
XMFLOAT4 fPosition;
XMStoreFloat4(&fPosition, vPosition);
float x = fPosition.x;

XMMATRIX you can store into a XMFLOAT4X4:

XMMATRIX mtxView;
XMFLOAT4X4 fView;
XMStoreFloat4x4(&fView, mtxView);
float fView_11 = fView._11;

There are also Load functions to make the opposite: write to XMVECTOR and XMMATRIX.

For further information, refer to DirectXMath Programming Reference.

Happy coding!

OTHER TIPS

I can't comment the answer, but i believe the correct code for XMMATRIX is:

XMMATRIX mtxView;
XMFLOAT4X4 fView;
XMStoreFloat4x4(&fView, mtxView);
float fView_11 = fView._11;

so that you can access the matrix member values using the newly created XMFLOAT4X4

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top