Hi. I want to get a 2D object to rotate around another one. They are both in world coordinates.
Here's what I have so far:
Point t = center of object that I want to rotate around.
Point p = position of the object that I want to rotate.
I've concatenated 3 matrices (each 3x3):
Matrix concat = TransInv*Rotation*Translate.
where Translate is:
1 0 -t.x
0 1 -t.y
0 0 1
Rotation is:
cos(a) -sin(a) 0
sin(a) cos(a) 0
0 0 1
TransInv is:
1 0 t.x
0 1 t.y
0 0 1
and I get:
| cos(a) -sin(a) -t.x*cos(a) + t.y*sin(a) + t.x |
| sin(a) cos(a) -t.x*sin(a) - t.y*cos(a) + t.y |
| 0 0 1 |
So then I use that matrix and transform 'p':
Point temp;
temp.x = cos(a)*p.x + -sin(a)*p.y + -t.x*cos(a) + t.y*sin(a) + t.x;
temp.y = sin(a)*p.x + cos(a)*p.y + -t.x*sin(a) - t.y*cos(a) + t.y;
p = temp;
[Every time before I apply that transform on p, I reposition it to it's original location (because angle 'a' accumulates each frame)]
And so, what I get is that as the object rotates below position 't', it strays really far away from its circular path but as the object rotates above position 't', it's fine.
What the heck am I doing wrong here? Thank you.
[Edited by - 16bit_port on February 9, 2008 9:05:37 PM]