It's free to join Gamasutra!|Have a question? Want to know who runs this site? Here you go.|Targeting the game development market with your product or service? Get info on advertising here.||For altering your contact information or changing email subscription preferences.
Registered members can log in here.Back to the home page.

Search articles, jobs, buyers guide, and more.

By Gabe Kruger
Gamasutra
June 11, 1999

 

Letters to the Editor:
Write a letter
View all letters


Features

 

Contents

Introduction

On Lines

Connect the Curves

Rendering Bézier Curves

Divide and Conquer

Code Listing 2

Bézier Patches

Rendering Bézier Patches

Advanced Patching

Not All is Perfect

Listing 2

/*

* 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);

}


Bézier Patches


join | contact us | advertise | write | my profile
news | features | companies | jobs | resumes | education | product guide | projects | store



Copyright © 2003 CMP Media LLC

privacy policy
| terms of service