Can anyone see an error in the multiply or rotate functions ?

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

Recommended Posts

Hi When I rotate around Z my points seem to scatter after a little while. Am I doing something wrong or is it a number precision problem? Thanks for the help
void Matrix44::Multiply(Matrix44* aOut, Matrix44* aIn1, Matrix44* aIn2)
{
aOut->myMat[0] = aIn1->myMat[0] * aIn2->myMat[0] + aIn1->myMat[1] * aIn2->myMat[4] + aIn1->myMat[2] * aIn2->myMat[8] + aIn1->myMat[3] * aIn2->myMat[12];
aOut->myMat[1] = aIn1->myMat[0] * aIn2->myMat[1] + aIn1->myMat[1] * aIn2->myMat[5] +aIn1->myMat[2] * aIn2->myMat[9] +aIn1->myMat[3] * aIn2->myMat[13];
aOut->myMat[2] = aIn1->myMat[0] * aIn2->myMat[2] + aIn1->myMat[1] * aIn2->myMat[6] +aIn1->myMat[2] * aIn2->myMat[10] +aIn1->myMat[3] * aIn2->myMat[14];
aOut->myMat[3] = aIn1->myMat[0] * aIn2->myMat[3] + aIn1->myMat[1] * aIn2->myMat[7] +aIn1->myMat[2] * aIn2->myMat[11] +aIn1->myMat[3] * aIn2->myMat[15];

aOut->myMat[4] = aIn1->myMat[4] * aIn2->myMat[0] +aIn1->myMat[5] * aIn2->myMat[4] +aIn1->myMat[6] * aIn2->myMat[8] +aIn1->myMat[7] * aIn2->myMat[12];
aOut->myMat[5] = aIn1->myMat[4] * aIn2->myMat[1] +aIn1->myMat[5] * aIn2->myMat[5] +aIn1->myMat[6] * aIn2->myMat[9] +aIn1->myMat[7] * aIn2->myMat[13];
aOut->myMat[6] = aIn1->myMat[4] * aIn2->myMat[2] +aIn1->myMat[5] * aIn2->myMat[6] +aIn1->myMat[6] * aIn2->myMat[10] +aIn1->myMat[7] * aIn2->myMat[14];
aOut->myMat[7] = aIn1->myMat[4] * aIn2->myMat[3] +aIn1->myMat[5] * aIn2->myMat[7] +aIn1->myMat[6] * aIn2->myMat[11] +aIn1->myMat[7] * aIn2->myMat[15];

aOut->myMat[8] = aIn1->myMat[8] * aIn2->myMat[0] +aIn1->myMat[9] * aIn2->myMat[4] +aIn1->myMat[10] * aIn2->myMat[8] +aIn1->myMat[11] * aIn2->myMat[12];
aOut->myMat[9] = aIn1->myMat[8] * aIn2->myMat[1] +aIn1->myMat[9] * aIn2->myMat[5] +aIn1->myMat[10] * aIn2->myMat[9] +aIn1->myMat[11] * aIn2->myMat[13];
aOut->myMat[10] = aIn1->myMat[8] * aIn2->myMat[2] +aIn1->myMat[9] * aIn2->myMat[6] +aIn1->myMat[10] * aIn2->myMat[10] +aIn1->myMat[11] * aIn2->myMat[14];
aOut->myMat[11] = aIn1->myMat[8] * aIn2->myMat[3] +aIn1->myMat[9] * aIn2->myMat[7] +aIn1->myMat[10] * aIn2->myMat[11] +aIn1->myMat[11] * aIn2->myMat[15];

aOut->myMat[12] =aIn1->myMat[12] * aIn2->myMat[0] +aIn1->myMat[13] * aIn2->myMat[4] +aIn1->myMat[14] * aIn2->myMat[8] +aIn1->myMat[15] * aIn2->myMat[12];
aOut->myMat[13] =aIn1->myMat[12] * aIn2->myMat[1] +aIn1->myMat[13] * aIn2->myMat[5] +aIn1->myMat[14] * aIn2->myMat[9] +aIn1->myMat[15] * aIn2->myMat[13];
aOut->myMat[14] =aIn1->myMat[12] * aIn2->myMat[2] +aIn1->myMat[13] * aIn2->myMat[6] +aIn1->myMat[14] * aIn2->myMat[10] +aIn1->myMat[15] * aIn2->myMat[14];
aOut->myMat[15] =aIn1->myMat[12] * aIn2->myMat[3] +aIn1->myMat[13] * aIn2->myMat[7] +aIn1->myMat[14] * aIn2->myMat[11] +aIn1->myMat[15] * aIn2->myMat[15];
}

void Matrix44::RotateZ(float aAngle)
{
//Set it to identity
Identity();
myMat[0] = cos(aAngle);
myMat[1] = sin(aAngle);
myMat[4] = -sin(aAngle);
myMat[5] = cos(aAngle);
}



Share on other sites
How do you use your matrix multiplication ?

Do you take the points from the last frame and rotate them by some amount ? This might result in scattering.

Share on other sites
Afternoon, Joachim.

Sounds like it could be a Gimbal-Lock problem.

Is it possible to show the code which does the actual updating (i.e. what calls RotateZ)?

I've got a snippet which obtains Gimbal-Lock, however there's no point posting it if it wouldn't suit how you're positioning and moving/rotating objects (and, NO, it doesn't use quaternions;p )

Cheers,
Scronty

1. 1
Rutin
19
2. 2
3. 3
JoeJ
16
4. 4
5. 5

• 26
• 20
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631700
• Total Posts
3001781
×