Public Group

# Matrix problem

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

## 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 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 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 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 on other sites
Quote:
 Original post by Sync Views//-4.3714e-008 == 0.3714 - d3dx

Er, how did you figure that?

1. 1
Rutin
43
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633398
• Total Posts
3011659
• ### Who's Online (See full list)

There are no registered users currently online

×