opengl curves & surfaces. where u varies in some domain (say [0,1]). a bezier surface patch is a...

26
OpenGL Curves & OpenGL Curves & Surfaces Surfaces

Post on 20-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

OpenGL Curves & OpenGL Curves & SurfacesSurfaces

Page 2: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

Where u varies in some domain (say [0,1]).

A Bezier surface patch is a vector-valued function of two variables

EvaluatorsEvaluators

A Bezier curve is a vector-valued function of 1 variable

Page 3: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

OpenGL EvaluatorOpenGL Evaluator

• Define the function C( ) or S( )

• Enable it

• Use glEvalCoord1( ) or glEvalCoord2( ) instead of glVertex*( )

• The curve or surface is used just as any other vertices are used.

Page 4: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

Example bezcurve.cExample bezcurve.c(Note: the one I handed out is slightly different than this one.)

Control Points

Bézier Curve

Page 5: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

bezcurve.c (part 1)bezcurve.c (part 1)

GLfloat ctrlpoints[4][3] = {

{-4.0, -4.0, 0.0},

{-2.0, 4.0, 0.0},

{2.0, -4.0, 0.0},

{4.0, 4.0, 0.0}};

void init(void){

glClearColor(0.0, 0.0, 0.0,, 0.0);

glShadeModel(GL_FLAT);

glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]);

glEnable(GL_MAP1_VERTEX_3);}

Page 6: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

glMap1{fd} ( … )glMap1{fd} ( … )• GLenum target (see next slide)

• TYPE u1 – starting value of u

• TYPE u2 – ending value of u

• GLint stride – number of single or double precision values in each block of storage.

• GLint order – degree plus 1 (should agree with the number of control points)

• const TYPE * points – pointer to control points

Page 7: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

glMap1 target parameterglMap1 target parameter

• GL_MAP1_VERTEX_3 : x,y,z vertex coordinates

• GL_MAP1_VERTEX_4 : x,y,z,w vertex coordinates

• GL_MAP1_INDEX : color index• GL_MAP1_COLOR_4 : R,G,B,A• GL_MAP1_NORMAL : normal

coordinates• GL_MAP1_TEXTURE_COORD_1 :

s texture coordinate

• GL_MAP1_TEXTURE_COORD_2 : s,t texture coordinates

• GL_MAP1_TEXTURE_COORD_3 : s,t,r texture coordinates

• GL_MAP1_TEXTURE_COORD_4 : s,t,r,q texture coordinates

Page 8: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

glEnable(GL_MAP1_VERTEX_3)glEnable(GL_MAP1_VERTEX_3)

• Enables the one-dimensional evaluator for three dimensional vertices.

Page 9: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

bezcurve.c (part 2) display functionbezcurve.c (part 2) display function

void display(void) {

int i;

glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0, 1.0, 1.0); // set color to white

glBegin(GL_LINE_STRIP);

for(i=0; i<=30; i++) // loop 31 times

glEvalCoord1f((GLfloat) i/30.0); // call evaluator

glEnd( );

Page 10: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

bezcurve.c (part 3) bezcurve.c (part 3)

/* the following code displays the control points as dots */

glPointSize(5.0);

glColor3f(1.0, 1.0, 0.0); // set color to yellow

glBegin(GL_POINTS);

for(i=0; i<4; i++)

glVertex3fv(&ctrloints[i][0]); // Draw a point

glEnd( );

glFlush( );

Page 11: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

Bezcurve.c (part 4)Bezcurve.c (part 4)

• A reshape function that uses glOrtho for orthographic projections and an identity matrix for model view.

• A normal main function like all other examples.

Page 12: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

Modification for hand-outModification for hand-out

• I changed the color of the bezier curve to red and added another bezier curve with different parameters.

• Only 4 steps in the evaluator loop.

• (This new curve is drawn in white)

• Note the lack of smoothness.

• Note the same start and end points.

Page 13: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A
Page 14: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

Additional codeAdditional code

glClear(GL_COLOR_BUFFER_BIT); // clear screenglColor3f(1.0, 1.0, 1.0); // set color to whiteglBegin(GL_LINE_STRIP); // start a line strip for(i=0; i<=4; i++); // loop FIVE times glEvalCoord1f((GLfloat)i/4.0); // calc a pointglEnd( );glColor3f(1.0, 0.0, 0.0); // set color to redglBegin(GL_LINE_STRIP); // start a line strip for(i=0; i<=30; i++); // loop 31 times glEvalCoord1f((GLfloat)i/30.0); // calc a pointglEnd( );

Page 15: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

0 : 0.0/4.0 = 0.0

2 : 2.0/4.0 = 0.50

1 : 1.0/4.0 = 0.25

3 : 3.0/4.0 = 0.75

4 : 4.0/4.0 = 1.0

15 : 15.0/30.0=0.50

Page 16: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

Calculated

Points

Page 17: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

DEMOSDEMOS

• Bezier /wwwf2003/examples/class

• Curves /wwwf2003/public/curves

Page 18: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

Another way to do even spacingAnother way to do even spacing

• void glMapGrid1{fd}(GLint n, TYPE u1, TYPE u2);

• Void glEvalMesh1(GLenum mode, GLint p1, GLint p2); (equivalent to following)

glBegin(GL_POINTS); // or glBegin(GL_LINE_STRIP);

for (i=p1; i<=p2; i++)

glEvalCoord1(u1+i*(u2-u1)/n);

glEnd();

Page 19: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

2D Bezier Surfaces2D Bezier Surfaces

Page 20: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A
Page 21: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A
Page 22: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A
Page 23: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A
Page 24: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

Code is bezmeshnolight.cCode is bezmeshnolight.c

Page 25: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

bezmesh.c with lightingbezmesh.c with lighting

Page 26: OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A

bezsurf.cbezsurf.c