make particles rotate around the y axis of the scene using jit.gen

Florent's icon

Hello, I have made a particles system using mainly jit.noise, jit.gl.mesh and jit.gen to make them move.

Now I'm trying to add rotation : I'd like to be able to make the particles rotate at different speeds around the y axis depending on their position.

Can you help me ?

I dont know how I can apply a different rotation to each particle inside of jit.gen. I only animate for the moment the whole mesh using the message "rotatexyz".

Graham Wakefield's icon

I recommend using quaternions to represent particle orientation, and also to apply rotations. You can store individual particle orientation quaternions in a 4-plane matrix. You can also do this for particle rotations (i.e. rotational velocity), or you could use a shared param for that. jit.gen has a [qrot] object for rotating a vector by a quaternion, which you could use to rotate a forward vector (e.g. 0,0,-1 for the local Z axis) by the particle's orientation, to give you the direction vector for movement, and scale that by particle speed to get the particle velocity. There's a [qmul] object to rotate one quaternion by another, which you could use to apply a rotation to each particle's orientation. Both of these are demonstrated in the patcher below.

Note that jit.gen by default uses the same plane count on all inputs/outputs, so I've set the position vectors to also be 4-plane (the 4th component is set to 1.0 by default, which is pretty much how it works in OpenGL anyway).

Max Patch
Copy patch and select New From Clipboard in Max.

Florent's icon

Hello,

Thank you for your help. I will need time to fully understand your patch but it looks promising!

I tried to rotate my particles using another technique for the moment as you can see in the patch attached to this post.

The rotation works as expected but with the expression I'm using the particles get pulled away from the center.

Do you know how I can continue to animate the rotation whithout pulling away the particles from the center ?

define_matrix_using_uzi_002_forum.maxpat
Max Patch