Matrix Rotation Centered off of the Origin

Started by
3 comments, last by shadowman13131 21 years, 8 months ago
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
Advertisement
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)
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
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....)
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

This topic is closed to new replies.

Advertisement