PDA

View Full Version : nurb



08-04-2003, 12:11 PM
I am trying to draw a smooth surface from some control points
( the bottom of the sea from real lat, lon and depth data). The data I have include 8x8 points. Each have x, y, Z value.
I build a

GLfloat pfControlPoints[8][8][3];
then I assigned the real value to the 3-dimensional array.
then I did the following

GLfloat Knots1[16] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
GLfloat Knots2[16] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};

glPushMatrix();

gluBeginSurface(m_pNurb);


gluNurbsSurface(m_pNurb,
16, Knots1,
16, Knots2,
3*8,
3,
&(pfControlPoints[0][0][0]),
4, 4,
GL_MAP2_VERTEX_3);

gluEndSurface(m_pNurb);
glPopMatrix();


The problem is my virtual memory went up very high and my computer got killed.
I tried 4X4 points, The program works just fine. I fuuny thing is, all examples I found are use 4x4 control points.
I tried 6x4, only 4x4 points are connected by the nurb. Are there any restrictions to the NURB. Does it only take 4X4 control points?

thanks a lot
jim

mikael_aronsson
08-04-2003, 12:37 PM
Hi !

There are lots of number so if you change for example the number of control points make sure you update everything else also.

The size of each knot vector should be order+num_control_points (a 4*4 order 4*4 surface should have 8 knots in each direction) you also need to take of the first and last knots if you want to make sure that the first and last points are at the same position as the first and last control points.

Check the stride values also.

Other then that I think it should work just fine, there are limitations on both order and the size of the control point array, I think you can get them with glGet...

Mikael


[This message has been edited by mikael_aronsson (edited 08-04-2003).]

08-04-2003, 12:58 PM
I think I did update every parameter of gluNurbsSurface when I try 8x8 control points.
Again, my program work fine if I use 4x4. I also don't know why you are talk about "stride value" here, and what is that "glGet...". All I need is a working example of how to use gluNurbsSurface when I have 8x8 control points.
the following is what I did. Can anybody tell me what is wrong.
Thanks a lot.

jim
gluNurbsSurface(m_pNurb,
16, Knots1,
16, Knots2,
3*8,
3,
&(pfControlPoints[0][0][0]),
4, 4,
GL_MAP2_VERTEX_3);

Originally posted by mikael_aronsson:
Hi !

There are lots of number so if you change for example the number of control points make sure you update everything else also.

The size of each knot vector should be order+num_control_points (a 4*4 order 4*4 surface should have 8 knots in each direction) you also need to take of the first and last knots if you want to make sure that the first and last points are at the same position as the first and last control points.

Check the stride values also.

Other then that I think it should work just fine, there are limitations on both order and the size of the control point array, I think you can get them with glGet...

Mikael


[This message has been edited by mikael_aronsson (edited 08-04-2003).]

mikael_aronsson
08-05-2003, 04:44 AM
Hi !

Well you should know I guess, you supply the stride values yourself http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Anyway, you say that it works with 4*4 and that's what is in your example so that one works, how about posting an example you doesn't work, that would help a little bit.

Mikael


[This message has been edited by mikael_aronsson (edited 08-05-2003).]

08-05-2003, 05:11 AM
In my first post I have the code posted.
here is the copy of the first post.
please take a look and tell me what is wrong.
I am trying to do a 8x8.

Thanks.
I am trying to draw a smooth surface from some control points
( the bottom of the sea from real lat, lon and depth data). The data I have include 8x8 points. Each have x, y, Z value.
I build a

GLfloat pfControlPoints[8][8][3];
then I assigned the real value to the 3-dimensional array.
then I did the following

GLfloat Knots1[16] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
GLfloat Knots2[16] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};

glPushMatrix();

gluBeginSurface(m_pNurb);


gluNurbsSurface(m_pNurb,
16, Knots1,
16, Knots2,
3*8,
3,
&(pfControlPoints[0][0][0]),
4, 4,
GL_MAP2_VERTEX_3);

gluEndSurface(m_pNurb);
glPopMatrix();


The problem is my virtual memory went up very high and my computer got killed.
I tried 4X4 points, The program works just fine. I fuuny thing is, all examples I found are use 4x4 control points.
I tried 6x4, only 4x4 points are connected by the nurb. Are there any restrictions to the NURB. Does it only take 4X4 control points?


Originally posted by mikael_aronsson:
Hi !

Well you should know I guess, you supply the stride values yourself http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Anyway, you say that it works with 4*4 and that's what is in your example so that one works, how about posting an example you doesn't work, that would help a little bit.

Mikael


[This message has been edited by mikael_aronsson (edited 08-05-2003).]

mikael_aronsson
08-05-2003, 09:33 AM
Hi !

Yes I know that, but that is with 4*4 CP and you said that it worked fine with that, what did you change when you tried to use 6*4 for example ?

Mikael

08-05-2003, 10:22 AM
Please look at the code. It is 8x8. or simply give me an working example of 8x8. or any working example other than 4x4.
Thanks
jim

Originally posted by mikael_aronsson:
Hi !

Yes I know that, but that is with 4*4 CP and you said that it worked fine with that, what did you change when you tried to use 6*4 for example ?

Mikael

mikael_aronsson
08-05-2003, 09:30 PM
Hi again !

void gluNurbsSurface(
GLUnurbsObj *nobj, /* m_pNurb */
GLint sknot_count, /* 16 */
GLfloat *sknot, /* Knots1 */
GLint tknot_count, /* 16 */
GLfloat *tknot, /* Konts2 */
GLint s_stride, /* 3*8 */
GLint t_stride, /* 3 */
GLfloat *ctlarray, /* CP array */
GLint sorder, /* 4 */
GLint torder, /* 4 */
GLenum type /* GL_MAP_VERTEX3 */
);

The example you give does not work, first of all, you have 16 knots in each direction, with an order of 4 that would mean that you need 12 control points in each direction and you only give 8... that's not good.

So if you change the size of the knot vectors to 8 instead of 16 to start with, I think it would work better.

OpenGL uses the size of the knot vector together with the order to calculate the number of control points used (number of control points + order = size of knotvector)

And if you want the first and last points to end up at the first and last control points I suggest that you use a knot vector like:
0 0 0 1 1 2 2 2

Mikael

08-06-2003, 05:43 AM
Now My stuff is working completely. I got the size of the knot array from a math equation yesterday. Your Answer confirmed that point. And I figure out the rest of parameters for my 8x8 last night.

Thanks.
Jim

Originally posted by mikael_aronsson:
Hi again !

void gluNurbsSurface(
GLUnurbsObj *nobj, /* m_pNurb */
GLint sknot_count, /* 16 */
GLfloat *sknot, /* Knots1 */
GLint tknot_count, /* 16 */
GLfloat *tknot, /* Konts2 */
GLint s_stride, /* 3*8 */
GLint t_stride, /* 3 */
GLfloat *ctlarray, /* CP array */
GLint sorder, /* 4 */
GLint torder, /* 4 */
GLenum type /* GL_MAP_VERTEX3 */
);

The example you give does not work, first of all, you have 16 knots in each direction, with an order of 4 that would mean that you need 12 control points in each direction and you only give 8... that's not good.

So if you change the size of the knot vectors to 8 instead of 16 to start with, I think it would work better.

OpenGL uses the size of the knot vector together with the order to calculate the number of control points used (number of control points + order = size of knotvector)

And if you want the first and last points to end up at the first and last control points I suggest that you use a knot vector like:
0 0 0 1 1 2 2 2

Mikael