[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);
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);

View File

@ -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