# Directly access XMMATRIX ellements

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

## Recommended Posts

Hello, Dont know if Im in the right spot to ask.  Im stuck moving to DirectXMath.   I am calculating the direction of a picking ray in view space and unable to access the member elements in the XMMATRIX.  Maybe they are not public.   The Microsoft DirectX guide was more confusion than help.

Any advice on the conversion would greatly appreciated.

old -> D3CXMATRIX inverseViewMatrix;

direction.x = (pointX * inverseViewMatrix._11) + (pointY * inverseViewMatrix._21) + inverseViewMatrix._31;

converting to below....

Getting error XMMATRIX has no member _11 _21 or _31.

new -> XMMATRIX inverseViewMatrix;

direction.x = (pointX * inverseViewMatrix._11) + (pointY * inverseViewMatrix._21) + inverseViewMatrix._31;

##### Share on other sites

Hi there,

Seems like you need to get a little more familiar with C++ and your dev environment. I assume you're using Visual Studio... if so you can right click on any class name and select "goto definition"

If you do that for XMMATRIX it will bring you to this bit of code

#ifdef _XM_NO_INTRINSICS_
union
{
XMVECTOR r[4];
struct
{
float _11, _12, _13, _14;
float _21, _22, _23, _24;
float _31, _32, _33, _34;
float _41, _42, _43, _44;
};
float m[4][4];
};
#else
XMVECTOR r[4];
#endif


As you can see ... if _XM_NO_INTRINSICS_ is defined you have access to "float _11, _12, _13, _14;" etc via the union.
otherwise the data for the structure is defined as XMVECTOR r[4];

So the simple answer would be to define _XM_NO_INTRINSICS_ if you NEED access to those members for learning purposes. However I assume from the definition name that you will lose all SIMD optimizations!

Good luck!

##### Share on other sites
What you need to do is to store your XMMATRIX into a XMFLOAT4X4. For that you can use XMStoreFloat4x4 (https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.storing.xmstorefloat4x4(v=vs.85).aspx). Then you just use your XMFLOAT4X4 like you were trying to use the XMMATRIX and boom. Done.

It's not very obvious for starters and is a pain in the A for everyone. That's one of the reasons why I moved to GLM.

This for REF_Cracker: disabling SIMD is not a solution and will probably cause greater problems. Also why do you assume OP is using Visual Studio? There's lots of compilers and IDEs, you can't assume such thing.

##### Share on other sites

Thank LH, works like a charm.  A is a good way to describe directxmath. :)

##### Share on other sites

LHLaurini:

1) The OP is asking why he's getting an error trying to access "members _11 _21 _31" etc. I have correctly answered why this is occurring. You have not.

2) While I do assume OP is using Visual Studio as we are dealing with the DirectX Math library here the advice of "going to the definition" of XMMATRIX is sound and teaches the OP how to get to the root of the problem.

3) I have not recommended disabling SIMD. But it appears to be the only way to access elements NAMED _11 _21 _31 if you need to do so for learning purposes.

4) There are additional ways to access the individual components of the matrix including the one you pointed out.

##### Share on other sites

Thank LH, works like a charm. A is a good way to describe directxmath. :)

Glad to hear you managed to make it work. :)

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632960
• Total Posts
3009476
• ### Who's Online (See full list)

There are no registered users currently online

×