PDA

View Full Version : NURBS again!



sky-raven
08-25-2002, 07:35 AM
Hello,
So far no one has answered this question on nurbs:
If I use GL_MAP1_VERTEX4 for the type in the function gluNurbsCurve() it should allow you to draw rational b spline curves by specifying the homogenious weighting factors in the fourth coordinate of the each control point. Unfortunately all this does is gives you a distorted curve for homogenious weighting factors different from 1.0. Could I be doing something wrong?

Sky-raven

Rob The Bloke
08-25-2002, 03:17 PM
err, more info; the curve should be distorted when using wieghts, that's kinda the point....

specifying the curve with all weights at 1 should give you the same as when using no weights at all.

If something is different then have a look at the stride value between points and make sure it matches the vertex data you are passing it

sky-raven
08-26-2002, 01:18 AM
Sky-raven reply:
Since I am using x,y,z,w for each control pt I set my stride at 4, but it still draws curve incorrectly, in that if i set all w to a new value it is drawn in the same way as glvertex4f() say would draw it. Therefore gluNurbsCurve() so far cannot give a true rational bspline. Where I am going wrong?



Originally posted by Rob The Bloke:
err, more info; the curve should be distorted when using wieghts, that's kinda the point....

specifying the curve with all weights at 1 should give you the same as when using no weights at all.

If something is different then have a look at the stride value between points and make sure it matches the vertex data you are passing it

sky-raven
08-28-2002, 11:05 AM
I have checked the stride which in this case is 4, since x,y,z,w coords for each control pt vertex. Now I put this to you.
If you try writing a programme to draw a circle using gluNurbsCurve() function with a
X[] of 000112233444 for the knot vector and
homogeneous weighting factors of
w[] of 1.0, 0.707,1.0,0.707,1.0,0.707,1.0,0.707,1.0
this should give a circular curve. Unfortunately it does not!The order should be an order of 3 with 9 control p.ts in the form of a box. Where I am going wrong?


Originally posted by sky-raven:
Sky-raven reply:
Since I am using x,y,z,w for each control pt I set my stride at 4, but it still draws curve incorrectly, in that if i set all w to a new value it is drawn in the same way as glvertex4f() say would draw it. Therefore gluNurbsCurve() so far cannot give a true rational bspline. Where I am going wrong?

Pete
08-29-2002, 09:21 PM
Hi, I am new in Nurbs, and I had this same problem. In the case, you use a GL_MAP1_VERTEX_4, you must apply w parameter to your x, y, and z coordinate (simply multiply each of them by w).

example:
double w = 0.707;
GLfloat ctrlpt[9][4] = {
{0, 1, 1, 1}, // here is w = 1
{0*w, 0*w, 1*w, w},
{1, 0, 1, 1},
{2*w, 0*w, 1*w, w},
{2, 1, 1, 1},
{2*w, 2*w, 1*w, w},
{1, 2, 1, 1},
{0*w, 2*w, 1*w, w},
{0, 1, 1, 1},
};

GLfloat knots[12] = { 0.0, 0.0, 0.0, 0.25,
0.25, 0.5, 0.5, 0.75,
0.75, 1.0, 1.0, 1.0};

gluNurbsCurve(theNurb,
12, knots,
4, &ctrlpt [0][0],
3, GL_MAP1_VERTEX_4);

sky-raven
08-30-2002, 12:13 PM
Thank very much! It worked! Great!

Originally posted by Pete:
Hi, I am new in Nurbs, and I had this same problem. In the case, you use a GL_MAP1_VERTEX_4, you must apply w parameter to your x, y, and z coordinate (simply multiply each of them by w).

example:
double w = 0.707;
GLfloat ctrlpt[9][4] = {
{0, 1, 1, 1}, // here is w = 1
{0*w, 0*w, 1*w, w},
{1, 0, 1, 1},
{2*w, 0*w, 1*w, w},
{2, 1, 1, 1},
{2*w, 2*w, 1*w, w},
{1, 2, 1, 1},
{0*w, 2*w, 1*w, w},
{0, 1, 1, 1},
};

GLfloat knots[12] = { 0.0, 0.0, 0.0, 0.25,
0.25, 0.5, 0.5, 0.75,
0.75, 1.0, 1.0, 1.0};

gluNurbsCurve(theNurb,
12, knots,
4, &ctrlpt [0][0],
3, GL_MAP1_VERTEX_4);

sky-raven
09-04-2002, 11:37 AM
I would just like to finish this topic by asking anyone how they would best handle the situation of w approaching zero? Otherwise any w value will work by this method to produce rational curves.

Pete
09-04-2002, 08:31 PM
In the case, w is zero, use w = 1

sky-raven
09-05-2002, 04:49 AM
But if w should equal 1 then the particular control p.t will be left with 0,0,0,1. Is that right?