PDA

View Full Version : Particle creation expression algorithm


Aikiman
03-22-2012, 08:43 AM
Im playing around sticking particles to goalU and goalV on a planar surface but rather than have them randomly placed, I want them in an ordered fashion just as if I was to goal them to the vertices. The point is I dont want them on the vertices, I want them on the UVs.

Okay so I came up with a crude looking expression in creation (and it works) but Im wondering if there is a better algorithm out there. I guess I could try and call a procedure from outside but can this be done and is it wise?

The following code basically checks the particle ID using a series of if statements and adjusts parameters accordingly, the problem is I would need to write this out 20 times. It would be nice if it was more user friendly.


if(particleShape1.particleId<20) {
particleShape1.goalV=0;
particleShape1.goalU=linstep(0,19,particleShape1.particleId);
}

if(particleShape1.particleId>19 && particleShape1.particleId<40) {
particleShape1.goalV=0.05;
particleShape1.goalU=linstep(20,39,particleShape1.particleId);
}

if(particleShape1.particleId>39 && particleShape1.particleId<60) {
particleShape1.goalV=0.1;
particleShape1.goalU=linstep(40,59,particleShape1.particleId);
}

if(particleShape1.particleId>59 && particleShape1.particleId<80) {
particleShape1.goalV=0.15;
particleShape1.goalU=linstep(60,79,particleShape1.particleId);
}

if(particleShape1.particleId>79 && particleShape1.particleId<100) {
particleShape1.goalV=0.2;
particleShape1.goalU=linstep(80,99,particleShape1.particleId);
}

if(particleShape1.particleId>99 && particleShape1.particleId<120) {
particleShape1.goalV=0.25;
particleShape1.goalU=linstep(100,119,particleShape1.particleId);
}

haggi
03-22-2012, 09:28 AM
Is it correct that you want to create a grid of particles on your surfaces with 20 particles in u and 20 in v direction?

If yes than I'd try something like this:

float $uStep = (float)(particleId % 20)/20.0;
int $vInt = (int)((float)particleId /20.0);
float $vStep = (float)$vStep/20.0;

goalU = $uStep;
goalV = $vStep;


With the modulo sign (%), uStep should vary from 0 - 1.0 for every 20 particles and vStep goes from 0 - 1.0 as well but will increase only every 20th step.

Aikiman
03-22-2012, 10:01 AM
You make it look so easy, thanks heaps. :)

CGTalk Moderation
03-22-2012, 10:01 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.