netPivotShift

|_

*object* |_ pivot_loc

|_ object_rotInstead of step by step tutorial, I will try to describe main logic of how it works. First, let's examine our goal and see what kind of result we are looking for. Here is an image that shows the initial status and what we expect after rotating the cube.

If we rotate the cube right now in our current initial state, then what we get is shown in the image below. It's what you would expect since our pivot is parented under the cube. But this is not what we want.

So how do we go from our initial state to the final result? There are different ways to solve this problem. Here, we look at one way to do it, which may not necessarily be the easiest.

First thing we need to keep in mind is that our pivot is parented under the cube, that means our pivot is operating under cube's coordinate space (

**V.IMP.**). Now, let's see the steps to get the final result.

**#1**) We move the pivot point so that it lies on the origin. (Keep in mind, this origin is in our cube's space)

Why do we do this? So we can apply rotation matrix which always rotates around (0,0,0)

**#2**) Now, we apply the rotation, which will be around the origin by default.

See it already looks closer to the result we want!

**#3**) Then we reverse the first step. We move everything back so that pivot goes to it's original location.

And we have our final result!

The matrix equation to get the above result is:

shift = pivot_loc.inverseMatrix * object_rot.matrix * pivot_loc.matrix

(this can be a bit confusing if compared to original equation in first post, because we are taking a bit different approach here)Now prepare the network to calculate the object movement around pivot using above matrix equation. Plug object's rotation into

*object_rot*which will be our rotation matrix. Once you have the matrix calculation network ready, plug the final

*.matrixSum*to a

*decomposeMatrix*node's

*.inputMatrix*attribute. What we will get here (in

*.outputTranslate*) is the translation value that the

*object*should move to get the pivoting movement around pivot_loc. Just to test the result you can plug

*.outputTranslate*attribute of decomposeMatrix node to

*netPivotShift*node and see how it works. Give it a try, it's fun! :)

Phew! That took the whole brain out of me! Now, remains the offsetting logic. Let's keep it for the next post to give my brain processor some rest :)