I'm getting myself confused with rotations in 2D when rotating about a point about another point. I'm using a simple tree as my scene graph. Each node knows its position relative to its parent, and there is a root node that is the ancestor of all nodes. So when I move a node all of its children move with it.
Rotations of a node about its parent are simple. But how do I rotate a node about another node ?
What I could find on the internet talks about translating the origin to the node being rotated around, rotating it, then translating back. So based on that, I came up with:
- From the node to be rotated walk up the tree to the root node building a translation matrix (1)
- From the origin node walk up the tree to the root node building a translation matrix (2)
- inverse the origin node's translation (2) matrix
- Form the origin translation matrix by multiplying matrix (1) by matrix (2), forming matrix (3)
- Multiply the node to be rotated by matrix (3). It's now a vector relative to the rotation origin
- apply rotation matrix
- multiply the node by the inverse of matrix (3), its now a vector relative to its parent again.
But that seems somewhat over complicated, which makes me think I'm either doing it wrong, or have found a convoluted way of doing something simple.
Any help greatly appreciated.