void vegetation::drawBranche(int p,float taille){ // Fonction récursive pour tracer les branches en fonction de celle d'avant float x,y; if (p==1){ for(int i=0;i<3;i++){ if (i==0){ x=1,y=0; }else if(i==1){ x=-0.5,y=r3s2; }else { x=-0.5,y=-r3s2; } glPushMatrix(); glColor3f(0.27,0.55,0); glTranslatef(0,0,taille*5); glRotatef(-40, x,y,0.0); drawCylindre(taille*1.7,taille*7); glPopMatrix(); } return; } for(int i=0;i<3;i++){ if (i==0){ x=1,y=0; }else if(i==1){ x=-0.5,y=r3s2; }else { x=-0.5,y=-r3s2; } glPushMatrix(); glColor3f(0.36+(7-p)*0.05, 0.24+(7-p)*0.05, 0.07+(7-p)*0.05); glTranslatef(0,0,taille*5*p); glRotatef(-40, x,y,0.0); drawCylindre(taille*p/4,taille*p*5); drawBranche( p-1,taille); glPopMatrix(); } }
void vegetation::drawArbre(float x,float y,float taille){ glPushMatrix(); glTranslatef(x,y,0); glColor3f(0.36, 0.24, 0.07); glPushMatrix(); drawCylindre(taille/2,taille*5); glPopMatrix(); drawBranche(4, taille/4); glPopMatrix(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); cam_position[0] = cam_radius * sin(cam_phi) * sin(cam_theta); cam_position[1] = cam_radius * cos(cam_phi); cam_position[2] = cam_radius * sin(cam_phi) * cos(cam_theta); gluLookAt(cam_position[0],cam_position[1],cam_position[2], cam_target[0], cam_target[1], cam_target[2], cam_up[0], cam_up[1], cam_up[2]); showReferenceAxis(); glColor3f(1.0, 1.0, 1.0); glPushMatrix(); glTranslatef(0.0,0, -2.0); //glRotatef(90,1,0,0); for(int i =0; i<10;i++) { glTranslatef(0.1*i , 0 , 0); drawCylindre(2.0,1.0,3); } glPopMatrix(); //Sleep(5); glutSwapBuffers(); }