• Advertisement
Sign in to follow this  

DirectX 9 Effect framework and XNA math problem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've decided to change math library in my engine (GAPI - DirectX9) from D3DX to XNA from the new DX SDK. The problem is that I can't find a way to pass my matrices to shader through Effect framework SetMatrix function. I tried (float*), (D3DMATRIX *) and many other things but no success.

Here's a structure of XMMATRIX according to SDK help:
typedef struct _XMMATRIX {
union {
XMVECTOR r[4];
struct {
FLOAT _11;
FLOAT _12;
FLOAT _13;
FLOAT _14;
FLOAT _21;
FLOAT _22;
FLOAT _23;
FLOAT _24;
FLOAT _31;
FLOAT _32;
FLOAT _33;
FLOAT _34;
FLOAT _41;
FLOAT _42;
FLOAT _43;
FLOAT _44;
};
FLOAT m[4][4];
};
} XMMATRIX;
Please if anyone know how to solve this issue (pass XMMATRIX to fx shader through SetMatrix function) I'd gladly listen to the solution :)

edit:
In drawScene function I have:
HR(mFX->SetMatrix(mhP, &mProj));
where mFX -> ID3DXEffect* mFX;
mhP->D3DXHANDLE mhP;
mProj ->
XMMATRIX mProj;
If I use D3DX matrix - everything is fine. But if I use XMMATRIX - I receive the following compiler error: error C2664: 'ID3DXEffect::SetMatrix' : cannot convert parameter 2 from 'XMMATRIX *' to 'const D3DXMATRIX *' on this line.

Share this post


Link to post
Share on other sites
Advertisement
but no success[/quote]
Relalize that your post is essentially: "I have some code. It doesn't work. What's wrong?"

Post a minimal block of code that illustrates your issue, including your error checking, and describe why you say there's "no success."

Share this post


Link to post
Share on other sites
You should be able to use SetValue to pass in the bytes directly.

Something like: mFX->SetValue(mhP, &mProj, sizeof(mProj));

Share this post


Link to post
Share on other sites
Hidden
Thank you for a suggestion andur but your method doesn't work either. It gives Unhandled exception Access violation reading on this line of code:
mFX->SetValue(mhP, &mProj, sizeof(mProj));
My friend told me that this is due to the fact that data is aligned in XMMATRIX.

Share this post


Link to post

You should be able to use SetValue to pass in the bytes directly.

Something like: mFX->SetValue(mhP, &mProj, sizeof(mProj));

Thank you very much andur!

A friend of mine told me another way to do this:
mFX->SetMatrix(mhP, (const D3DXMATRIX *)&mProj._11);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement