[2.4👍] Redimensionner l'affichage

This commit is contained in:
Theo 2024-09-09 09:36:36 +02:00
parent d2789fadfc
commit cdf981263b
2 changed files with 30 additions and 16 deletions

44
main.c
View File

@ -11,8 +11,9 @@ long getFileSize(FILE*);
void parseFile(char*, long); void parseFile(char*, long);
bool charger(char*); bool charger(char*);
void printCourbeTerminal(void); void printCourbeTerminal(void);
void ligne(int); void ligne(int, float, float, float, float);
float map(float, float, float, float, float); float map(float, float, float, float, float);
void reshapeCallback(int, int);
// Variables donneés // Variables donneés
#define MAXC 20 #define MAXC 20
@ -23,6 +24,8 @@ float valmin[MAXC];
float valmax[MAXC]; float valmax[MAXC];
int nc = 0; 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) 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; return (omax-omin) * percent + omin;
} }
void ligne(int index) void ligne(int index, float hgx, float hgy, float bdx, float bdy)
{ {
if(index >= nc) if(index >= nc)
{ {
@ -47,12 +50,12 @@ void ligne(int index)
unsigned int size = (unsigned int)courbe[index][0]; 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_x = map(0, size-1, i-1, hgx, bdx);
float pos_y = map(valmin[index], valmax[index], courbe[index][i], -1.0, 1.0); float pos_y = map(valmin[index], valmax[index], courbe[index][i], bdy, hgy);
glVertex2f(pos_x, pos_y);
//printf("%d : {%f, %f}\n", i, pos_x, pos_y); //printf("%d : {%f, %f}\n", i, pos_x, pos_y);
glVertex2f(pos_x, pos_y);
} }
fflush(stdout); fflush(stdout);
@ -65,15 +68,24 @@ void afficher(void)
glClearColor(0.0,0.0,0.0,0.0); glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
ligne(0); ligne(0, -1.0, 1.0, 1.0, 0);
glFlush(); 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 initWindow(int argc, char* argv[], void(*display)(void))
{ {
int vx1 = 0, vx2 = 400, vy1 = 0, vy2 = 400;
glutInit(&argc, argv); glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
glutInitWindowPosition(vx1, vy1); glutInitWindowPosition(vx1, vy1);
@ -83,6 +95,8 @@ int initWindow(int argc, char* argv[], void(*display)(void))
glutDisplayFunc(display); glutDisplayFunc(display);
glutReshapeFunc(reshapeCallback);
return window; return window;
} }
@ -104,7 +118,7 @@ void parseFile(char* file, long size)
nc = atoi(file); nc = atoi(file);
printf("nc=%d\n", nc); printf("nc=%d\n", nc);
printf("====\n%s\n====\n", file); //printf("====\n%s\n====\n", file);
// Pointeur mobile dans le fichier // Pointeur mobile dans le fichier
char* pointeur = file; char* pointeur = file;
@ -121,7 +135,7 @@ void parseFile(char* file, long size)
// printf(" ->\"%d\" \n", taille_tableau); // printf(" ->\"%d\" \n", taille_tableau);
// On suppose que les nombres sont séparés par un espace // 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; pointeur = strchr(pointeur, ' ') + 1;
float num = strtof(pointeur, 0); float num = strtof(pointeur, 0);
@ -181,12 +195,12 @@ bool charger(char* nom)
void printCourbeTerminal(void) 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]); printf("%f", courbe[i][j]);
if(j < MAXV-1) if(j < courbe[i][0])
printf(", "); printf(", ");
} }
printf("\n"); printf("\n");
@ -198,7 +212,7 @@ int main(int argc, char* argv[])
if(!charger("valeurs.txt")) if(!charger("valeurs.txt"))
return EXIT_FAILURE; return EXIT_FAILURE;
//printCourbeTerminal(); printCourbeTerminal();
int window = initWindow(argc, argv, afficher); int window = initWindow(argc, argv, afficher);

View File

@ -1,5 +1,5 @@
6 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 5 1 2 3 4 5
6 21 543.3 75 34 76 89 6 21 543.3 75 34 76 89
1 234 1 234