convert XMMATRIX to D3DXMATRIX

1k Views Asked by At

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

1

There are 1 best solutions below

0
Chuck Walbourn On

(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).