| |
|
|
||||
![]() |
||||||
| |
|
|||||
|
/* * Calculates a Bezier curve using subdivision to the desired depth. * * Point is an object that has the x, y, and z coordinates and defines * some mathematical operations for points. See the project accompanying * the article for its definition. * * G is the geometry vector, the three control points for the curves. * level is the depth to subdivide. */ void QuadraticBezierSubdivide(Point G[], int level) { // Draw a line if level 0 using the end points if(level == 0) { glBegin(GL_LINES); glVertex3f(G[0].x, G[0].y, G[0].z); glVertex3f(G[2].x, G[2].y, G[2].z); glEnd(); return; } // New geometry vectors for the left and right halves of the curve Point Gl[3]; Point Gr[3];
// Subdivide Gl[0] = G[0]; Gl[1] = (G[0] + G[1]) * 0.5f; Gr[1] = (G[1] + G[2]) * 0.5f; Gl[2] = Gr[0] = (Gl[1] + Gr[1]) * 0.5f; Gr[2] = G[2]; // Call recursively for left and right halves QuadraticBezierSubdivide(Gl, --level); QuadraticBezierSubdivide(Gr, level); } |
|
|