![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2005
Posts: 23
Rep Power: 0
![]() |
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, |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|