| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 
 |  
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
 
 
#define N	5
#define STEP	0.001f
 
int valuesA[N] = { 1, 2, 3, 4, 5 };
int valuesB[N] = { 6, 7, 8, 9, 10 };
int valuesC[N] = { 11, 12, 13, 14, 15 };
int valuesD[N] = { 16, 17, 18, 19, 20 };
 
int width, height;
int verbose = 0;
 
float Couleurs[N][3] = 
{
	{ 1, 0, 0 },
	{ 0, 1, 0 },
	{ 0, 0, 1 },
	{ 1, 1, 0 },
	{ 0, 1, 1 }
};
 
char *NomCouleur[N] =
{
	"rouge", "vert", "bleu", "jaune", "turquoise"
};
 
 
float FonctionABCD( float u, int a, int b, int c, int d )
{
	return  a * u*u*u + b * u*u + c * u + d;  
}
 
void PrintArray( char *name, int n, int *array)
{
	int i;
 
	printf("%s = [ ", name); 
	for( i = 0 ; i < N ; i++ )
	{
		printf("%2d", array[i] );
		if( i < N - 1 )
		{
			printf(", ");
		} 
	} 
	printf(" ]\n");
 
}
 
void  ReshapeFunc(int w, int h)
{
	//Tell OpenGL how to convert from coordinates to pixel values
	glViewport(0, 0, w, h);
	width = w;
	height = h;
 
	//Switch to setting the camera perspective
	glMatrixMode(GL_PROJECTION); 
 
	//Set the camera perspective
	glLoadIdentity(); 
 
	//Reset the camera
	// gluPerspective( 45.0, (double)w / (double)h, 1.0, 200.0);
	glOrtho(-1,1,-1,1,-10,10);
}
 
void KeyboardFunc(unsigned char key,int x, int y)
{
	switch (key) 
	{
 
   		case 27:                            /* ESC = Quit */
   		case 'Q':
   		case 'q': 
      			exit(0); 
      			break;
	}
 
 
	glutPostRedisplay();	
}
 
 
void DisplayFunc()
{
	int i;
	float u, v;
 
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
	glPushMatrix();
	glTranslatef(-1.0f, -1.0f, 0.0f);
	glScalef(2.0f, 0.02f, 1.0f);
 
 
	for (i = 0 ; i < N ; i++ )
	{
 
		printf("\nSX(%d) = %s \n", i + 1, NomCouleur[i] );
 
		glBegin(GL_LINES);
		glColor3fv( &Couleurs[i][0] );
 
		for( u = 0.0f ; u <= 1.000f ; u += STEP )
		{
			v = FonctionABCD(u, valuesA[i], valuesB[i], valuesC[i], valuesD[i]);
 
			glVertex2f(u, v);       
		}
 
		glEnd();
	}
 
	glPopMatrix();
 
	glutSwapBuffers();
}
 
 
int main(int argc, char **argv )
{
	printf("Courbe parametrique multiple SX(1..%d) = a*u^3 + b*u^2 +c*u + d avec (a,b,c,d) comme paramêtres et u variant de 0 à 1 par pas de %.3f \n\n", N, STEP);
 
	PrintArray("a", N, valuesA );
	PrintArray("b", N, valuesB );
	PrintArray("c", N, valuesC );
	PrintArray("d", N, valuesD );
 
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutCreateWindow("Courbe parametrique multiple");
 
	glutDisplayFunc(DisplayFunc);
	glutReshapeFunc(ReshapeFunc);
	glutKeyboardFunc(KeyboardFunc);
 
	glutMainLoop();
 
	return 0;
} | 
Partager