#include float y[5]={0,50,120,170,200}; float v[5]={50,30,45,31,33}; float pas; void ura() { float dt; int i; dt=0.1; for(i=1;i<6;i++) { y[i]=y[i]+v[i]*dt; } glutPostRedisplay(); glutTimerFunc(100, ura, 0); } float vozilo(float y, float pas) { glPushMatrix(); glColor3f(1.0, 1.0, 1.0); glTranslatef(pas, y, 0.5); glRectf(-2.0, 0.0, 2.0, 6.0); glPopMatrix(); } void display() { int i; glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glRotatef(-45.0, 0.0, 0.0, 1.0); glTranslatef(0.0, -1.0, 0.0); glScalef(0.004, 0.004, 0.004); glColor3f(0.0, 0.0, 0.0); glRectf(-4.0, 0.0, 4.0, 500.0); glTranslatef(0.0, -50.0, 0.0); for(i=1;i<6;i++) { if (i<5 && (y[i+1]-y[i])>10.0) pas=-2.0; else pas=2.0; vozilo(y[i], pas); } glPopMatrix(); glutSwapBuffers(); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE); glutCreateWindow("Avtocesta"); glClearColor(0.0, 0.5, 0.0, 0.0); glutDisplayFunc(display); glutTimerFunc(100, ura, 0); glutMainLoop(); return 0; }