2

for my university project I have to combine the majority of two different frameworks provided by lecturers but the problem is one lecturer uses XMMATRIX and one uses D3DXMATRIX. Is there a way to convert between the two without having to re-write the majority of the frameworks?

I have tried what is suggested in this question: how to convert XMMATRIX to D3DMATRIX in DirectX 9?

But this did not help. I need to pass a D3DXMATRIX in to a particular shader class from an XMMATRIX. Storing the XMMATRIX in an XMFLOAT4X4 and casting did not work it just tells me that there is no suitable conversion from the float to the d3dxmatrix.

XMMATRIX worldMatrix, viewMatrix, projectionMatrix;
XMFLOAT4X4 wMatrix, vMatrix, pMatrix;

m_Direct3D->GetWorldMatrix(worldMatrix);
m_Camera->GetViewMatrix(viewMatrix);
m_Direct3D->GetProjectionMatrix(projectionMatrix);

XMStoreFloat4x4(&wMatrix, worldMatrix);
XMStoreFloat4x4(&vMatrix, viewMatrix);
XMStoreFloat4x4(&pMatrix, projectionMatrix);

m_Tshader->Render(m_Direct3D->GetDeviceContext(), m_Terrain->GetIndexCount(), (D3DXMATRIX)wMatrix, (D3DXMATRIX)vMatrix, (D3DXMATRIX)pMatrix,
m_Light->GetAmbientColour, m_Light->GetDiffuseColour, m_Light->GetDirection);

Thanks

Community
  • 1
  • 1
AdamW95
  • 51
  • 1
  • 5
  • Similar question [here](http://stackoverflow.com/q/17173925/1460794). – wally Apr 20 '16 at 15:20
  • have updated question – AdamW95 Apr 20 '16 at 15:54
  • `But this did not help`. Then you are doing something wrong. See: [MSDN - Working with D3DXMath](https://msdn.microsoft.com/en-us/library/windows/desktop/ff729728%28v=vs.85%29.aspx). Post relevant [code](http://stackoverflow.com/help/mcve) and the current problem description, along with carefully copy-pasted error messages. – Ivan Aksamentov - Drop Apr 21 '16 at 00:18

1 Answers1

2

(D3DXMATRIX)wMatrix will not work.

If the function takes D3DXMATRIX by value, then you can do *reinterpret_cast<D3DXMATRIX*>(&wMatrix).

If the function takes D3DXMATRIX* then you can do reinterpret_cast<D3DXMATRIX*>(&wMatrix).

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81