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
"Nicolás Brenner Léniz" <nbre...@ing.puc.cl> wrote in message news:39A84838...@ing.puc.cl...
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
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.
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