The titles should really be how to rotate the orient attribute but spinning particles is more catchy. Rotation can be a tricky beast and when it comes to particles there are a bunch of ways to control their direction, and when you are stacking multiple rotations things can become a little hairy! I suggest using quaternions to control direction because the qmultiply function makes it very simple to modify the current orient.

Randomly oriented points

The above points have random orientation driven by a random @orient attribute. To rotate it around the z axis with the qmultiply we need to build the quaternion to multiply with. To do that we use the quaternion fuction building it with a vector axis and a float angle. The axis is z so (0,0,1) and the angle is set to @Time * $PI * 2 so that it make a full rotation each second. Finally the new vector4 we created gets multiplied with the orient and this is the result:

Here is was I described in code:

// make spin vector4 
vector axis = set(0,0,1);
float angle = @Time * $PI;
vector4 spin = quaternion(angle, axis);

// apply to orient attribute
@orient = qmultiply(@orient, spin);

The cool thing about this is that the new vector4 does not have to know anything about the incoming orient attribute and it can be applied in unil directions. To illustrate that here is the spin vector4 applied as the orient:

@orient = spin;

For there if you want to change the behaviour like pick a random axis or spin a different rates all you need to control is a unit vector direction and and a float angle. Here is one last example with a random axis and angle.

vector axis = set(0,0,0);
int randaxis = floor(rand(@ptnum+237.23*293)*3);

float spinseed = rand(@ptnum+38.43*8723.74);
float rate = fit01(spinseed, 0.1, 1);
float angle = (@Time * $PI * 2) * rate;

//spin quaternion
vector4 spin = quaternion(angle, axis);

@orient = qmultiply(@orient, spin);

Here is the HIP File enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *