Sign in to follow this  
peter_b

Copying the behaviour of D3DXMatrixMultiply

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this