Archived

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

Matrix Rotation Centered off of the Origin

This topic is 5599 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

Hey, I am using 4x4 matrices to do my rotations and I was wondering if there was some way to rotate around a point OTHER than 0, 0, 0. It is for skeletal animation. As most of the bones are not located exactly at 0, 0, 0, and I do not want to move all of the parts of the model to 0, 0, 0 to compensate, I need to know if this is possible or not and if so how I can do it. Thanks in advance. Walt

Share this post


Link to post
Share on other sites
Yes it is possible. If your center of rotation is P, then first you translate by -P, then perform your rotations, and then translate by P. (not sure about the order of matrix multiplications require, but should be able to guess it in two tries)

Share this post


Link to post
Share on other sites
Hey...
Uhhh I tried this... (with P as position, total rot as previous bones'' sum rotation, rot as this bones new rotation)

NewRot = Matrix(-P) * TotalRot * rot * Matrix(P);

And the rotation screws up the final translation... how can i fix this? I tried moving the multiplies around but it didn''t work

Walt

Share this post


Link to post
Share on other sites
Update:

I''ve found that it works *better* to do this:

NewRot = TotalRot * (Matrix(-Loc) * Rot * Matrix(Loc * Rot.GetTranspose33()))

But it still doesn''t work... Rot is the rotation of the current bone and TotalRot is the NewRot of the previous bone (thus forming a chain of rotations and translations which should work....)

Share this post


Link to post
Share on other sites
w00t! anyway, i fixed it, you have to do this (in case anyone''s interested, which, if you are, post a message so i''ll know this wasn''t in vain) :

NewRot = TotalRot * (Matrix(Loc) * Rot * Matrix(-Loc));

where, once again, the totalrot is the NewRot of the parent bones for this bone. The Loc''s are the locations BEFORE any transformation also.

Walt

Share this post


Link to post
Share on other sites