• C

NURBS and B-splines

I am trying to create an interactive NUBRS (with openGL) in C where user is available to select the points with the click of the mouse. However, as soon as I made 25 points the nurb dissapier from the screen .. does anyone have any idea why would be doing something like that.

Here is the part of my code that does it

void render_bspline(void)
{
      GLUnurbsObj *theNurb;
        GLfloat      knots[MAX_POINTS*2];
      int i=0;
      
      for(;i<=(numpoints*2);i++)
      {
            if(i<((numpoints*2)/2))
                  knots[i] =0.0;
            else
                  knots[i]=1.0;
      }
  theNurb = gluNewNurbsRenderer();
  gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
      
  glPushMatrix();
        glColor3f(1.0,0.0, 0.0 );
        gluBeginCurve(theNurb);
                  gluNurbsCurve(theNurb, numpoints*2, knots,3,&ctlpoints[0][0], numpoints,GL_MAP1_TEXTURE_COORD_2);
                  gluNurbsCurve(theNurb, numpoints*2, knots,3,&ctlpoints[0][0], numpoints,GL_MAP1_NORMAL);
                    gluNurbsCurve(theNurb, numpoints*2, knots,3,&ctlpoints[0][0], numpoints,GL_MAP1_VERTEX_3);
        gluEndCurve(theNurb);
      gluDeleteNurbsRenderer(theNurb);
  glPopMatrix();
}

Thanks for taking your time to look at this
L.
ledeniAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenDBACommented:


What's the value of MAX_POINTS?

Kent
ledeniAuthor Commented:
hey Kent .. thanks for looking at it ... MAX_POINTS is 255 .. that I am also using as a array max points for that control points ... so my array is initializes as
cntrlpoints[MAX_POINTS][3] and that array gets populated with the values that I select with the mouse on the open window. And since my understanding that knots are 2 times number of control points that is why I initiate the knots as MAX_POINTS * 2

Thanks a bunch once more

L.
ledeniAuthor Commented:
And one more thing ... and that is that the numpoints is the current selected number of points on the screen
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Kent OlsenDBACommented:

What is the value of numpoints when you enter the function?

Also, as a matter of technique, if you're passing the array ctlpoints to a function you can use the name instead of taking the address of the first element.

              gluNurbsCurve(theNurb, numpoints*2, knots, 3, &ctlpoints[0][0], numpoints, GL_MAP1_TEXTURE_COORD_2);

becomes:

              gluNurbsCurve(theNurb, numpoints*2, knots, 3, ctlpoints, numpoints, GL_MAP1_TEXTURE_COORD_2);


Kent

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ledeniAuthor Commented:
Hey Kent

numpoints is 2 when I enter the function ... b.c. at least I think I should not be drawing the b-spline before I have at least 2 points. However I think that my problem is my understanding the entire process of knots, nurbs, etc etc ...

Maybe you can be more of assistance to me if you can just point me in direction of how many knots I should be having at some point for e.g. if I have chosen 2 points on the screen .. then should there be a 4 knots to it ... and should my order by number of points selected. all in all how gluNurbCurve works for dynamicly populated array of elements.

Thanks again for looking at this ... and I will just bump up some more points on this question now ... thanks again
ledeniAuthor Commented:
Hey Kent .. just thought to let you know (or anyone else) that I have figured out the nerb drawing ... I was wondering if anyone would know what type of openGL command lines I can use to spin this 2D nurb around the Z axis to get the 3D image.

Thanks ... a bunch once more for looking at this ..

L.
sunnycoderCommented:
you may also like to read this --- it des not have nerbs but rotation -- yes
http://www.mfcogl.com/OpenGL%20-%20draw%20cylinder%20between%202%20pts.htm
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.