Sign in to follow this  

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

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
	myMat[0] = cos(aAngle);
	myMat[1] = sin(aAngle);
	myMat[4] = -sin(aAngle);
	myMat[5] = cos(aAngle);

Share this post

Link to post
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 this post

Link to post
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 )


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