[2.3👍] Coures affichées
Fonctions déjà implémentées pour l'exo 2.4
On parle pas du bug 🤫
This commit is contained in:
parent
8976b8e75b
commit
d2789fadfc
68
main.c
68
main.c
@ -5,12 +5,14 @@
|
||||
#include <GL/glut.h>
|
||||
|
||||
void afficher(void);
|
||||
int initWindow(int, char**);
|
||||
int initWindow(int, char**, void(*)(void));
|
||||
void destroyWindow(int);
|
||||
long getFileSize(FILE*);
|
||||
void parseFile(char*, long);
|
||||
bool charger(char*);
|
||||
void printCourbeTerminal(void);
|
||||
void ligne(int);
|
||||
float map(float, float, float, float, float);
|
||||
|
||||
// Variables donneés
|
||||
#define MAXC 20
|
||||
@ -22,24 +24,53 @@ float valmax[MAXC];
|
||||
int nc = 0;
|
||||
|
||||
|
||||
void afficher(void)
|
||||
float map(float smin, float smax, float val, float omin, float omax)
|
||||
{
|
||||
float percent = (val - smin) / (smax - smin);
|
||||
//printf("v%f, p%f, min%f, max%f\n", val, percent, omin, omax);
|
||||
return (omax-omin) * percent + omin;
|
||||
}
|
||||
|
||||
void ligne(int index)
|
||||
{
|
||||
if(index >= nc)
|
||||
{
|
||||
printf("Courbe non-existante.");
|
||||
return;
|
||||
}
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
|
||||
glClearColor(0.0,0.0,0.0,0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glColor3f(1.0,1.0,1.0);
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex2f(-0.7,-0.7);
|
||||
glVertex2f(-0.7, 0.7);
|
||||
glVertex2f( 0.7, 0.7);
|
||||
glVertex2f( 0.7,-0.7);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
|
||||
unsigned int size = (unsigned int)courbe[index][0];
|
||||
|
||||
for(unsigned int i = 1; i < size; 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);
|
||||
//printf("%d : {%f, %f}\n", i, pos_x, pos_y);
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void afficher(void)
|
||||
{
|
||||
glClearColor(0.0,0.0,0.0,0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
ligne(0);
|
||||
|
||||
glFlush();
|
||||
}
|
||||
|
||||
int initWindow(int argc, char* argv[])
|
||||
int initWindow(int argc, char* argv[], void(*display)(void))
|
||||
{
|
||||
int vx1 = 0, vx2 = 400, vy1 = 0, vy2 = 400;
|
||||
|
||||
@ -50,7 +81,7 @@ int initWindow(int argc, char* argv[])
|
||||
|
||||
int window = glutCreateWindow("TP1");
|
||||
|
||||
glutDisplayFunc(afficher);
|
||||
glutDisplayFunc(display);
|
||||
|
||||
return window;
|
||||
}
|
||||
@ -86,16 +117,17 @@ void parseFile(char* file, long size)
|
||||
// printf(" ->\"%c\"", *pointeur);
|
||||
|
||||
int taille_tableau = atoi(pointeur);
|
||||
courbe[line][0] = taille_tableau;
|
||||
// printf(" ->\"%d\" \n", taille_tableau);
|
||||
|
||||
// On suppose que les nombres sont séparés par un espace
|
||||
for(unsigned int i = 0; i < taille_tableau; i++)
|
||||
for(unsigned int i = 1; i < taille_tableau; i++)
|
||||
{
|
||||
pointeur = strchr(pointeur, ' ') + 1;
|
||||
float num = strtof(pointeur, 0);
|
||||
courbe[line][i] = num;
|
||||
|
||||
if(i == 0)
|
||||
if(i == 1)
|
||||
{
|
||||
valmin[line] = num;
|
||||
valmax[line] = num;
|
||||
@ -163,15 +195,15 @@ void printCourbeTerminal(void)
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
//int window = initWindow(argc, argv);
|
||||
|
||||
//glutMainLoop();
|
||||
|
||||
if(!charger("valeurs.txt"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
//printCourbeTerminal();
|
||||
|
||||
//destroyWindow(window);
|
||||
int window = initWindow(argc, argv, afficher);
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
destroyWindow(window);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
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
|
||||
5 1 2 3 4 5
|
||||
6 21 543.3 75 34 76 89
|
||||
1 234
|
||||
|
Loading…
Reference in New Issue
Block a user