Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 7th, 2005, 6:40 PM   #1
Konnor
Newbie
 
Join Date: Aug 2005
Posts: 23
Rep Power: 0 Konnor is on a distinguished road
Implementing a ball trail

I'd like to have a ball trail implemented in my openGL game (round circles of decreasing size behind the ship when it is moving).

The code I'm using to draw a cirlce is as follows

glBegin(GL_POLYGON);
    glColor3f(0.0, 1.0, 0.0);
    for(int i=0; i<360; i+=5)
    {
          float xcoord = Xtri + 2 * cos(i*(PI/180));
          float ycoord = Ytri + 2 * sin(i*(PI/180));
          glVertex2f(xcoord, ycoord);
    }
glEnd();

the 'Xtri' and 'Ytri' represent The position the circle is drawn and is constantly updated.

I can visualise it in my head but I cant get it down on paper. I (think) i need to store the old co-ordinates for the ball in an array (an array each for X and Y). What might the code for this look like? how can I shift the old co-ordinates through an array of say length 5, filling it will different old values? (the current X and Y values are being updated all the time when the user presses the arrow keys to move the ship round the screen).

Once I have the old values I can duplicate the code above and draw more circles behind the ship and smaller to give the trail effect.

Many thanks,
Konnor is offline   Reply With Quote
Old Dec 8th, 2005, 11:21 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I would personally use a queue. You can implement one yourself, or use the standard library's one (std::queue). When you're adding a new ring, enqueue a coordinate, and when you're removing one, dequeue it.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:03 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC