Question

I've been working on an OpenGL project that's essentially practice for drawing b-spline curves. My program returns no errors but the curves won't display.

Given an array of control points of length 13 named 'coords' (the control points themselves are all visible on-screen), this is my code:

glBegin(GL_LINE_STRIP);

float x=0;
float y=0;
float z=0;
for (double u = 3; u <= 14; u+=0.1){

    for (int i = 1; i <=13; i++){
        x += NofU(u,i)*coords[i].x;
        y += NofU(u,i)*coords[i].y;
        z += NofU(u,i)*coords[i].z;
    }//for

}//for

glVertex3f(x, y, z);

glEnd();

Where "NofU" represents the blending functions:

double NofU(double u, int i){

if (u < i)
    return 0;
else if (u < i+1)
    return (1/6)*pow(u,3);
else if (u < i+2)
    return (1/6)*((-3)*pow(u,3)+3*pow(u,2)+3*u+1);
else if (u < i+3)
    return (1/6)*(3*pow(u,3)-6*pow(u,2)+4);
else if (u < i+4)
    return (1/6)*pow((1-u),3);
else
    return 0;

}//NofU

When I attempt print statements, I end up with either insanely large or small coordinate values, or just 0.

Was it helpful?

Solution

Uh, you only have one glVertex3f call inside the glBegin/End block. So you're trying to draw a line strip with only one point in it, which can't really be done. (Not sure whether OpenGL would actually report an error for this or not.)

Hope this helps.

OTHER TIPS

I'd also check your B-spline calculation function. My reference (Advanced Animation and Rendering Techniques, Watt & Watt) has two u values. There's the global U in upper case which range from 0 .. n - 2. That corresponds to your lower case u. But for the basis functions (lower case) u must be in the range 0 .. 1. In your code, that would be fmod(u, 1). I think that if you use that in all the NoFu return statements you'll get better answers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top