More Splines, Recursive Subdivision, Patches, OpenGL




CS116b/CS216

Chris Pollett

Feb 26, 2014

Outline

Introduction

Bessel-Overhauser Splines

example of not Catmull-Rom Splines with not evenly spaced control points

More Bessel-Overhauser Splines

Recursive Subdivision

Applications of Recursive Subdivision

Another Application of Recursive Subdivision

Bezier Surface Patches

A picture of the degree three Bezier patch and its sixteen control points

More on Bezier Patches

Joining Bezier Patches

Subdividing Bezier Patches

two Bezier patches, one subdivided, one not resulting in a crack

OpenGL and Bezier Curves and Patches

OpenGL Bezier Curve Example

/*-----------------------------------------------*/
void drawBezier()
/*
 PURPOSE: Drawing a Bezier curve with glMap1* functions 
 RECEIVES: nothing
 RETURNS: nothing
 REMARKS: 
 */
{
    GLfloat ctrlPts[4][3] = {{-40.0, -40.0, 0.0}, 
        {-10.0, 200.0, 0.0}, {10.0, -200.0, 0.0}, {40.0, 40.0, 0.0}};
    glMap1f (GL_MAP1_VERTEX_3, 0.0 /* uMin*/, 1.0 /* uMax*/, 
        3 /* stride*/, 4 /*num points */,
	          *ctrlPts);
    glEnable(GL_MAP1_VERTEX_3);
    GLint k;	
    // draw curve in blue
    glColor3f(0.0, 0.0, 1.0);	
    glBegin(GL_LINE_STRIP);
    for (k = 0; k <= 50; k++) {
        glEvalCoord1f(GLfloat(k)/50.0);
    }
    glEnd();
	
    // draw control points in red
    glColor3f(1.0, 0.0, 0.0);
    glPointSize(5.0);	
    glBegin(GL_POINTS);
    for (k = 0; k < 4; k++) {
        glVertex3fv(&ctrlPts[k][0]);
    }
    glEnd();
	
    glFlush();
}

Example Screenshot

a cubic Bezier curve

Remarks

Drawing a Bezier Patch

/*-----------------------------------------------*/
void drawBezierPatch()
/*
 PURPOSE: Drawing a Bezier Patch with glMap2* functions 
 RECEIVES: nothing
 RETURNS: nothing
 REMARKS:   
 */
{
    GLfloat ctrlPts[4][4][3] = {
        {{-1.5, -1.5, 4.0}, {-.5, -1.5, 2.0}, 
         {-.5, -1.5, -1.0}, {1.5, -1.5, 2.0} }, 
        {{-1.5, -.5, 1.0}, {-.5, -.5, 3.0},
         {.5, -.5, 0.0}, {1.5, -.5, 1.0} }, 
        {{-1.5, .5, 4.0}, {-.5, .5, 0.0}, 
         {.5, .5, 3.0}, {1.5, .5, 4.0} },
        {{-1.5, 1.5, -2.0}, {-.5, 1.5, -2.0}, 
         {.5, 1.5, 0.0}, {1.5, 1.5, -1.0} }
    };
	
    glMap2f (GL_MAP2_VERTEX_3, 0.0 /* uMin*/, 1.0 /* uMax*/, 
        3 /* u stride*/, 4 /*num points u*/,
        0.0 /* vMin*/, 1.0 /* vMax*/, 12 /*v stride*/, 
        4, &ctrlPts[0][0][0]);

    glEnable(GL_MAP2_VERTEX_3);
    GLint k, j;

    //draw patch in red
    glColor3f(1.0, 0.0, 0.0);
    glMapGrid2f(50, 0.0, 1.0, 50, 0.0, 1.0);
    glEvalMesh2(GL_FILL, 0, 50, 0, 50);

    // draw curves on patch in blue
    glColor3f(0.0, 0.0, 1.0);
	
    for (k = 0 ; k <= 8; k++) {
        glBegin(GL_LINE_STRIP);
        for(j = 0; j <= 40; j++) {
            glEvalCoord2f(GLfloat(j)/40.0, GLfloat(k)/8.0);
        }
        glEnd();
        glBegin(GL_LINE_STRIP);
        for (j = 0; j <= 40; j++) {
            glEvalCoord2f(GLfloat(k)/8.0, GLfloat(j)/40.0);
        }
        glEnd();	
    }
    glFlush();
}

Example Screenshot

a cubic Bezier Patch