Sign in to follow this  

Matrix problem

This topic is 3459 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

Ive been working on writing a matrix class to hlep me learn how and why they work, as well as to have something that isn't tied to an API (D3DXMatrix), for my game logic, keeping the grafics stuff in the rendering stages. I have been checking it against the d3dx one to make sure the maths is right (also because ultimately I'll need to convert from mine to theres for setting transforms etc). This has been going fine untill I got onto rotation, where for some reason I'm coming up with a diffrent matrix than the d3d one :(
Matrix<4,4>* MatrixCreateRotateZ(double rad, fw::math::Matrix<4,4>* Mat = NULL)
{
	double s = sin(rad);
	double c = cos(rad);
	if(!Mat)
		Mat = new fw::math::Matrix<4,4>();

	Mat->m[0][0] = c; Mat->m[1][0] =-s; Mat->m[2][0] = 0; Mat->m[3][0] = 0;
	Mat->m[0][1] = s; Mat->m[1][1] = c; Mat->m[2][1] = 0; Mat->m[3][1] = 0;
	Mat->m[0][2] = 0; Mat->m[1][2] = 0; Mat->m[2][2] = 1; Mat->m[3][2] = 0;
	Mat->m[0][3] = 0; Mat->m[1][3] = 0; Mat->m[2][3] = 0; Mat->m[3][3] = 1;
	return Mat;
}



Both are supposed to be a roation of 90 degrees on the z axis, (I did convert both to radians first)
D3DX

-4.3714e-008    0-1          0        0
 
  
1             -4.3714e-008   0        0


0             0              1        0


0             0              0        1


MINE:

6.12303e-017   0-1           0        0



1              6.12303e-017  0        0



0              0             1        0



0              0             0        1

//-4.3714e-008 == 0.3714 - d3dx
//6.12303e-017 == 0.00000000000000612303 - mine

Share this post


Link to post
Share on other sites
They are identical as far as single and double precision floating point values goes. 8 and 17 significant values (taken from the exponents in your values) is about the limit of single and double precision floating point values, respectively.

Share this post


Link to post
Share on other sites
There is no big difference in the 2 matrices: For most practical purposes -4.3*10-8 is close to 0, as well as 6.2*10-17 is. Perhaps D3D uses floats for the components, while you use doubles.

EDIT: Oh, I'm too late ...

Share this post


Link to post
Share on other sites
That looks fine to me, a float can't hold a very precise value at all, and -4.3714e-008 is absolutely tiny, approaching the smallest value a float can hold.

Looks like it's just a minor rounding error.

As an aside, I'd avoid doubles for this, since there can be a performance impact from using D3D with doubles, since they both need the FPU state set differently.

EDIT: Waaaay too late [smile]

Share this post


Link to post
Share on other sites

This topic is 3459 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.

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