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
}
Copying the behaviour of D3DXMatrixMultiply
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?
Thanks in advance!
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.
Your implementation will break in both of these cases:
matrix_multiply( m2, m1, m2); matrix_multiply( m1, m1, m2);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement