- 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.


