# Making particles accelerate toward a mouse point

I'm currently working on a particle simulation program that makes pixels move towards a mouse point continually accelerating, but i'm running into some math issues. Currently my particle will accelerate in the direction of the mouse point, but will not actually accelerate towards a given point(only in it's direction).

To get an idea of what I'm trying to accomplish, my older program does just this but uses the fixed function pipeline. I want to recreate this program using the programmable pipeline and as a result changed around a lot of the program, there is really no similar code between the two at this point. Example of my problem:

As you can see the particle only accelerate in the direction of the cursor, my main equation I'm using is:

//if left mouse button is pressed
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)){
p.speed += glm::vec3(-pos.x * 30, -pos.y * 30 ,0.0f);   //increase speed in direction
}
//update position of particle with a little bit of spread -- speed(dt) * DRAG * Rand
p.pos += p.speed * (float)(delta) * DRAG * glm::vec3(rand()%5,rand()%5,0);


where my particle struct is:

struct Particle{
glm::vec3 pos, speed;       //position, speed
unsigned char r,g,b,a;      //color
float size, angle, weight;  //?
float life;                 //remaining life of a particle, if <0 it's super dead

//used for std::sort, needs an overloaded comparison operator
bool operator<(const Particle& that) const {
}
};


how would I go about simulating the behavior of my first program with this second program I'm writing? I can't seem to wrap my head around doing this as the program structure is so drastically different.

• Currently my particle will accelerate in the direction of the mouse point, but will not actually accelerate towards a given point(only in it's direction). I don't really understand your problem can you please clarify it? Commented May 20, 2014 at 7:50
• @concept3d I think he means that the particles don't stop when they reach the point where the mouse cursor is located, but keep moving (and accelerating) beyond that point. Commented May 20, 2014 at 12:20

foreach particle: