Bouncy bouncy
loop
for each particle
erase particle
position = position + velocity
velocity = velocity + acceleration
if position is below floor then velocity = (xv, -yv, zv)
draw particle
end of particle loop
end of main loop
Now, if you were to take a ball and drop it on the floor, you would notice that the ball does
not bounce back up to the same height you dropped it from. This is because the ball looses energy
when it hits the floor, and so the velocity it bounces with is less than that of the impact.
Again, this is quite easy to take into account in the algorithm. First you must decide how bouncy the ball is. The bouncyness can be represented by a number between 0 and 1. 0 being not at all bouncy, and 1 being perfectly bouncy. Call this value e.
loop
for each particle
erase particle
position = position + velocity
velocity = velocity + acceleration
if position is below floor then velocity = (xv*e, -yv*e, zv*e)
draw particle
end of particle loop
end of main loop
Some approximate values for e:
Where CosVect returns the cosine of the angle between two vectors, otherwise known as the Dot Product.
Click here do download a demonstration of bouncing dots