Drawing a path...speed problem...

Hi…Im working on a project that has to do with elliptical trajectories of satellites…
My satellite is moving well(well, it looks like it is), the only thing is, i’d like to draw the path its taking.

This is what I have right now:

int mod = (counter-1)%360;
x5[mod]=x-rp;
y5[mod]=y;

glPointSize(20);
for(int i=0; i<mod; i++)
{
glBegin(GL_POINTS);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(x5[i],y5[i], 0);
glEnd();
if (counter>360)
{
for(int k=359; k>(mod); k–)
{
glBegin(GL_POINTS);
glVertex3f(x5[k],y5[k], 0);
glEnd();
}
}
counter++;

Technically, what it’s doing is drawing all the points until counter, everytime the screen refreshes, then, weh glDRAW() starts over, it redraws them all, plus the newest coordinate found.
Once counter hits 360(which represents the degrees, all around the ellipse), the loop starts over redrawing first, second, third,etc…, but another loops starts and redraws from last up until where my other loop is at…

I dont know if you guys get what i mean, but it’s not all complicated. In short, after one full revolution, one loop draws clockwise, and another draws counter clockwise untill it meets the satellite.

The reason i do this is because my program lets the user change the “initial speed” So i’d like the user to see the difference in the trajectory.

My problem is, once the second loop starts, the animation slows down…ALOT… Pretty obviud why, since it’s drawing about 720 points in one shot…not too mention a textured square(satellite), and a sphere…

I’d like to know if there’s a more efficient way of creating showing the trajectory, as it is being traced…

(BTW, with only one loop, at the end of one revolution, the trajectory erases, and starts over)

Thanx Alot!

Look into vertex arrays if your card supports them. Should be a lot faster though you will have to change your data from separate x array and y array to a combined x,y or x, y, z array.

Hmm…im not really sure what that is, but I dont want to take a chance…
I have to present this to my teacher on the computers in our lab, and I’m not sure what kind of hardware they’re supporting…

To tell you the truth, I dont really use their computers much, the place is always full…

hi,
i was working on 3D Radar Systems and found the same problem as that of urs.
My problem was when i wanted to display target on a new position that whole screen used to get refreshed.
to eliminate this i used some flags , while rendering a scene.
but still even to draw a small polyon(target), the mathematical calculations were repeated every time , which reduced the speed of the program enormously.
i still couldn’t fix this. If u get some idea on this please share it with me.
bye. siddu78

I guess I didn’t really look at your code all that well the first time around.

After counter >360, it is performing the inner loop each and everytime an outerloop is done. Which means redundant code… I would imagine it slows down speeds up slows down speeds up.

Example:

counter = 540
mod = 179
int test = 0;
for (i=0;i<mod;i++)
{
for(k=359;k>mod;k–)
{
test++;
}
}
printf(“test = %d”, test);

Output:
test = 32220

Somehow you need to take the k loop and put it on the same level as the i loop. Re-examine your code and change your algorithm.

[This message has been edited by shinpaughp (edited 04-14-2003).]

Originally posted by shinpaughp:
[b]
Example:

[quote]

counter = 540
mod = 179
int test = 0;
for (i=0;i<mod;i++)
{
for(k=359;k>mod;k–)
{
test++;
}
}
printf(“test = %d”, test);

Output:
test = 32220

[This message has been edited by shinpaughp (edited 04-14-2003).][/b][/QUOTE]

well, this doesnt really represent what im trying to do with my code, cause frm what i’ve seen up to now, my trajectory will show up all the time, only if i kinda print
it out twice. Once my old one, and once the new one. One going forwards with my satellite, the other backwards up to the satellite…

The point is that the inner loop is being run once in its entirety (all iterations) to every single iteration of the outer loop. In other words in that example the outer loop iterates 179 times while the inner loop is run 179 times when 1 time would have been enough or it iterates 179 * 180 = 32220 times (180 points rendered once for that counter as opposed to each of those 180 points being rerendered 179 times or 32220 times total for that counter = 540). Hence, the slow down. If I understand what you are trying to do you want no more than a total of 2 * 360 = 720 points max to show the 2 ellipses. But, if you do want that many points (10s of thousands) then use vertex arrays or place the glBegin and glEnd outside the main loop so there is only a single call to each as opposed to 1 set of calls per point which will speed it up somewhat but I’m not sure how much.

But, check the code you put in your original post and verify that it is what you think it should be. There are 3 left braces and only 2 right braces, so it could be you left one out by mistake causing my confusion if I am confused. I ended up putting it after the counter++.

[This message has been edited by shinpaughp (edited 04-14-2003).]

Hmm…you’re right, i’m missing a brace.
It’d be placed before counter++.

Thanx alot, ill see what I can do with what you just told me…except if what this algorithm does is print out 32200 points, what should i do to print out only 720?

[This message has been edited by Carlop (edited 04-15-2003).]

int mod = (counter-1)%360;
x5[mod]=x-rp;
y5[mod]=y;

glPointSize(20);
glColor3f(0.0f,0.0f,1.0f);
glBegin(GL_POINTS);
for(int i=0; i<mod; i++)
{
    glVertex3f(x5[i],y5[i], 0);
}
glColor3f(0.0f,1.0f,0.0f);
if (counter>360)
{
  for(int k=359; k>(mod); k--)
  {
glVertex3f(x5[k],y5[k], 0);
  }
}
glEnd();

counter++;

Not positive, but I think that should do it. The other wouldn’t do 32220 all the time… it would fluctuate between 360 and I think the max would be 32220 points. Anyway try it as above. You’ll probably need to make some adjustments to it.

WoW! Big difference in speed!
It’s not eactly what i had in mind as animation(the code you wrote, starts erasing the trajectory once half the ellipse is done), but to tell you the truth, I like yours alot better…
It has kind of a spiffy shooting star-type feel too it…

I also used what you did, and tried it out on my code, and there’s no hit on the performance either… So now i can give a choice for my teammates…

Thanx Alot!!!

[This message has been edited by Carlop (edited 04-15-2003).]

UPDATE:

HAHA! Opps…I just realised why theres a shooting start type effect to it…
I realised there were 2 counter++; in the code, so it would draw half the points…
But it’s still cool…

and the right way of doing it(the way you wrote it), is still just as fast!

Once again! Thanx Alot!

Glad it improved the speed. Again, you should modify it so it does do what you want. You could always have either or both loops draw all 360 points of the ellipses or whatever you need to do.

Good luck with it.