🔥 TP Terminé 🔥
This commit is contained in:
parent
3fb8528c1f
commit
3b19bde79e
96
main.c
96
main.c
@ -15,6 +15,7 @@ void ligne(int, float, float, float, float);
|
||||
float map(float, float, float, float, float);
|
||||
void reshapeCallback(int, int);
|
||||
void axes(float, float, float, float);
|
||||
void histo(int, float, float, float, float);
|
||||
|
||||
// Variables donneés
|
||||
#define MAXC 20
|
||||
@ -30,9 +31,14 @@ int nc = 0;
|
||||
#define VERTICAL 1
|
||||
#define SUPERPOSER 2
|
||||
|
||||
#define LIGNE 0
|
||||
#define LIGNE_AXES 1
|
||||
#define HISTOGRAMME 2 // pas un vrai histogramme
|
||||
|
||||
// Variables globales
|
||||
int vx1 = 0, vx2 = 400, vy1 = 0, vy2 = 400;
|
||||
int mode_affichage = HORIZONTAL;
|
||||
int type_dessin = LIGNE;
|
||||
|
||||
float map(float smin, float smax, float val, float omin, float omax)
|
||||
{
|
||||
@ -92,20 +98,65 @@ void ligne(int index, float hgx, float hgy, float bdx, float bdy)
|
||||
|
||||
glEnd();
|
||||
|
||||
for(unsigned int i = 1; i < size+1; i++)
|
||||
if(type_dessin == LIGNE_AXES)
|
||||
{
|
||||
float pos_x = map(0, size-1, i-1, hgx, bdx);
|
||||
float pos_y = map(valmin[index], valmax[index], courbe[index][i], bdy, hgy);
|
||||
if(mode_affichage == VERTICAL)
|
||||
for(unsigned int i = 1; i < size+1; i++)
|
||||
{
|
||||
axes(bdy, pos_y, hgx, pos_x);
|
||||
}else{
|
||||
axes(hgx, pos_x, bdy, 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);
|
||||
if(mode_affichage == VERTICAL)
|
||||
{
|
||||
axes(bdy, pos_y, hgx, pos_x);
|
||||
}else{
|
||||
axes(hgx, pos_x, bdy, pos_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void histo(int index, float hgx, float hgy, float bdx, float bdy)
|
||||
{
|
||||
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);
|
||||
glColor3f(1.0,1.0,1.0);
|
||||
//glBegin(GL_POLYGON);
|
||||
|
||||
unsigned int size = (unsigned int)courbe[index][0];
|
||||
|
||||
for(unsigned int i = 1; i < size+1; i++)
|
||||
{
|
||||
float gauche = map(0, size, i-1, hgx, bdx);
|
||||
float droite = map(0, size, i, hgx, bdx);
|
||||
float haut = map(valmin[index], valmax[index], courbe[index][i], bdy, hgy);
|
||||
float bas = bdy;
|
||||
|
||||
if(mode_affichage == VERTICAL)
|
||||
{
|
||||
float temp = bas;
|
||||
bas = gauche;
|
||||
gauche = haut;
|
||||
haut = droite;
|
||||
droite = temp;
|
||||
}
|
||||
|
||||
glRectf(gauche, haut, droite, bas);
|
||||
//printf("%d : {g%f, h%f, b%f, d%f}\n", i, gauche, haut, droite, bas);
|
||||
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
//glEnd();
|
||||
}
|
||||
|
||||
void afficher(void)
|
||||
{
|
||||
glClearColor(0.0,0.0,0.0,0.0);
|
||||
@ -117,7 +168,13 @@ void afficher(void)
|
||||
{
|
||||
float haut = map(0, nc, i-1, 1.0, -1.0);
|
||||
float bas = map(0, nc, i, 1.0, -1.0);
|
||||
ligne(i-1, -1.0, haut, 1.0, bas);
|
||||
if(type_dessin == LIGNE || type_dessin == LIGNE_AXES)
|
||||
{
|
||||
ligne(i-1, -1.0, haut, 1.0, bas);
|
||||
}else{
|
||||
// type_dessin == HISTO
|
||||
histo(i-1, -1.0, haut, 1.0, bas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +184,13 @@ void afficher(void)
|
||||
{
|
||||
float gauche = map(0, nc, i-1, -1.0, 1.0);
|
||||
float droite = map(0, nc, i, -1.0, 1.0);
|
||||
ligne(i-1, -1.0, gauche, 1.0, droite);
|
||||
if(type_dessin == LIGNE || type_dessin == LIGNE_AXES)
|
||||
{
|
||||
ligne(i-1, -1.0, gauche, 1.0, droite);
|
||||
}else{
|
||||
// type_dessin == HISTO
|
||||
histo(i-1, -1.0, gauche, 1.0, droite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +198,13 @@ void afficher(void)
|
||||
{
|
||||
for(unsigned int i = 1; i < nc+1; i++)
|
||||
{
|
||||
ligne(i-1, -1.0, 1.0, 1.0, -1.0);
|
||||
if(type_dessin == LIGNE || type_dessin == LIGNE_AXES)
|
||||
{
|
||||
ligne(i-1, -1.0, 1.0, 1.0, -1.0);
|
||||
}else{
|
||||
// type_dessin == HISTO
|
||||
histo(i-1, -1.0, 1.0, 1.0, -1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,7 +219,7 @@ void reshapeCallback(int largeur, int hauteur)
|
||||
glViewport(0, 0, largeur, hauteur);
|
||||
//glutPostRedisplay();
|
||||
|
||||
printf("Reshape : [%d, %d]\n", vx2, vy2);
|
||||
//printf("Reshape : [%d, %d]\n", vx2, vy2);
|
||||
}
|
||||
|
||||
int initWindow(int argc, char* argv[], void(*display)(void))
|
||||
@ -185,7 +254,7 @@ long getFileSize(FILE* file)
|
||||
void parseFile(char* file, long size)
|
||||
{
|
||||
nc = atoi(file);
|
||||
printf("nc=%d\n", nc);
|
||||
//printf("nc=%d\n", nc);
|
||||
|
||||
//printf("====\n%s\n====\n", file);
|
||||
|
||||
@ -283,7 +352,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
printCourbeTerminal();
|
||||
|
||||
mode_affichage = SUPERPOSER;
|
||||
type_dessin = LIGNE_AXES;
|
||||
mode_affichage = VERTICAL;
|
||||
int window = initWindow(argc, argv, afficher);
|
||||
|
||||
glutMainLoop();
|
||||
|
Loading…
Reference in New Issue
Block a user