# Copying the behaviour of D3DXMatrixMultiply

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

## Recommended Posts

Hello. Im trying to write a matrix mul that has the exact same behaviour as D3DXMatrixMultiply. The function iv pasted below does this, the most of the time.. But sometimes it is slightly off! I cant see what causes this. The diffrance shows when im flying around with my camera, which has up, forward, right & position vectors. Which i build a look at lefthand view matrix from. When strafeing, the diffrance between the functions shows, the right vector becomes wrong. And instead of strafing straight to the right or left, it strafes both right/left and forward/back. But that isn't really important, its just that its the only way i have to reproduce the errors, but i havent made any extensive analys of results. Can anyone see what is wrong?
void matrix_multiply(matrix_t* out, const matrix_t* m1, const matrix_t* m2)
{
#ifdef D3DTESTING
D3DXMatrixMultiply((D3DXMATRIX*)out, (CONST D3DXMATRIX*)m1, (CONST D3DXMATRIX*)m2);
#else
for(int x = 0; x < 4; x++)
{
for(int y = 0; y < 4; y++)
{
float f = 0;
for(int n = 0; n < 4; n++)
f += m1->m[x][n] * m2->m[n][y];

out->m[x][y] = f;
}
}
#endif
}



##### Share on other sites
Your function looks correct. There are a number of other places where things could be going wrong though, such as where you extract your vectors from the matrix or construct the lookat matrix. If the post the rest of the relevant code, I'm sure someone will be able to help you.

##### Share on other sites
Your implementation will break in both of these cases:
    matrix_multiply( m2, m1, m2);    matrix_multiply( m1, m1, m2);

##### Share on other sites
ah that was it! it works when i use a temp matrix and then copy it to the out matrix, thanks for all replies!

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002290
×