Jump to content
  • Advertisement
Sign in to follow this  
WonderWorld

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.

If you intended to correct an error in the post then please contact us.

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


Link to post
Share on other sites
Advertisement
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 )

Cheers,
Scronty

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!