## Recommended Posts

So Im rotating my geometry with:

```vector rot = my_normalized_axis; // this is local axis, not some global like {0, 1, 0}
float angle = this_is_my_angle;
vector piv = my_nice_pivot;

matrix3 rotm = ident();
prerotate(rotm, angle, rot);
vector4 orient = quaternion(rotm);
matrix m = instance(piv, 0, 1, 0, orient, piv);
@P *= m;```

And everything is nice and dandy, except that now I want for my vector rot to apply the rotation too. Because now it just stays as it is.

So this sounds easy but I just cannot make it to work. I tried converting to quat and them qmultiply, extracting rotation from m with cracktransform. But the rotations are weird, not what I want.

Closest where I got was with qmultiply, as one of the components of rot seemed to be doing its thing. But other were off. And since im not rotating with some global rotation axis like {0, 1, 0} I cannot just simply take just one component and discard others.

Edited by JJ FX

##### Share on other sites

Hi,

but "rot" is your axis. If you rotate around this axis, this axis should stay the same, if you apply this rotation on it or am I missing something?

##### Share on other sites

Lets say rot is a vector attribute I use to debug visually whats going on in the viewport. As well its more intuitive to use vector instead of @orient, especially that behaviours of the geo depends on the axes. So I actually have 3 different local attributes for rotations (rotX, rotY, roZ). If Im rotating around rotX, I need to adjust rotY and rotZ. But they are all perpendicular. But technically yeah, the rot I use stays the same.

When applying rotation matrix to geo, this only moves the points, does not rotate attributes. So my rotations stay the same. Think something like FK in rigging. You rotate an arm, and the rotation for the forearm rotates as well.

So when I do:

```vector r = cracktransform(XFORM_TRS, XFORM_XYZ, 4, piv, rotm);
v@myOtherRot += r;```

I can see that the vector is rotating with proper degrees angle, but wrong axis. I tried to extract with different rotation order, but doesnt do much

Edited by JJ FX

##### Share on other sites

Ok I got it finally! So its:

```v@rotX; v@rotY; v@rotZ; // this is local axis, not some global like {0, 1, 0}
float angle = this_is_my_angle;
vector piv = my_nice_pivot; // Try in for loop with different pivots for each point, besically you can bend hair with that

// Rotate by Z:
matrix3 rotm = ident();
prerotate(rotm, angle, rotZ);

// Now rotate other rotation axes, for X:
matrix3 rotXm = ident();
rotate(rotXm, angle, rotYm);
v@rotX += cracktransform(XFORM_TRS, XFORM_XYZ, 4, piv, rotXm);
v@rotX = normalize(v@rotX);
// And Y (its MINUS for some reason):
matrix3 rotYm = ident();
rotate(rotYm, angle, rotXm);
v@rotY -= cracktransform(XFORM_TRS, XFORM_XYZ, 4, piv, rotYm);
v@rotY = normalize(v@rotY);

// And just move the points:
vector4 orient = quaternion(rotm);
matrix m = instance(piv, 0, 1, 0, orient, piv);
@P *= m;```

This took me some time This is visual copy paste, hope no big mistakes

EDIT:

Updated the expression there was one mistake, and rotations need to be normalized after rotating. But now working flowlessly. But still its a visual copy/paste. But you get the idea

Edited by JJ FX

##### Share on other sites

Hi,

ok it looks like you want to chain transformations. Have you tried to multiply the matrices? Quaternions can be another option if you have many operations ... .

Check my example. It contains 3 rotations matrices which are applied on a geometry in a specific order.

If you look into my example, you can see that the first matrix rotates the box around its diagonal line. If you apply the second rotation the box still rotates around its diagonal line, if you change the angle for the first rotation, but now in the transformed space.

matrix_chain.hipnc

##### Share on other sites
3 hours ago, Aizatulin said:

Hi,

ok it looks like you want to chain transformations. Have you tried to multiply the matrices? Quaternions can be another option if you have many operations ... .

Check my example. It contains 3 rotations matrices which are applied on a geometry in a specific order.

If you look into my example, you can see that the first matrix rotates the box around its diagonal line. If you apply the second rotation the box still rotates around its diagonal line, if you change the angle for the first rotation, but now in the transformed space.

Thank you for the example file, will look at that when Im back home!

## Create an account

Register a new account