I’m using gluNurbsCurve to draw some curves with some control points. I’ve got the basic setup as described in the red book working correctly and I’m trying to expand on it.
This sample looks like this:
float knots[8] = {0,0,0,0,1,1,1,1};
float pnts[4][3] = { {...},{...},{...},{...} };
GLUnurbsObj *m = gluNewNurbsRenderer();
gluBeginCurve(n);
gluNurbsCurve(n, 8, knots, 3, pnts, 4, GL_MAP1_VERTEX_3)
gluEndCurve(n);
One thing I was wondering about is the meaning of the knots data. How does it affect the result? What other options can I experiment there?
For some reason I could not find any tutorial which properly explains this.
Actually there are ample sites online that explain the knot vector. It’s not a GL specific thing but an inherent property of NURBS. So entering "NURBS knot vector" in google is gonna get you detailed explanations.
I’m just gonna say that usually the knot vector has a length of
knot_vector_length = number_of_points + degree_of_curve + 1and the only thing that matters is the ratio and not the absolute values. So{0,1,2,3}is the same as{0,2,4,6}in my opinion the most important knot vectors are these:
1)
{0,1,2,3,4,5,6,...}which will allow you to easily extend the curve with curvature continuity if you repeat the last (or first)
degree_of_curve-1points but this means that that the curve doesn’t actually run through its start and end points so you must repeat the last (or first)degree_of_curve-1points to create a closed curve that is continuous.The other important form is
2)
{0,0,0,1,2,3,...,n,n,n}whereas the
0at the beginning and thenat the end repeatdegree_of_curve + 1times. This is also the form that you used. This will give you a NURBS curve that begins at the first point and ends at the last point you specified. But it only gives positional continuity. So if you make a closed curve with this then you are highly likely to get a tangential discontinuity.Btw. if you only have
degree_of_curve + 1points and use the second form then you only have0s and1s. The resulting spline will be identical to a Bézier curve.This is really hard to explain without images or the mathematical background (Bernstein polynomials)