From cdf981263ba3b96bed233457b94d00b19403c84a Mon Sep 17 00:00:00 2001 From: Theo Date: Mon, 9 Sep 2024 09:36:36 +0200 Subject: [PATCH] =?UTF-8?q?[2.4=F0=9F=91=8D]=20Redimensionner=20l'affichag?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 44 +++++++++++++++++++++++++++++--------------- valeurs.txt | 2 +- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/main.c b/main.c index fbece75..c7a1729 100644 --- a/main.c +++ b/main.c @@ -11,8 +11,9 @@ long getFileSize(FILE*); void parseFile(char*, long); bool charger(char*); void printCourbeTerminal(void); -void ligne(int); +void ligne(int, float, float, float, float); float map(float, float, float, float, float); +void reshapeCallback(int, int); // Variables donneés #define MAXC 20 @@ -23,6 +24,8 @@ float valmin[MAXC]; float valmax[MAXC]; int nc = 0; +// Variables globales +int vx1 = 0, vx2 = 400, vy1 = 0, vy2 = 400; float map(float smin, float smax, float val, float omin, float omax) { @@ -31,7 +34,7 @@ float map(float smin, float smax, float val, float omin, float omax) return (omax-omin) * percent + omin; } -void ligne(int index) +void ligne(int index, float hgx, float hgy, float bdx, float bdy) { if(index >= nc) { @@ -47,12 +50,12 @@ void ligne(int index) unsigned int size = (unsigned int)courbe[index][0]; - for(unsigned int i = 1; i < size; i++) + for(unsigned int i = 1; i < size+1; i++) { - float pos_x = map(0, size, i-1, -1.0, 1.0); - float pos_y = map(valmin[index], valmax[index], courbe[index][i], -1.0, 1.0); - glVertex2f(pos_x, pos_y); + float pos_x = map(0, size-1, i-1, hgx, bdx); + float pos_y = map(valmin[index], valmax[index], courbe[index][i], bdy, hgy); //printf("%d : {%f, %f}\n", i, pos_x, pos_y); + glVertex2f(pos_x, pos_y); } fflush(stdout); @@ -65,15 +68,24 @@ void afficher(void) glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT); - ligne(0); + ligne(0, -1.0, 1.0, 1.0, 0); glFlush(); } +void reshapeCallback(int largeur, int hauteur) +{ + vx2 = largeur; + vy2 = hauteur; + + glViewport(0, 0, largeur, hauteur); + //glutPostRedisplay(); + + printf("Reshape : [%d, %d]\n", vx2, vy2); +} + int initWindow(int argc, char* argv[], void(*display)(void)) { - int vx1 = 0, vx2 = 400, vy1 = 0, vy2 = 400; - glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA); glutInitWindowPosition(vx1, vy1); @@ -83,6 +95,8 @@ int initWindow(int argc, char* argv[], void(*display)(void)) glutDisplayFunc(display); + glutReshapeFunc(reshapeCallback); + return window; } @@ -104,7 +118,7 @@ void parseFile(char* file, long size) nc = atoi(file); printf("nc=%d\n", nc); - printf("====\n%s\n====\n", file); + //printf("====\n%s\n====\n", file); // Pointeur mobile dans le fichier char* pointeur = file; @@ -121,7 +135,7 @@ void parseFile(char* file, long size) // printf(" ->\"%d\" \n", taille_tableau); // On suppose que les nombres sont séparés par un espace - for(unsigned int i = 1; i < taille_tableau; i++) + for(unsigned int i = 1; i < taille_tableau+1; i++) { pointeur = strchr(pointeur, ' ') + 1; float num = strtof(pointeur, 0); @@ -181,12 +195,12 @@ bool charger(char* nom) void printCourbeTerminal(void) { - for(unsigned int i = 0; i < MAXC; i++) + for(unsigned int i = 0; i < nc; i++) { - for(unsigned int j = 0; j < MAXV; j++) + for(unsigned int j = 0; j < courbe[i][0]+1; j++) { printf("%f", courbe[i][j]); - if(j < MAXV-1) + if(j < courbe[i][0]) printf(", "); } printf("\n"); @@ -198,7 +212,7 @@ int main(int argc, char* argv[]) if(!charger("valeurs.txt")) return EXIT_FAILURE; - //printCourbeTerminal(); + printCourbeTerminal(); int window = initWindow(argc, argv, afficher); diff --git a/valeurs.txt b/valeurs.txt index ddfe9af..55139ed 100644 --- a/valeurs.txt +++ b/valeurs.txt @@ -1,5 +1,5 @@ 6 -46 0.978147601 0.913545458 0.809016994 0.669130606 0.5 0.309016994 0.104528463 -0.104528463 -0.309016994 -0.5 -0.669130606 -0.809016994 -0.913545458 -0.978147601 -1 -0.978147601 -0.913545458 -0.809016994 -0.669130606 -0.5 -0.309016994 -0.104528463 0.104528463 0.309016994 0.5 0.669130606 0.809016994 0.913545458 0.978147601 1 0.978147601 0.913545458 0.809016994 0.669130606 0.5 0.309016994 0.104528463 -0.104528463 -0.309016994 -0.5 -0.669130606 -0.809016994 -0.913545458 -0.978147601 -1 +45 0.978147601 0.913545458 0.809016994 0.669130606 0.5 0.309016994 0.104528463 -0.104528463 -0.309016994 -0.5 -0.669130606 -0.809016994 -0.913545458 -0.978147601 -1 -0.978147601 -0.913545458 -0.809016994 -0.669130606 -0.5 -0.309016994 -0.104528463 0.104528463 0.309016994 0.5 0.669130606 0.809016994 0.913545458 0.978147601 1 0.978147601 0.913545458 0.809016994 0.669130606 0.5 0.309016994 0.104528463 -0.104528463 -0.309016994 -0.5 -0.669130606 -0.809016994 -0.913545458 -0.978147601 -1 5 1 2 3 4 5 6 21 543.3 75 34 76 89 1 234