Archived

This topic is now archived and is closed to further replies.

mickey

how do you make those particles move in patterns?

Recommended Posts

hello, like for example move in a letter ''S'' or ''W'' pattern or just about to move in any way you want, just like how the space ship move in a space shooter game, many thanks,

Share this post


Link to post
Share on other sites
Usually for special effect like that you hardcode in a pattern that particles move along. Another method, if you just want to make an S or W is to add a bunch of line emitters in the shape of your patter. And still a third, although somewhat difficult way to do things is to have some kind of invisible gravity volume in space that affects the movement of particles. My engine does not support those at this time. See my engine here

(I never miss a chance to show off my work



Gamedev for learning.
libGDN for putting it all together.

Share this post


Link to post
Share on other sites
An S pattern can be formed by a sinusoidal function like, for instance, sine!

A W pattern can be formed by Sin[sup]-1[/sup](sin x) ... (inverse Sin of (sin x))

(Of course you would need to restrict the domains of these functions, else they will keep going on for ever and ever, due to their inherent cyclic nature)

There is probably some mathematical way to describe any path you could think of, and if mathematics fails you (heaven forbid!) then you can always just hard code it, as CpMan suggested.

Share this post


Link to post
Share on other sites
no hard code plz, it''s not the most intuitive of all,

CpMan: yepz i already saw your work on your post at the dx forum, could you tell me how you did the letter M or what are those shapes something functions are for so it''ll be easier for me to understand your code?

i think all these is just a matter of changing the velocity and we can make ''all'' kinds of movements we want..., but still very vague for me,

thnaks,

Share this post


Link to post
Share on other sites
I dont know whether u are asking for this or not... so i''m just assuming.

create a texture [ preferably a bmp pic ] with a letter ''W'' written on it and the rest part black. Now load the texture in GL_RGBA format and assign alpha as 0 wherever there are "black" pixel 255 otherwise.

now render the rect with the texturing by enabling GL_DEPTH_TEST and with glAlphaFunc(GL_GREATER,0);

To rotate and move the letter, all u have to do is aply transformations on the rect only, just as u would do with any other geom figures

Is that what u were looking for ?

Share this post


Link to post
Share on other sites
Define a few points, say, for the letter ''W'', you define 5 points. Now, you write some function to simulate natural behaviour to follow the points in order, from point #0 to point #1, then point #2 etc. The function can depend on environment, speed, direction or even random numbers Trick around a little, we all need new ideas.

Share this post


Link to post
Share on other sites
To get any pattern you want...

Sounds awfully like a fourier transform! I''ve only had 4 weeks of lectures on them so far though so asking me to produce maths would be quite tricky :-)

However to get a nice representation of the pattern would take a lot of processing (tens, hundreds or even thousands of sines/cosines).

You could pregenerate the path by sampling the transform every so far along but then you could always just hardcode the path instead and interpolate which will be a lot *lot* less intensive.

Anyway my 2 pence :-)

-Meto

Share this post


Link to post
Share on other sites
Rather than using repeating patterns, have you considered using flocking of some sort? Look into Craig Reynold''s Steering behaviors (homefully I remembered the name correctly).

If you don''t want enemy spaceships to stick together in a flock, maybe you could try just a random wandering behavior. Wandering is simple.

Each particle is always moving forward at a constant speed. It can steer left, right, up, and down. For simplicity, I''ll stick to the 2d case and just use left and right. Now, take a single particle. Imagine that a random angle, alpha, is associated with it. The particle is oriented at an angle theta, and can turn at a specific speed. Every timestep, it turns, bringing theta closer to alpha. But here''s the catch: every timestep, a small random amount is added to or subtracted from alpha. This results in a wandering behavior which may be useful.

For more info, check out steering behaviors.

Share this post


Link to post
Share on other sites