Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Drawing particle "tail" help please

167 views
Skip to first unread message

Nicolás Brenner Léniz

unread,
Aug 26, 2000, 3:00:00 AM8/26/00
to
Hi, I have an OpengGL program that displays a particle making a circular

trayectory, I want to add to this particle a nice "tail", for this I
have implemented a bidimensional array[200][3], to store the previous
200 coordenates of the particle (x, y and z), I have also implemented a
system to determine the "head" and "tail" of this array, so that I can
draw the tail in the right way. I'm using the GL_LINE_STRIP primitive to

draw the tail but I have a problem. I want to draw the tail in a way
that blends with the background at the end. I've manages to do this but
it doesn't work how I want it to, the tail is drawn once entirely, and
then it's drawn again, but it's always drawn entirely every 200
positions that the particle has gone through, not every but not every
time the particle changes it's coordenates.
I know that maybe I didn't explained myself very good, maybe I lack the
language to do it right, because english's not my native language, but
if you catch a glimpse of what the problem I'm trying to describe is,
please reply to this message. If you like I could send you the source
code so that you can try the program, it is very little and simple, or I

could even post it.
Well, thanks in advance for your time and help,
Nicolás Brenner


ZZ

unread,
Aug 27, 2000, 3:00:00 AM8/27/00
to
just keep on adding new particles at the head of the comet with an alpha of 1
every frame decrease the alpha by say 0.01 of all the particles in the comet
u can also enlarge them, shrink them whatever
when the alphas under 0 kill the particle
http://nate.scuzzy.net/programming.html got a particle demo on his site


"Nicolás Brenner Léniz" <nbre...@ing.puc.cl> wrote in message news:39A84838...@ing.puc.cl...

ZZ

unread,
Aug 27, 2000, 3:00:00 AM8/27/00
to
whoops as batman said when he was pushed out the window, should of mentioned u need some other things enabled

glColor4f(1,0,0,(maxAge-age)*(1./maxAge));
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable(GL_LIGHTING); // though not sure about this

zed

Rob R

unread,
Aug 27, 2000, 3:00:00 AM8/27/00
to
Sound's more like a problem with how the list is used rather than OpenGL.
My mind right now is screaming about you not looping the list! What I mean
is that you start the particle going and add the point to the list. As the
particle moves you add another point then draw the line back throught the
list to the beginning of the list. When your get to the end of the list you
start adding points at the baggining of the list again and then draw the
line from the current list pointer to the beggining of the list. The
problem is that now the list is actually above the list pointer!!! You have
to loop to the end of the list and go back down to the entry after the one
you just entered. If you don't do this then the tail will grow till it has
all 200 points then shrink to one and grow again. A bit of psedocode that
should work would be...

lastretriexeindex = particleindex;
retrieveindex = particleindex;
for(int i = 0;i < listlength-1; i++){
retrieveindes --;
if(retrieveindex < 0) retrieveindex += listlength;
// draw line from lastretrieveindex to retrieve index
lastretriexeindex = retrieveindex;
}

One point to remember with this though!!!! You have to initialize the list
so that all the points are the same as the particles starting poing or
you'll start with a random mess of lines from the uninitialized data in the
list. with all the points the same the line will end up being drawn as one
point.

Nicolás Brenner Léniz

unread,
Aug 27, 2000, 3:00:00 AM8/27/00
to
Thank you very much, this is the kind of help I was looking for, I know how to
draw the tail, and how to make it fade on to the background, gradually
changing the color of the tail to the color of the background, but I was
looking for a way not to mess with the color of the tail.
I haven't tried your solution yet, I'll go try it and then tell you back how
did I do with it, thanks again.

Tim Auld

unread,
Aug 28, 2000, 3:00:00 AM8/28/00
to
I have written exactly what you are describing with a bit more. Instead of
using a line to draw the tail I rotated a quad strip to face the camera. It
looks very nice for missile and engine smoke trails. You can see some
screenshots at http://www.tne.net.au/astro/projects/spacegame/index.html

or these links are more specific:

http://www.tne.net.au/astro/projects/spacegame/trail.jpg
http://www.tne.net.au/astro/projects/spacegame/sun.jpg

The trick here is that your array is actually a circular queue. It has a
head and a tail. The way I modelled it is as follows:

- start with head and tail being the same index (zero)

- After a period of time and the particle has moved a minimum distance add
the position and time of creation at the head and move the head along one.
If you collide with the tail then advance the tail.

- If the current time minus the creation time of a keyframe is longer than
the time length of the tail then remove the keyframe and advance the tail of
the array. This way the tail will naturally shorten if it's sitting still.

I may not be quite with you so I'll cover that base. If your problem is
accidently drawing all 200 keyframes when there aren't 200 meaningful
keyframes, then just loop from the array tail to the array head, drawing
each segment of the line. At the start the head and the tail will be equal
so you won't draw anything. When you have one keyframe you can't draw
anything either. When there are two keyframes you can draw a line between
them. And so on. You can use the distance from the head of the array to
determine the alpha, using glColor4f(). But if you record the time the
keyframe was created it will make sense when you don't make many keyframes
because the particle doesn't move far enough each period (this is just an
optimisation I made).

Also note that I am linearly interpolating between the tail keyframe and the
next from tail keyframe according to the current time minus the trail time
length and the times of the two keyframes. This makes the end of the tail
move smoothly instead of just popping out when the keyframe is removed. You
also have to draw a line from the last keyframe recorded to the current
position of the particle, or else you'll see a gap popping between the
particle and the tail.

Here is a diagram of what I mean (hopefully it turns out!)

[ = actual end point
| = keyframe
>==> = particle

[--------|--------|--------|--------|>==>

|[-------|--------|--------|--------|->==>

| [------|--------|--------|--------|-->==>

| [-----|--------|--------|--------|--->==>

| [----|--------|--------|--------|---->==>

| [---|--------|--------|--------|----->==>

| [--|--------|--------|--------|------>==>

| [-|--------|--------|--------|------->==>

| [|--------|--------|--------|-------->==>

[--------|--------|--------|--------|>==>


A little problem that stumped me for a while was that the alpha was
flickering. I was hardcoding the tail index to zero alpha and interpolating
the alpha and tail positions properly, but it was still flickering. I
worked out that you actually need two extra keyframes than what you would
expect, because of the end points. Hard to explain, but keep it in mind if
you do anything like this.

Hope this helps. If not post some more specific questions or email me in
private.

Tim Auld

0 new messages