Flying flag : code/algorithm anyone ?

BlitzMax Forums/BlitzMax Beginners Area/Flying flag : code/algorithm anyone ?

DannyD(Posted 2005) [#1]
Wondering if anyone has coded an animated flag as if it was flying in the wind ? The flag I'd like to use would have three colors in horizontal layout. Anyone done this or got any tips ? THanks in advance.


DannyD(Posted 2005) [#2]
It would also be nice to animate an image in the same way as a flag.


ImaginaryHuman(Posted 2005) [#3]
Well. It really depends on how accurate you want to simulate the motion of air passing over the cloth. To do a full simulation would be kind of complicated. I figure you would settle for something that looks half decent?

You should look to using sine waves. However, I'm really not sure what would be the best way to go about doing this in BlitzMax. You could, most simply, chop your flag into lots of verticle strips, and then move each strip vertically, individually, with the sine wave moving from left to right (ie use something like sin(angle)*30 or whatever). If the movement isn't too extreme it will look okay.


DannyD(Posted 2005) [#4]
Thanks for the advice.I'm not to pushed as how realistic it appears as long as it looks like a flag in the breeze.I'll give sin waves a go.Thanks again.


ImaginaryHuman(Posted 2005) [#5]
Are we talking about a big flag or just some small thing?


DannyD(Posted 2005) [#6]
Perhaps 1/8 of the screen or even 1/2 of the screen.


DannyD(Posted 2006) [#7]
something similar to a sine scroller.


ImaginaryHuman(Posted 2006) [#8]
Depends whether you are coding OpenGL or Max2D.

In Open GL i'd have a texture with the image on it, then just draw quads, one for each column, adjusting the texture coordinates to show only a given column from the texture, for each column. And as you say, just have a sinewave with an offset that changes to make it move. That'd wiggle it horizontally.

To do it vertically as well, ideally you'd want to grab the drawn flag into another texture (or render to texture first), and then draw horizontal strips with another sinewave of offsets. That'd get it wiggling pretty good.

But even then it's not going to really look like a real flag in the wind with different shaped ripples progressing over the cloth, creating dynamic curves and shapes etc. For that you'd need a cloth simulator with a bunch of springs and maybe make it out of a grid of small quads, moving the vertices around to stretch it.