Fireworks Sample maths

BlitzMax Forums/BlitzMax Programming/Fireworks Sample maths

SillyPutty(Posted 2005) [#1]
Hi all

In the simonh folder, regarding the fireworks sample, I see the x and y updates are

// pos update
x+=sin(angle)*cos(angle)*speed
y+=cos(angle)*cos(angle)*speed

psuedo code that is.

I am familiar with the plain sin(angle) and cos(angle) update steps, my question is, why are the double cos(angle) steps included. The effect is cool, just trying to understand :)


ImaginaryHuman(Posted 2005) [#2]
Once you've worked out the coords to draw at using Cos(angle) and sin(angle), you have to multiply them by some amount so that they are not just in the range of 0.0 to 1.0 .... ie multiply by 50 and they are then plotted 50 pixels distance from the center. In this fireworks thing they just happen to multiply by a speed factor and by another number (cos(angle)).. ... just lets the speed change based on whether the particle is moving down or is flying up in the air.


ImaginaryHuman(Posted 2005) [#3]
Another way to do it would be to avoid Cos/Sin altogether and just have Floating point X and Y coords with Floating point Xadd and Yadd. You would then subtract a very small Floating point `gravity` variable from the Y coord and if you want air resistance in both directions you'd multiple like 0.99 or something by the Xadd and Yadd to diminish it a bit ... should have less influence than gravity though. Then you just need to add Xadd to X and Yadd to Y.


SillyPutty(Posted 2005) [#4]
ah ok that makes sense :)

i was thinking of adding another term to it, to effect the speed and randomness(sp) of the particle system.

Thanks AngelDaniel !