• Create Account

### #Actualcozzie

Posted 23 April 2014 - 01:08 PM

Thanks, in my case it's a left handed system.

Here's my code of composing a model matrix:

D3DXMATRIX* ComposeD3DXWorldMatrix(D3DXMATRIX *pOut, const D3DXVECTOR3 &pScale, const float pXrot, const float pYrot, const float pZrot, const D3DXVECTOR3 pTranslation)
{
pOut->m[0][0] = std::cos(pYrot) * std::cos(pZrot) * pScale.x;
pOut->m[0][1] = std::cos(pYrot) * std::sin(pZrot) * pScale.x;
pOut->m[0][2] = -std::sin(pYrot) * pScale.x;
pOut->m[0][3] = 0.0f;

pOut->m[1][0] = (((std::sin(pXrot) * std::sin(pYrot)) * std::cos(pZrot)) + (std::cos(pXrot) * -std::sin(pZrot))) * pScale.y;
pOut->m[1][1] = (((std::sin(pXrot) * std::sin(pYrot)) * std::sin(pZrot)) + (std::cos(pXrot) * std::cos(pZrot))) * pScale.y;
pOut->m[1][2] = std::sin(pXrot) * std::cos(pYrot) * pScale.y;
pOut->m[1][3] = 0.0f;

pOut->m[2][0] = (((std::cos(pXrot) * std::sin(pYrot)) * std::cos(pZrot)) + (-std::sin(pXrot) * -std::sin(pZrot))) * pScale.z;
pOut->m[2][1] = (((std::cos(pXrot) * std::sin(pYrot)) * std::sin(pZrot)) + (-std::sin(pXrot) * std::cos(pZrot))) * pScale.z;
pOut->m[2][2] = std::cos(pXrot) * std::cos(pYrot) * pScale.z;
pOut->m[2][3] = 0.0f;

pOut->m[3][0] = pTranslation.x;
pOut->m[3][1] = pTranslation.y;
pOut->m[3][2] = pTranslation.z;
pOut->m[3][3] = 1.0f;

return pOut;
}


I also draw it out for understanding:

Math is slightly growing on me, luckily

For better clarity I could have named 'XYZW'/ XYZW, columns/ row 0 to 3.

I also found out that I can user either the 2 dimensional array for the d3dxmatrix data [ ][ ] or the '_11, _12 etc.' members (_12 would be 1st row, 2nd col).

### #1cozzie

Posted 23 April 2014 - 01:08 PM

Thanks, in my case it's a left handed system.

Here's by code of composing a model matrix:

D3DXMATRIX* ComposeD3DXWorldMatrix(D3DXMATRIX *pOut, const D3DXVECTOR3 &pScale, const float pXrot, const float pYrot, const float pZrot, const D3DXVECTOR3 pTranslation)
{
pOut->m[0][0] = std::cos(pYrot) * std::cos(pZrot) * pScale.x;
pOut->m[0][1] = std::cos(pYrot) * std::sin(pZrot) * pScale.x;
pOut->m[0][2] = -std::sin(pYrot) * pScale.x;
pOut->m[0][3] = 0.0f;

pOut->m[1][0] = (((std::sin(pXrot) * std::sin(pYrot)) * std::cos(pZrot)) + (std::cos(pXrot) * -std::sin(pZrot))) * pScale.y;
pOut->m[1][1] = (((std::sin(pXrot) * std::sin(pYrot)) * std::sin(pZrot)) + (std::cos(pXrot) * std::cos(pZrot))) * pScale.y;
pOut->m[1][2] = std::sin(pXrot) * std::cos(pYrot) * pScale.y;
pOut->m[1][3] = 0.0f;

pOut->m[2][0] = (((std::cos(pXrot) * std::sin(pYrot)) * std::cos(pZrot)) + (-std::sin(pXrot) * -std::sin(pZrot))) * pScale.z;
pOut->m[2][1] = (((std::cos(pXrot) * std::sin(pYrot)) * std::sin(pZrot)) + (-std::sin(pXrot) * std::cos(pZrot))) * pScale.z;
pOut->m[2][2] = std::cos(pXrot) * std::cos(pYrot) * pScale.z;
pOut->m[2][3] = 0.0f;

pOut->m[3][0] = pTranslation.x;
pOut->m[3][1] = pTranslation.y;
pOut->m[3][2] = pTranslation.z;
pOut->m[3][3] = 1.0f;

return pOut;
}


I also draw it out for understanding:

Math is slightly growing on me, luckily

For better clarity I could have named 'XYZW'/ XYZW, columns/ row 0 to 3.

I also found out that I can user either the 2 dimensional array for the d3dxmatrix data [ ][ ] or the '_11, _12 etc.' members (_12 would be 1st row, 2nd col).

PARTNERS