Hello, I am trying to implement a 3D game with a bicycle where the player has to avoid colisions. I am creating a “infinite” road with the following code:
glPushMatrix();
int count = 10;
glTranslatef(0.0, 0.0, road);
for (int i = 0; i < road; i++)
{
glBegin(GL_POLYGON);
glVertex3f(5, -1.0, count);
glVertex3f(5, -1.0, count - 10);
glVertex3f(-5, -1.0, count - 10);
glVertex3f(-5, -1.0, count);
glVertex3f(5, -1.0, count);
glEnd();
count = count - 10;
}
glPopMatrix();
The variable road is incremented by a keyboard action so I keep generating the road with no limit (it will not disappear).
Now I want to add some random obstacles on the road just like in normal race games. The problem is I cannot use rand() inside my drawScene because it will generate new positions for one obstacle every time and I cannot previously save random positions for my obstacles because I do not know how many obstacles I will have before a colision. Thanks in advance.