#### Archived

This topic is now archived and is closed to further replies.

# Matrix class (multiply matrix)

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

## Recommended Posts

I have created a matrix class to translate/scale/rotate objects in my engine.. but I can''t get the matrix multiply working example: cMatrix mat; mat.Identity(); mat.RotateY( 2.0 ); Sword->m_Matrix.Multiply( mat ); that code will rotate the sword around it''s Y axis by 2 every frame... the problem is that when the sword is rotating it is shrinking and the colors looks messy.. why? the Matrix multiply code
void cMatrix::Multiply(cMatrix m)
{
_11 = _11 * m._11 + _12 * m._21 + _13 * m._31 + _14 * m._41;
_12 = _11 * m._12 + _12 * m._22 + _13 * m._32 + _14 * m._42;
_13 = _11 * m._13 + _12 * m._23 + _13 * m._33 + _14 * m._43;
_14 = _11 * m._14 + _12 * m._24 + _13 * m._34 + _14 * m._44;

_21 = _21 * m._11 + _22 * m._21 + _23 * m._31 + _24 * m._41;
_22 = _21 * m._12 + _22 * m._22 + _23 * m._32 + _24 * m._42;
_23 = _21 * m._13 + _22 * m._23 + _23 * m._33 + _24 * m._43;
_24 = _21 * m._14 + _22 * m._24 + _23 * m._34 + _24 * m._44;

_31 = _31 * m._11 + _32 * m._21 + _33 * m._31 + _34 * m._41;
_32 = _31 * m._12 + _32 * m._22 + _33 * m._32 + _34 * m._42;
_33 = _31 * m._13 + _32 * m._23 + _33 * m._33 + _34 * m._43;
_34 = _31 * m._14 + _32 * m._24 + _33 * m._34 + _34 * m._44;

_41 = _41 * m._11 + _42 * m._21 + _43 * m._31 + _44 * m._41;
_42 = _41 * m._12 + _42 * m._22 + _43 * m._32 + _44 * m._42;
_43 = _41 * m._13 + _42 * m._23 + _43 * m._33 + _44 * m._43;
_44 = _41 * m._14 + _42 * m._24 + _43 * m._34 + _44 * m._44;
}

the RotateY code
void cMatrix::RotateY(float fAngle)
{
}

the cMatrix class
class ICE3D_API cMatrix {

float _11, _12, _13, _14;
float _21, _22, _23, _24;
float _31, _32, _33, _34;
float _41, _42, _43, _44;

public:

cMatrix();
~cMatrix();

void Zero();
void Identity();

/**
Multiply matrix
*/
void Multiply(cMatrix sM);
cVertex3f Multiply(cVertex3f src);

/**
Rotate matrix.
*/
void RotateX(float fAngle);
void RotateY(float fAngle);
void RotateZ(float fAngle);
};


##### Share on other sites
It''s the way you are generating the matrix from euler angles - to do this you must create separate x, y, and z matrixes and multiply those together to get the complete transformation matrix for all 3 axii(sp).

There''s better ways of doing this, I did this for a while, but now I generate quaternions from euler, and convert to matrix when necessary.

##### Share on other sites
The reason is in the mat mult.The function is much,much wrong.After you do the first line:

_11 = _11 * m._11 + _12 * m._21 + _13 * m._31 + _14 * m._41;

the value of _11 is no longer the same so the rest of the matrix mult will use wrong value.The solution is to make a matrix which to store the multiplied values and simply pass it to the user after the mult.Cheers!

"Tonight we strike,there is thunder in the sky,together we''ll fight,some of us will die,but they''ll always remember that we''ve made a stand and many will die by hand!" - ManOwaR

##### Share on other sites
Good one, I didn''t notice that

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633695
• Total Posts
3013376
×