• Advertisement
Sign in to follow this  

Copying the behaviour of D3DXMatrixMultiply

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

If you intended to correct an error in the post then please contact us.

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
	}


Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
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 this post


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

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement