2

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.

genpfault
  • 51,148
  • 11
  • 85
  • 139
JMcMinn
  • 275
  • 3
  • 10

2 Answers2

2

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.

Hugh
  • 1,641
  • 1
  • 11
  • 3
  • Yeah, as it turns out, that was pretty stupid of me. I moved the vertex to inside the loops and now it works-- sort of. I have another issue now but that'll have to wait for another question. Thanks for the answer. – JMcMinn Nov 20 '12 at 00:06
0

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.

Hugh
  • 1,641
  • 1
  • 11
  • 3
  • Thanks for this; my code's gone through some changes since I posted this question, and now my format more closely matches the one you mentioned. – JMcMinn Nov 21 '12 at 00:27