Projectile emission

Features/Funtions you would like to see in Particle Designer

Projectile emission

Postby Lazer » Sat May 28, 2011 10:53 pm

I updated the Particle Emitter code from the book to allow for particles that have different gravities. This allows all particles that are emitted to go to the same point (think having multiple fireballs leave a spot in different directions, with different velocities and all end up at the same point). I figured I'd share the code here, and since it's pretty simple see if you think it'd be a good feature for the next Particle Designer.

Code: Select all
//This is added code for projectiles.
   if (isProjectileEmitter == YES) {
      aParticle->gravity = gravity;
      GLfloat gravityX = (2 * (destination.x - aParticle->position.x - ((aParticle->direction.x) * aParticle->timeToLive)) / (powf(aParticle->timeToLive, 2)));
      GLfloat gravityY = (2 * (destination.y - aParticle->position.y - ((aParticle->direction.y) * aParticle->timeToLive)) / (powf(aParticle->timeToLive, 2)));
      gravity = Vector2fMake(gravityX, gravityY);
   }
   
   aParticle->gravity = gravity;
   //End projectile code


The direction vector for a particle is it's velocity, so using the velocity, source position, and end position this calculates the necessary acceleration vector which is the gravity property. In order to update correctly, you just change updateWithDelta from:

Code: Select all
Vector2f tmp = Vector2fMultiply(gravity, aDelta);

To:

Code: Select all
Vector2f tmp = Vector2fMultiply(currentParticle->gravity, aDelta);


And add Vector2f gravity to the particle struct. Just add an init method that sets the destination and all your particles will look like they're being sucked into a black hole at that point.
Lazer
 
Posts: 7
Joined: Sat May 28, 2011 8:20 pm

Re: Projectile emission

Postby mike » Tue May 31, 2011 4:56 pm

Nice update and I've put it on the list for Particle Designer 2.0 :D

Mike
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm


Return to Feature Suggestions

Who is online

Users browsing this forum: No registered users and 2 guests

cron