View Full Version : C++ Vectors problem in GLU NURBS interface??

07-11-2002, 07:38 AM
I am trying to write a program to interactively model and manipulate the NURBS surfaces. For this i am using the GLU NURBS interface. The interface requires control points to be given in a 3D array. But in order to extend the surface dynamically i need to change the no. of control points during execution.

But the command is not excepting dynamically allocated arrays, ( with new or malloc). It does not even take in C++ vector class variables.

Does anybody know a way to work around this problem?

Thank you,

07-11-2002, 09:58 AM
Post some code. You are probably using the gluNurbs methods wrong as they should have no knowledge of whether they are statically allocated or dynamically allocated arrays.

07-11-2002, 10:12 PM
I initialized NURBS object using

theNurb = gluNewNurbsRenderer();
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 50.0);
gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);

Then i called the drawing function,


8, &UKnots[0],8,&VKnots[0],
UKnots.size() - Degree - 1) * 4,4,
4, 4,GL_MAP2_VERTEX_4);


This drawing function is working only when the ControlPoints array is statically allocated to the exact no. of control points. It does not seem to be working when i dynamically allocate the array and then fill it with data. I could not understand why ? Same is the case with the use of C++ vectors.

Thank you.

07-12-2002, 04:25 AM
Ok. I notice you have a 3 dimensional array. Am I correct in assuming you are probably doing something like so when trying to allocate it dynamically?

float ***ControlPoints;

ControlPoints = new float**[size];

for (x=0;x<size;x++)
ControlPoints[x] = new float*[size2];
for (y=0;y<size2;y++)
ControlPoints[x][y] = news float[size3];

If that's the case, you are NOT setting memory correctly. What you need is one contiguous range of memory. When you setup a static multi-dimensional array, it will make the memory contiguous for you.

Doing it like above however, starting at the location pointed to by ControlPoints, you are actually pointing at a pointer which points to another pointer, which points to one row of data. See why that won't work, yet?

You should be allocating your memory like so.

float *ControlPoints = new float[size1*size2*size3];

One other thing. Not a major thing, but I thought I'd mention it.

Using &UKnots[0] is identical to just using UKnots. Arrays are always represented as a pointer to the first element when you don't dereference a specific element. Just thought I'd mention it as I tend to find just UKnots more readable.