03 April, 2011

Making Animatable Pivot: Part 1

First concept here to understand is the rotation operation and how it is affected by pivot point. Here is a post I wrote on my blog last year to understand how pivot works.

First we will look at how rotation around pivot point is calculated in simple steps.
1. Translate the object from its current location to the pivot point location
2. Rotate the object
3. Translate the object back to its place from pivot point location

What the last step does is that it moves the object in the rotated transform axis. Hence it moves the object to the final location which gives the effect of rotation around given pivot point. Mathematically here is what we will do using matrices to get the final result:
F = T * R * T'
T = translation matrix to move from current position to the pivot position
R = rotation matrix
T' = inverse matrix of T

This was just the first step, in calculating the rotation around arbitrary point. However, the main challenge is to make pivot point animatabale.

If you have rotated the object first and then try to change the pivot location, the object will move as well. What happens here is that the object already had some rotation applied to it based on previous pivot position. Now, we change the pivot location which will cause the final matrix to be recalculated based on existing rotation and new pivot point. This results in object shifting to a new location. This seems quite obvious, but in many cases it is unwanted. Maya deals with this problem by storing an offset value in ".translateRotatePivot" attribute when you are moving the pivot point. This stops object from shifting.
But the problem with Maya's approach is that all the rotation calculations are always based on single pivot location. So even if object does not move while moving pivot point, it does affect all the previously keyframed transform values.

So to solve this problem we calculate the offset at each change of pivot location and then store this offset which can be animated on a pivot control. I will write about this in detail in my next post.


  1. RoHiT :- so did u find the solution to it

  2. I have found one solution. I will try to explain that in second part of this topic.

  3. Hi Maulik,
    First of all thank you for sharing this information.
    One question - here you wrote :
    "1. Translate the object from its current location to the pivot point location."
    How to translate an object to it's pivot point, when pivot point moves with object? I mean, when objects moves also moves it's pivot point.

  4. You do not actually move the object, but for calculation you take the translation value necessary to move the object to its pivot location. I am planning to write some articles on these kinds of calculations using matrices. I am also learning it and I need to take some notes to remember them myself :)

  5. Thanks! I'll be watching your publications