PDA

View Full Version : Nurbs Surface in OpenGL



snupinokio
07-17-2003, 10:33 PM
I have a program that receives from the user control points of two B-Spline curves (de Boor points) and draws the surface with these curves as edges, connecting in a straight line between each two control points in different curves (ruled surface).
My problem is the gluNurbsSurface method doesn't work correctly when the control points array is dynamically allocated (two or three dimentions array), where it works correctly when it is statically allocated. i didn't find how to operate it right.

I would be grateful for any help anyone can give me with this.
Thanks

Deiussum
07-18-2003, 04:35 AM
The memory needs to be contiguous and it's not for dynamically-allocated, multi-dimensional arrays.

Consider this for example.




float **ppValues = new float*[someValue];

for (int c=0;c<someValue;c++)
{
ppValues[c] = new float[someOtherValue];
}


At this point you now have an array of pointers. ppValues itself doesn't point to any of your values. It points to a list of memory addresses. Each of those memory addresses points to a separate set of values. There is no guarantee that the memory allocated for any of the given float arrays directly follows the previously allocated float array.

To do this right, you should allocate the memory as a single large float array.




float *pValues = new float[someValue * someOtherValue];


Now, to calculate the indices you just use a formula like so...




index = y * width + x;


You can also use other tricks like so...




float *pValues;
float **ppValues;

pValues = new float[width * height];

for (int y=0;y<height;y++)
{
ppValues = &amp;pValues[y*width];
}



If you are using a multidimensional array for something like an array of x,y,z coordinates you can also do something like so...




struct Vector3
{
float x, y, z;
}

Vector3 *pValues = new Vector3[someValue];


Hope that helps.