Slide 1

Slide 1 text

jgs SER 431 Advanced Graphics Lecture 20: Non-Uniform Rational Basis Splines II Javier Gonzalez-Sanchez [email protected] PERALTA 230U Office Hours: By appointment

Slide 2

Slide 2 text

jgs Surfaces using OpenGL Support Solid Shape with Materials and Light

Slide 3

Slide 3 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 2 jgs Screenshot https://github.com/javiergs/SER431/blob/master/Lecture19/nurbs_surface_grid.cpp https://github.com/javiergs/SER431/blob/master/Lecture19/nurbs_surface_solid.cpp

Slide 4

Slide 4 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 3 jgs Code // control points GLfloat ctlpoints[4][4][3] = { { { 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } }, { { 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } }, { { 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } }, { { 20, 0, -10 },{ 0, 0, -10 },{ -5, 0, -10 },{ -10, 0, -10 } } }; GLfloat knots[8] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0 }; GLUnurbsObj *theNurb;

Slide 5

Slide 5 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 4 jgs Code // init void init(void) { // Materials and Light GLfloat mat_diffuse[] = { 1.0f, 0.5f, 0.31f, 1. }; GLfloat mat_specular[] = { 0.5f, 0.5f, 0.5f, 1. }; GLfloat mat_ambient[] = { 1.0f, 0.5f, 0.31f, 1. }; GLfloat mat_shininess[] = { 100.0 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); theNurb = gluNewNurbsRenderer(); gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0); gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL); }

Slide 6

Slide 6 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 5 jgs // display void display(void) { // camera and others configurations here... // NURBS glColor3f(0, 1, 0); gluBeginSurface(theNurb); gluNurbsSurface(theNurb, 8, knots, 8, knots, // knots u and v 4 * 3, 3, // offset u and v &ctlpoints[0][0][0], 4, 4, // function degree u and v GL_MAP2_VERTEX_3); gluEndSurface(theNurb); // more ... }

Slide 7

Slide 7 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 6 jgs Numbers to be considered // V_size curves with U_size control points each // V_size + ORDER knots per curve and // U_size + ORDER knots per inter-curve connection // offsets are V_size*3 and 3 // cubic equations ORDER = 4 GLfloat ctlpoints[U_size][V_size][3] = { … }; GLfloat vknots [V_size + ORDER] = { …}; GLfloat uknots [U_size + ORDER] = { …} gluNurbsSurface(theNurb,U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3);

Slide 8

Slide 8 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 7 jgs Screenshot 6 curves 6 control points each 5 curves 6 control points each 4 curves 6 control points each

Slide 9

Slide 9 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 8 jgs 6 curves x 6 control points per curve const int V_size = 6; const int U_size = 6; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 25, 5, 15 } ,{ 20, 5, 15 },{ 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 25, 5, 10 } ,{ 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 25, 0, 5 } ,{ 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 25, 0, -5 } ,{ 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } }, { { 25, 5, -10 } ,{ 20, 0, -10 },{ 0, 0, -10 },{ -5, 0, -10 },{ -10, 0, -10 } ,{ -15, 5, -10 } }, { { 25, 5, -15 } ,{ 20, 5, -15 },{ 0, 0, -15 },{ -5, 0, -15 },{ -10, 5, -15 } ,{ -15, 5, -15 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 5.0, 5.0, 5.0 }; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 5.0, 5.0, 5.0 }; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);

Slide 10

Slide 10 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 9 jgs 5 curves x 6 control points per curve const int V_size = 6; const int U_size = 5; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 25, 5, 15 } ,{ 20, 5, 15 },{ 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 25, 5, 10 } ,{ 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 25, 0, 5 } ,{ 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 25, 0, -5 } ,{ 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } }, { { 25, 5, -10 } ,{ 20, 0, -10 },{ 0, 0, -10 },{ -5, 0, -10 },{ -10, 0, -10 } ,{ -15, 5, -10 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 4.0, 4.0, 4.0, 4.0}; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 5.0, 5.0, 5.0 }; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);

Slide 11

Slide 11 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 10 jgs 4 curves x 6 control points per curve const int V_size = 6; const int U_size = 4; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 25, 5, 15 } ,{ 20, 5, 15 },{ 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 25, 5, 10 } ,{ 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 25, 0, 5 } ,{ 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 25, 0, -5 } ,{ 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0}; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 5.0, 5.0, 5.0 }; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);

Slide 12

Slide 12 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 11 jgs Test Yourselves What about 3?

Slide 13

Slide 13 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 12 jgs Test Yourselves What about 3? We need at least 4 using Cubic B-splines

Slide 14

Slide 14 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 13 jgs Screenshot 4 curves 6 control points each 4 curves 5 control points each 4 curves 4 control points each

Slide 15

Slide 15 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 14 jgs 4 curves x 6 control points per curve const int V_size = 6; const int U_size = 4; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 25, 5, 15 } ,{ 20, 5, 15 },{ 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 25, 5, 10 } ,{ 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 25, 0, 5 } ,{ 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 25, 0, -5 } ,{ 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0}; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 5.0, 5.0, 5.0 }; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);

Slide 16

Slide 16 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 15 jgs 4 curves x 5 control points per curve const int V_size = 5; const int U_size = 4; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 20, 5, 15 },{ 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0}; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 4.0, 4.0, 4.0, 4.0 }; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);

Slide 17

Slide 17 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 16 jgs 4 curves x 4 control points per curve const int V_size = 4; const int U_size = 4; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0}; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0}; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);

Slide 18

Slide 18 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 17 jgs Note § GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 2.0, 4.0, 4.0, 4.0, 3.0}; § GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0};

Slide 19

Slide 19 text

jgs Quiz 06 NURBS

Slide 20

Slide 20 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 19 jgs Problem A https://github.com/javiergs/SER431/blob/master/Lecture20/nurbs_surface_controlled.cpp

Slide 21

Slide 21 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 20 jgs Problem B https://github.com/javiergs/SER431/blob/master/Lecture20/nurbs_surface_controlled.cpp * There are 7 squares (i.e., 7 curves)in blue. * You need 8 control points per square; BUT since you want to close the curve. You may should need to add the first one again. Thus 8 + 1

Slide 22

Slide 22 text

jgs SER431 Advanced Graphics Javier Gonzalez-Sanchez [email protected] Fall 2018 Disclaimer. These slides can only be used as study material for the class SER431 at ASU. They cannot be distributed or used for another purpose.