PDA

View Full Version : gluNurbsCurve



Cardinal
04-17-2001, 08:05 PM
I have a subtle error in my spline code... the knots array is set to { 0,0,0,0,1,1,1,1 } and the total is set outside the code. I can't tell if my error is in my array allocation, filling, or call to gluNurbsCurve... both 'Selected's are correct in the linked-list I am using (I know its slow...) The only thing I have noticed so far, is that when I have 3 control points, I see a line from the last point to the coordinate of the first control points x, seconds y, and thirds z... If anyone has any suggestion, I would appreciate them. http://www.opengl.org/discussion_boards/ubb/confused.gif




GLfloat *points = (GLfloat *)malloc(4 * total * sizeof(GLfloat));

Selected->GetHead();
for(int index=0; index < total*4; index++){
//accesses elements of individual points
points[index] = Selected->Selected->v[index%4];
Selected->GetNext();
}

GLUnurbsObj *theNurb = gluNewNurbsRenderer();
gluBeginCurve(theNurb);
gluNurbsCurve(theNurb,8,knots,4,points,total,GL_MA P1_VERTEX_4);
gluEndCurve(theNurb);
gluDeleteNurbsRenderer(theNurb);

tvthompsonii
04-18-2001, 10:07 AM
The code you have can only work if the curve is order four, the points are rational, and there are four points. Thats just basic NURBS 101. http://www.opengl.org/discussion_boards/ubb/tongue.gif

The easiest way to look at this is that the length of your knot vector must equal the number of control points plus the order of the curve. further, you must have at least order number of cpts.

If you have a knot vector that is:

{0,0,0,0,1,1,1,1}

then this implies a curve with order 4 and exactly 4 control points (note: it could represent a lower order curve with more cpts, for instance order 3 with 5 cpts, but that curve would be a ~bad~ curve).

If "total" in your code is the number of cpts, which it appears to be, then you need to construct a new knot vector to match the curve length.

As an example (and this is just code off the top of my head so you may need to debug it a little):




GLfloat *knots = new GLfloat[total+order];
int i,j;
for( i =0; i<order; i++ ) knots[i] = 0;
for( j= 1; j<=total-order; j++,i++ ) knots[i] = j/(total-order+1);
for( j= 0; i<order; j++,i++ ) knots[i] = 1;
// the rest of your code stays the same except:
gluNurbsCurve(theNurb,total+order,knots,4,points,o rder,GL_MAP1_VERTEX_4);


Hopefully that helps. Long story short, you're passing "total" in the "order" slot to gluNurbsCurve. OpenGL infers the value of "total"by using the knot vector length and the order. Hence, those values better agree! http://www.opengl.org/discussion_boards/ubb/wink.gif


[This message has been edited by tvthompsonii (edited 04-18-2001).]

Cardinal
04-18-2001, 06:50 PM
yea, I noticed just a few seconds ago, while glancing in the blue book, that I had run amiss... thx http://www.opengl.org/discussion_boards/ubb/smile.gif