Hello,
I ve actually a small pb to draw 2 bezier curves on a single window.
This is the code (sorry for french description):
// Point de controle présent en dur
GLfloat ctrlpoints[6][3] = {
{ 2.f, 2.f, 0.f}, { 4.f, 4.f, 0.f},
{6.f, 2.f, 0.f}, {7.f, 7.f, 0.f},
{11.f, 4.f, 0.f}, {7.f, 10.f, 0.f}
};
/*---------------------------------------------------------------*/
/* Partie 1, continuité C1 pour une courbe de bezier de degré 2 */
/* le degré de liberté est de 1 */
/*---------------------------------------------------------------*/
GLfloat pC1[3];
// On calcul le point c1 pour avoir une continuité C1 entre les 2 courbes
// On applique la formule c1 = c0 + b3 - b2
// en sachant que c0 = b3
GLfloat DonnePoint(GLfloat b2, GLfloat c0){
return (2*c0-b2);
}
// Le but ici est d'initialiser les points de controles
// et d'initialiser les différentes courbes de bezier
// de façon à ce qu'elles soient de continuité C1
void display1(void)
{
int i;
//Initialisation du tableau de points à (0,0, 0)
GLfloat points[11][3]={{0},{0},{0}};
//
// Courbe 1
//
// Point 1 (qui est en dur)
for (i=0; i!=3; i++)
points[0][i]=ctrlpoints[0][i];
// Point 2 (qui est celui demandé)
for (i=0; i!=3; i++)
points[1][i]=pC1[i];
//Point 3 (qui est en dur)
for (i=0; i!=3; i++)
points[2][i]=ctrlpoints[1][i];
//
// Courbe 2
// le dernier point de la courbe 1 etant le premier point de la courbe 2
// Point 4 (qui est calculé)
for (i=0; i!=3; i++)
points[3][i]=DonnePoint(points[1][i], points[2][i]);
//Point 5 (qui est en dur)
for (i=0; i!=3; i++)
points[4][i]=ctrlpoints[2][i];
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 3, &points[0][0]);
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 3, &points[2][0]);
glEnable(GL_MAP1_VERTEX_3);
glEnable(GL_MAP1_VERTEX_3);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
for (i = 0; i <= 30; i++)
glEvalCoord1f((GLfloat) i/30.0);
glEnd();
// On trace les points que nous avons à la base
glPointSize(5.0);
glColor3f(1.0, 1.0, 0.0);
glBegin(GL_POINTS);
for (i = 0; i < 6; i++)
glVertex3fv(&ctrlpoints[i][0]);
glEnd();
// On trace les points calculé
glPointSize(5.0);
glColor3f(1.0, 0.0, 1.0);
glBegin(GL_POINTS);
glVertex3fv(&points[1][0]);
glVertex3fv(&points[3][0]);
glEnd();
glutSwapBuffers();
}
I understand that the probleme is with glEnable(GL_MAP1_VERTEX_3); because i ve only the second curve.
My goal is to draw 2 bezier curves ( final point of the first curve is the first point of the second curve), with a continuity C1.