Rotating Instances around a sphere

Hello Everyone!!
I have difficulties with Rotations of instances with GLSL.
I have a sphere composed of Points Sprites.
Each point is positioned with a shader (in GLSL MAT) sampling a texture .
The texture is obtained in the following way : I have a sphere SOP, I apply a ‘SOPto’ CHOP and a ‘CHOPto’ TOP; this last one, is then modified with a GLSL TOP which add a Rotation to the whole spherical geometry.
So at the end of the whole network, the point sprites on my sphere are rotating.
Now I want to do the same using instances, but the same process doesn’t work. I found an example to rotate the instance to its own axis, but not to the object axis. Any help?instancing example.3.toe (231.5 KB)

1 Like

Hi there,

if you want to rotate something around a different point than its center, you can first translate (move) your vertices, then rotate them, and move them back again. So something like:
pos = RotateMatrix * (pos - vec3(1,0,0)) + vec3(1,0,0);

I’ve made a small example where I’m using the default TDDeform() function to move the instances to the right position (reading out of the geo instance tab). If you rotate the position after this function, the sphere will rotate, if you do it before, the box will rotate.
Also don’t forget to rotate the normals as well.

Hope this helps.
cheers,
tim

InstancedSphereRotate.tox (3.0 KB)

1 Like

Thank you Tim. It has actually helped a lot.
Yesterday evening I was actually thinking about it.
So, if I want to rotate an object with coordinates different from its origin , I have just to apply the transformation after that the coordinates has been transformed from object coordinates to world coordinates (so that the origin change and it happens to be in the center of my sphere made of instances).
And I have to recalculate the normals.
Can you suggest me some specific material or source to look at, to study a bit more in depth the topic?
Thanks in advance :slight_smile:

Hi there,

The idea is that ‘space is rotating’ when multiplying with a rotation matrix. All points are rotating around the origin. So if you first move points away from the origin, it makes a bigger circle.
I dont have a link to glsl/touchdesigner related sources, but check out 3blue1brown’s ‘the essence of linear algebra’. A very great series describes in a very graphical way about those transformations:

Cheers,
tim

1 Like

Ok. In the next days I am going to watch the videos you suggested me.
The example file you passed is great, thank you.
The first formula you gave me, in which the object is translated, rotated and then put back in place , is it assuming that I want to rotate my object like it would have been in its center but using a different point in space?

yes exactly… it’s like some object is at position (3,5,2)… if you would rotate those coordinates without translating it, it will rotate the object around (0,0,0)… but if you first move it to the origin, then rotate it, it will rotate around its own axis… afterwards translating it back to the position, would mean the pivot point is (3,5,2).
But after making the tox example I realize you don’t need to do it since P (the vertex position in object space) is already at 0,0,0… so rotating that before TDDeform() (the function that translate the object), will result in rotating around its own axis.

Definitely interesting channel 3blue1brown. He manages to explain quite some advanced math topics in very understandable language and visuals… I’ve learned (and still learning) alot through that channel…

Cheers,
tim