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

Rendering Bézier Curves

Now that we have defined Bézier curves, we would like to display them. There are a couple of ways to do this. The most straightforward way, shown in Listing 1, is to evaluate the curve equation along constant steps in t between 0 and 1. The finer the steps that are taken, the higher quality the curve will be. Since the basis functions are polynomials, this process can be sped up by using forward differencing. Figure 6 shows the same curve rendered with different step sizes.

Listing 1.

/*

* Calculates a Bezier curve directly by iterating along the curve

* for the desired number of steps.

*

* 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.

* steps is the number of steps to take along the curve.

*/

void QuadraticBezierIterate(Point G[], int steps) {

float stepSize = 1.0 / steps;

float t = stepSize;

// Draw the curve as a line strip

glBegin(GL_LINE_STRIP);

// First control point is on the curve

glVertex3f(G[0].x, G[0].y, G[0].z);

// Calculate intermediate points

for(int step = 1; step < steps; step++, t += stepSize) {

// Calculate the blending functions

float b0 = (1 - t) * (1 - t);

float b1 = 2.0 * t * (1 - t);

float b2 = t * t;

// Blend

float x = b0 * G[0].x + b1 * G[1].x + b2 * G[2].x;

float y = b0 * G[0].y + b1 * G[1].y + b2 * G[2].y;

float z = b0 * G[0].z + b1 * G[1].z + b2 * G[2].z;

// Emit a vertex

glVertex3f(x, y, z);

}

// Last control point is on the curve

glVertex3f(G[2].x, G[2].y, G[2].z);

glEnd();

}


Divide and Conquer


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